Skip to content
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

Merged
merged 38 commits into from
Nov 30, 2017

Conversation

ma2ciek
Copy link
Contributor

@ma2ciek ma2ciek commented Nov 15, 2017

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 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.


Additional information

  • It's the main change that's required by Implement translation service (i18n) v2 ckeditor5#624.
  • It allows providing internalization for multiple languages or single language.
  • It allows creating js translation files, that can be added to the HTML file alongside with the built editor.
  • Parts of the translation service should be easier to maintain and more CKEditor5 independent, so they can be available to use outside, e.g. from the Letters codebase.
  • Few missing tests added.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Nov 16, 2017

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.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Nov 23, 2017

After above changes, the translation service should work according to the ckeditor/ckeditor5#624 (comment).

Steps to test:

  1. Go to ckeditor5-dev
  2. Switch branch to t/ckeditor5/624.
  3. Run lerna bootstrap

  1. Go to ckeditor5-dev/packages/ckeditor5-dev-webpack-plugin
  2. Run npm link

  1. Go to ckeditor5/packages/ckeditor5-utils
  2. Switch branch to t/ckeditor5/624.

  1. Go to ckeditor5/packages/ckeditor5-build-classic
  2. Switch branch to t/ckeditor5/624.
  3. Run npm link @ckeditor/ckeditor5-dev-webpack-plugin

  1. Run npm run build

Now you should be able to play with options defined in ckeditor/ckeditor5#624.

@pomek
Copy link
Member

pomek commented Nov 23, 2017

You can avoid calling npm link. Use switch-to-dev-dev.sh script.

*/
constructor( options = {} ) {
this.options = options;
}

apply( compiler ) {
const { languages } = this.options;
if ( !this.options.language ) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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(
Copy link
Contributor

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 ) {
Copy link
Contributor

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 ) {
Copy link
Contributor

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() {
Copy link
Contributor

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collects and returns.

@szymonkups szymonkups merged commit ee2a1d2 into master Nov 30, 2017
@szymonkups szymonkups deleted the t/ckeditor5/624 branch November 30, 2017 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants