Commit d30608a0 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'jhyson/fix-chinese-translation' into 'master'

Fix issue with project dropdown translation for languages without pluralisation

See merge request gitlab-org/gitlab!21988
parents 5e7b0669 b086e422
......@@ -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
......
......@@ -3,7 +3,7 @@ import $ from 'jquery';
import _ from 'underscore';
import { GlLoadingIcon, GlButton, GlAvatar } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import { sprintf, n__, s__, __ } from '~/locale';
import { n__, s__, __ } from '~/locale';
import Api from '~/api';
import { renderAvatar, renderIdenticon } from '~/helpers/avatar_helper';
......@@ -49,16 +49,17 @@ export default {
},
computed: {
selectedProjectsLabel() {
return this.selectedProjects.length
? sprintf(
n__(
'CycleAnalytics|%{projectName}',
'CycleAnalytics|%d projects selected',
this.selectedProjects.length,
),
{ projectName: this.selectedProjects[0].name },
)
: this.selectedProjectsPlaceholder;
if (this.selectedProjects.length === 1) {
return this.selectedProjects[0].name;
} else if (this.selectedProjects.length > 1) {
return n__(
'CycleAnalytics|Project selected',
'CycleAnalytics|%d projects selected',
this.selectedProjects.length,
);
}
return this.selectedProjectsPlaceholder;
},
selectedProjectsPlaceholder() {
return this.multiSelect ? __('Select projects') : __('Select a project');
......
......@@ -5742,11 +5742,6 @@ msgstr ""
msgid "CycleAnalyticsStage|should be under a group"
msgstr ""
msgid "CycleAnalytics|%{projectName}"
msgid_plural "CycleAnalytics|%d projects selected"
msgstr[0] ""
msgstr[1] ""
msgid "CycleAnalytics|%{stageCount} stages selected"
msgstr ""
......@@ -5768,6 +5763,11 @@ msgstr ""
msgid "CycleAnalytics|Number of tasks"
msgstr ""
msgid "CycleAnalytics|Project selected"
msgid_plural "CycleAnalytics|%d projects selected"
msgstr[0] ""
msgstr[1] ""
msgid "CycleAnalytics|Select labels"
msgstr ""
......
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