-
Notifications
You must be signed in to change notification settings - Fork 25
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 TranslationService v2 (ckeditor5-dev part) #314
Conversation
…and translation services.
df21254
to
70acef0
Compare
Notes for the reviewer: The most important parts of the PR are SingleLanguageTranslationService and MultipleLanguageTranslationService, which implements TranslationService interface and can be replaceable. The translation service is chosen depending on the config in CKEditorWebpackPlugin and passed alongside with the CKEditor5-specific env utils to the serveTranslation function, that takes care of the whole webpack compilation process. |
4f34157
to
bf04f26
Compare
After above changes, the translation service should work according to the ckeditor/ckeditor5#624 (comment). Steps to test:
Now you should be able to play with options defined in ckeditor/ckeditor5#624. |
You can avoid calling |
772d6bd
to
356cfab
Compare
eb788a6
to
a5dcb91
Compare
*/ | ||
constructor( options = {} ) { | ||
this.options = options; | ||
} | ||
|
||
apply( compiler ) { | ||
const { languages } = this.options; | ||
if ( !this.options.language ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could warn user about this in the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we could even move more logic to the constructor despite calling serveTranslations()
, but I'm not sure if this is necessary. TBH I'd move all config checks or none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so lets warn here instead of moving it to the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
if ( !additionalLanguages ) { | ||
if ( this.options.outputDirectory ) { | ||
console.warn( chalk.red( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding "Warning:" before the message and use yellow as in other warnings? To clearly state that it's not an error.
* @param {TranslationService} translationService | ||
* @param {String} resource Absolute path to the resource. | ||
*/ | ||
function maybeLoadPackage( cwd, translationService, resource ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change name of this method to, for example getPathToPackage()
. It would return proper path, or null
. This way we will not pass TranslationService
object here, just use the validated result outside the function.
* @param {String} resource Absolute path to the resource. | ||
* @param {Array.<Object>} loaders Array of Webpack loaders. | ||
*/ | ||
function maybeAddLoader( cwd, resource, loaders ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - rename to something like getLoader
.
this._idNumber = 0; | ||
} | ||
|
||
getNextId() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add docs to the method.
@@ -17,7 +17,7 @@ const corePackageName = 'ckeditor5-core'; | |||
|
|||
const utils = { | |||
/** | |||
* Collect translations and returns array of translations. | |||
* Collect translations and return array of translations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collects and returns.
Suggested merge commit message (convention)
Feature: Implement TranslationService v2 (ckeditor5-dev part). Closes ckeditor/ckeditor5#666. Closes ckeditor/ckeditor5#624.
BREAKING CHANGE:
CKEditorWebpackPlugin
plugin supports nowlanguage
andadditionalLanguages
options instead oflanguages
. If onlylanguage
is set, the plugin will translate code directly into the main bundle. WhenadditionalLanguages
are provided, then the plugin will output bundle with the main language and rest translation files separately.Additional information