-
-
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
Improve Locale.t() to handle context and plurals. #6158
Comments
Summary of the new Locale APIOur new API was inspired a lot by Jed and gettext.js which are themselves based on the original GNU gettext approach. const { t, ct, ctn } = this.editor.locale;
// t behaves the same as before.
// It finds a localized message based on the english version and can also perform string interpolation.
console.log( t( 'Hello, World!' );
// Interpolation values go into the second argument.
console.log( t( 'Hello, %0!', [ 'World' ] );
// ct is used to pass a context with the message to make sure similar messages are unique.
console.log(
ct( 'Welcome message', 'Hello, World!' )
);
// To perform an interpolation, use a method.
console.log(
ct( 'Welcome message', 'Hello, %0!' )
.format('World')
);
// ctq is used for messages with plural forms.
console.log(
ctq( 'Word count plugin', '# word', '# words', wordCount )
); We use the following functions for getting messages:
The new functions (
Read more about Jed API for comparison. Changes to translations JSON format{
"pl": {
"PLURAL_FORMS": "nplurals=3; plural=(n == 1) ? 0 : (n < 5) ? 1 : 2",
"message id": ["localised message", "localised message plural 1", "localised message plural 2"],
"message context|message id": "localised message"
}
} Things to note:
Breaking changes 💔There was functionality for providing the message context in the We decided to remove that functionality because it wasn't used anywhere. A better way of providing more information for the translator are |
The issue was closed by ckeditor/ckeditor5-dev#614. |
📝 Provide a description of the improvement
Support more functionality in
Locale.t
function.ngettext
.pgettext
). Right now it looks like passing the context as part of msgid in square brackets is supported.This will require work in the Locale class and changes in Webpack plugin.
The text was updated successfully, but these errors were encountered: