-
-
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
Implement translation service (i18n) v2 #624
Comments
I've got some issues that came to my mind recently, so I want to clarify few things. Do we want to create hashes for translation keys (#387 (comment) Do we want to support creating multiple chunks e.g. through the DllPlugin? We should be able to get all dependencies for the given asset, but I'll check it to be sure. How we want to support multiple instances of the editor? Because we can't register one
We should be able to provide an option to specify the destination directory for the translation files because we need to fit many dev environments. I'd propose the 'languageDirectory' option which defaults to 'output'. I'd try to write everything inside the webpack plugin, so the user won't need to execute anything. I'm testing https://webpack.js.org/api/compilation/#additional-assets-async and it should fit our needs. I'm not sure how do we want to change editor's language at runtime. For now, the language for the UI is set in the config, so the user needs to rebuild everything either way. |
cc @szymonkups |
Yes, it's possible to generate e.g. few 'en.js' translation files for few chunk during the compilation. Like in the original proposal:
But it's easy to guess, that this is going to be complicated with the support for multiple editors etc. |
I'll sum up our talks:
Yes, we do. Hashes as they resolve the problem with having same translation strings for different contexts. (the translation string's context is defined by the package name, e.g.
Not necessarily, but we might need it at some point in the future.
Few editors instances should be compiled at the same time, so it's solved by the
This is ok, as it's up to the developer, where these files should land.
We don't need it at runtime, but we should be able to change the editor's language by adding only one language file. With many language files, the editor's language should be specified by the |
It should be noted that no two translation strings across the whole project can't share the same name. If they mean the same, they should be placed in the |
The part I haven't mentioned earlier is the error handling. I made it configurable by providing the So for now, I'd introduce the 4 plugin options:
|
How should builds behave after that change? Should they translate code directly into the bundle, like before? Or should they emit files? |
The answer is in the following piece of my initial idea (although, it's a bit hidden :D)
|
Hmm, but after the translation keys are replaced with the corresponding translations it's impossible to change those translations later. We're losing the contexts. |
We might end up with multiple |
It'd be possible if we'd save the |
Note that we wanted to replace translation keys with hashes for optimizing the weight of the editor and translation files. |
I'm not sure whether I understand what you mean, but saving the context in translations can be done. Also, I think thee we agreed to ignore duplicated texts (when one text appears in two contexts) for now. So perhaps we can workaround this "temporarily" in a different way. |
So maybe I misunderstood the idea with ids/hashes. Because now I don't have an idea how they could be used and what's their purpose. |
EDITED After F2F talks, we agreed, that we should go with such solution:
One entry point (or to be precise one output JS file):
Multiple output JS files
Translation files will be emitted in the |
I changed a little bit naming as the option I've proposed provided more problems than it solved. So I added Cases:
So it should be easier to undestand and maintain such a config. |
Other: Aligned code to the new Translation Service (ckeditor/ckeditor5#624).
Let's say, we're setting up the main language and set some additional languages. What if one of the translations for some additional languages misses? Should we have the fallback to the main language or English? Should it be configurable? cc @Reinmar |
Good question. I think that it doesn't need to be configurable. In CKE4 missing translations default to English. I think it'd be good to keep this behaviour so it needs to happen during building. |
Feature: Implement TranslationService v2 (ckeditor5-dev part). Closes ckeditor/ckeditor5#666. Closes ckeditor/ckeditor5#624. BREAKING CHANGE: `CKEditorWebpackPlugin` plugin supports now `language` and `additionalLanguages` options instead of `languages`. If only `language` is set, the plugin will translate code directly into the main bundle. When `additionalLanguages` are provided, then the plugin will output bundle with the main language and rest translation files separately.
Other: Aligned code to changes (`config.lang` to `config.languages`). Part of the Translation Service v2 (ckeditor/ckeditor5#624).
Other: Aligned code to changes (`config.lang` to `config.languages`). Part of the Translation Service v2 (ckeditor/ckeditor5#624).
Other: Aligned build and `webpack.config.js` to the new Translation Service (ckeditor/ckeditor5#624).
Other: Aligned build and `webpack.config.js` to the new Translation Service (ckeditor/ckeditor5#624).
Other: Aligned build and `webpack.config.js` to the new Translation Service (ckeditor/ckeditor5#624).
Docs: Aligned docs and snippets to the Translation Service v2. Closes #624.
Other: Aligned build and `webpack.config.js` to the new Translation Service (ckeditor/ckeditor5#624).
Followup of #387
In #387 we didn't manage to implement a webpack plugin which would be able to create translation files for CKEditor. E.g. you can see this in builds – there's a single
build/ckeditor.js
file which contains English translations. If you'd like to have the editor in Polish you need to go through the entire Custom builds guides (see also Setting UI language). This is bad. Really bad.What we need is that each build will contain the following files:
To enable the editor with a Polish interface you'll need to load two files (e.g. using script tags):
And initialize it:
By default, if not specified, the editor will be initialised with English interface (cause that localization is automatically bundled in
ckeditor.js
).Implementation
It'd be best if all this was handled by the
CKEditorWebpackPlugin
that we use for builds:If someone wants to build just a single language and have the most optimised build she/he can do it like this:
From CKEditor's code perspective, the language files will look something like this:
And this will use the global API exposed by the https://github.com/ckeditor/ckeditor5-utils/blob/master/src/translation-service.js (basically, the
add()
function needs to be exposed).If it won't be possible to implement this with a webpack's plugin it can also be done independently from webpack – by an external tool. Every build has its
bin/build-ckeditor.sh
file anyway so we can add more scripts there. However, this will need to be somehow synchronised with the settings passed toCKEditorWebpackPlugin()
.One more thing to notice is that when that plugin is configured to build just one language it could use the current method which is to replace
t( 'Bold' )
calls with e.g.t( 'Pogrubienie' )
. When building for multiple languages such calls need to be replaced witht( 'some-key' )
(see the old ticket for more details about this) and thissome-key
needs to be passed to translation services (so a different translation service is need to be used – cause right nowt()
function returns its first param).However, for simplicity, we could always replace
t()
witht( 'some-key' )
, even when building for a single language. Then, it'd be just a matter of feeding the translations.The text was updated successfully, but these errors were encountered: