Commit 04202bb9 authored by Josianne Hyson's avatar Josianne Hyson

Add documentation around plural control flow

Previously we have had cases of the `n__` method being used to control
which different strings should show up in the singular and plural cases
for a string. This doesn't work in languages such as Chinese Simplified,
as this language only has one target plural form - which means the
translator needs to determine which string should show up.

This is particularly an issue when different variables are used in each
version of the string, as variables present in the source string for
one case may not show up in the target string for the chosen plural form
from the translators - which will cause linting to fail.
parent f4f589be
......@@ -195,6 +195,31 @@ For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript. Make s
// => When x == 2: 'Last 2 days'
```
The `n_` method should only be used to fetch pluralized translations of the same
string, not to control the logic of showing different strings for different
quantities. Some languages have different quantities of target plural forms -
Chinese (simplified), for example, has only one target plural form in our
translation tool. This means the translator would have to choose to translate
only one of the strings and the translation would not behave as intended in the
other case.
For example, prefer to use:
```ruby
if selected_projects.one?
selected_projects.first.name
else
n__("Project selected", "%d projects selected", selected_projects.count)
end
```
rather than:
```ruby
# incorrect usage example
n_("%{project_name}", "%d projects selected", count) % { project_name: 'GitLab' }
```
### Namespaces
Sometimes you need to add some context to the text that you want to translate
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment