-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support translating plural forms (i18n vol 3) #6526
Comments
Extending the 2. proposal we could add the support for the interface TranslationOptions {
// A string id that would be used for translation uniqueness.
// The value defaults to the `string`'s value if it isn't set.
// We could also use it as a translation context to not define two similar things.
// This way that string could be also used by translators.
// E.g. `'Show/Hide %0 editors'`.
id?: string;
// A translation string. Required. E.g. `'editor'`.
string: string;
// A plural form of the translation. E.g. `'%0 editors'`.
// It can be easily ommited if the translation will not have plural forms.
plural?: string
} This way we could still use the
One more advantage is that this API is open-ended for future enhancements. In contrast, the previously proposed APIs would be impossible to change in the future without introducing breaking changes. I've checked and both, parsing (when looking for translation strings and other things) and obfuscation should work for this API. |
As an update, I'll write that I chose the above API as it seems the most flexible, extendible and descriptive and uses the old |
Feature: Provided support for plural forms internalization. Part of ckeditor/ckeditor5#6526. MINOR BREAKING CHANGE: The `translate` function from the `translation-service` was marked as protected. See #334. MINOR BREAKING CHANGE: The format of translations added to the editor has been changed. If you use `window.CKEDITOR_TRANSLATIONS` please see #334.
Internal: Aligned snippet adapter to changes in CKEditorWebpackPlugin. Part of #6526.
Feature: Provided support for plural forms i18n. Closes ckeditor/ckeditor5#6526. Closes ckeditor/ckeditor5#988. MINOR BREAKING CHANGE: Omitting the language property in the CKEditorWebpackPlugin will not have any effect from now. This means that in both cases only the main language (language) will be added to the main bundle and translations for other languages will be saved in separate files. MAJOR BREAKING CHANGE: The translation process no longer creates short ids for message strings. From now, the source code will not be changed by the translation process, translations for the main language will be added to the bundle(s) and translations for other languages will be outputted to separate executable JS files.
Feature: Provided support for plural forms internalization. Part of #6526. MINOR BREAKING CHANGE: The `translate` function from the `translation-service` was marked as protected. See #334. MINOR BREAKING CHANGE: The format of translations added to the editor has been changed. If you use `window.CKEDITOR_TRANSLATIONS` please see #334.
📝 Provide a description of the new feature
Reasoning
The current implementation of the internalization process doesn't support translating plural forms. Supporting many plural forms is necessary in cases where there's an unknown number of elements like
Add %0 bananas
and there is an unknown language and not known number and rules of its plural forms. For sure we could write theAdd bananas (%0)
but this looks much less friendly and IMO it's a little bit distractive.Required changes an checks
ckeditor5-utils
)t()
function changes should be backward-compatible.t()
function needs to support new function(s) too. (ckeditor5-dev
)translate()
function inckeditor5-utils
. (ckeditor5-dev
)window.Intl.PluralRules
but it is not implemented in Safari, so each translation file should include its own plural rulesPossible further improvements
gettext-extract
,xgettext
etc.t()
function invocations, removecontexts.json
file (?) This would be only valuable if we'd need to have contexts directly in new functionsLimitations
translationId
parameter to the translation function)API proposal
Translation functions
Proposal 1: Full sentences
Without the function returning intermediate results we could just add an overload to the known
t()
function:The above API could be used in the following way:
Note that concatenating strings could be quite dangerous due to the fact that languages can have various declension rules so we can't do the following:
The styling should be added directly into the code like as the
t()
function produces strings and there's no way to determine later which part should be be bolded. The bolded text could be done only this way:So after the translation phases these styling could be e.g. wrapped in bold.
Proposal 2 - Add additional support for defining translation ids
Add contexts/translation ids to translation strings so some translations can be reused without worrying about different declension rules.
E.g.:
Pluses
Minuses
ct
andt
functions - in thect
function we'd need to use contexts as translation id or add a unique id as the first argumentProposal 3 - return an object instead of a string for more customizable usages
Create a function that returns an object with translation fragments
e.g.:
Pluses
Minuses
t()
function API while the function name seems to be familiarWith the
toString()
function defined, we could also use it indirectly in the string concatenations as we use thet()
function currently. However such a not-explicit way seems a little bit scary.Translation files
The translation files need to have defined translation rules like:
They also need to include these plural forms:
Refs
cc @Reinmar @scofalik @mlewand
If you'd like to see this feature implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: