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

Align docs to the new Translation Service #694

Merged
merged 8 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/builds/guides/development/custom-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ module.exports = {
'../relative/path/to/some/othercustomplugin'
],

// UI language. Language codes follow the https://en.wikipedia.org/wiki/ISO_639-1 format.
language: 'en',

// Editor configuration.
config: {
toolbar: [ 'headings', 'bold', 'italic', 'custombutton' ]
toolbar: [ 'headings', 'bold', 'italic', 'custombutton' ],

// UI language. Language codes follow the https://en.wikipedia.org/wiki/ISO_639-1 format.
language: 'en'
}
};
```
Expand Down
8 changes: 2 additions & 6 deletions docs/builds/guides/integration/advanced-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ In this guide, we would like to show you ways to closer integrate CKEditor with

## Bundler

CKEditor 5 is currently built using [webpack](https://webpack.js.org) (>=2.x.x). All builds, examples and demos are generated using this bundler. It should also be possible to build CKEditor using other bundlers (if they are configured properly), such as [Rollup](https://github.com/rollup/rollup) or [Browserify](http://browserify.org/) but these setups are not officially supported yet. Also, the [`@ckeditor/ckeditor5-dev-webpack-plugin`](https://www.npmjs.com/package/@ckeditor/ckeditor5-dev-webpack-plugin) that allows to localize the editor is only available for webpack. More work on this subject will be done after v1.0.0.
CKEditor 5 is currently built using [webpack](https://webpack.js.org) (>=3.x.x). All builds, examples and demos are generated using this bundler. It should also be possible to build CKEditor using other bundlers (if they are configured properly), such as [Rollup](https://github.com/rollup/rollup) or [Browserify](http://browserify.org/) but these setups are not officially supported yet. Also, the [`@ckeditor/ckeditor5-dev-webpack-plugin`](https://www.npmjs.com/package/@ckeditor/ckeditor5-dev-webpack-plugin) that allows to localize the editor is only available for webpack. More work on this subject will be done after v1.0.0.

Therefore, **a prerequisite to this guide is that you are using webpack as your build tool**.

## Scenario 1: Integrating existing builds

This is the simplest scenario. It assumes that you want to use {@link builds/guides/overview#Available-builds one of the existing builds} "as-is" (you can, of course, still {@link builds/guides/integration/configuration configure the editor}). It also gives the fastest build times.

<info-box>
At the current stage, builds are only available in English. {@link features/ui-language Setting editor UI language} requires rebuilding the editor which means that this scenario is quite limited.
</info-box>

First, install the build of your choice {@link builds/guides/integration/installation#npm from npm}:

```bash
Expand Down Expand Up @@ -119,7 +115,7 @@ module.exports = {

new CKEditorWebpackPlugin( {
// See https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/features/ui-language.html
languages: [ 'pl' ]
language: 'pl'
} )
],

Expand Down
93 changes: 87 additions & 6 deletions docs/features/ui-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,60 @@ See the demo of the editor in German:

{@snippet features/ui-language}

## Loading additional languages from CDN, npm and zip file

You can load additional languages using:
* [CDN](#CDN),
* [npm](#npm),
* [Zip download](#Zip).

Next, configure the editor to use chosen language:

```js
ClassicEditor
.create( document.querySelector( '#editor' ), {
language: 'de'
} )
.then( editor => {
console.log( editor );
} )
.catch( error => {
console.error( error );
} );
```

### CDN

To use different language than default one, you need to load the editor together with the preferred language:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can specify, that English will be the main language at CDN.


```html
<script src="https://cdn.ckeditor.com/ckeditor5/[version.number]/[distribution]/ckeditor.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/[version.number]/[distribution]/lang/de.js"></script>
```

See {@link builds/guides/integration/installation#CDN CDN installation guides} for more information.

### npm

After installing the build from npm, languages will be available at `node_modules/@ckeditor/ckeditor5-build-[name]/build/lang/`.
Single language can be imported directly to your code by `'@ckeditor/ckeditor5-build-[name]/build/lang/de.js' )`.

See {@link builds/guides/integration/installation#npm npm installation guides} for more information.

### Zip

All additional languages are included in `.zip` file. You need to include `ckeditor.js` file together with language file:

```js
<script src="[ckeditor-path]/ckeditor.js"></script>
<script src="[ckeditor-path]/lang/de.js"></script>
```

See {@link builds/guides/integration/installation#Zip-download zip installation guides} for more information.

## Building the editor using a specific language

Currently, it is only possible to change the UI language at the build stage. A single build of the editor supports only the language which was defined in the [CKEditor 5 webpack plugin](https://www.npmjs.com/package/@ckeditor/ckeditor5-dev-webpack-plugin)'s configuration.
Currently, it is possible to change the UI language at the build stage and after the build. A single build of the editor supports the language which was defined in the [CKEditor 5 webpack plugin](https://www.npmjs.com/package/@ckeditor/ckeditor5-dev-webpack-plugin)'s configuration. See the whole translation process to see how you can change the language later.
Copy link
Member

Choose a reason for hiding this comment

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

This guide needs to be pretty much rewritten rather than patched. Since the whole picture changed dramatically we need to put focus on different things.

  1. The current intro can stay.

  2. But then we should explain how to initialize the editor from CDN/zip/npm with a different language. This is what most people will want to do. Please also review other guides like installation.md and other places where we list files available in a build because that list needs to be updated (and perhaps link to the ui-language.md guide):

    image

  3. Then we can provide a few more details on what other options people have:

    • compiling an optimised editor (single language case),
    • compiling a subset of languages (TBH, I'm not sure what's the use case for that – perhaps speeding up the process and reducing the number of files – but let's mention it anyway),
    • handling multiple entry points scenario (as @ma2ciek noticed that has certain limitations)
  4. At the end we can mention that compiling editor translations is only available for Webpack and we will be extending support for other bundlers in the future. If we want to mention those tickets about translations services we should explain why we mention them. Something like – if you'd like to tinker with one of the bundlers you can read about CKEditor 5's translation service here and here.


If you use one of the {@link builds/index predefined editor builds}, refer to {@link builds/guides/development/custom-builds Creating custom builds} to learn how to change the language of your build.

Expand All @@ -37,19 +88,49 @@ If you build CKEditor from scratch or integrate it directly into your applicatio
// Define webpack plugins ...
plugins: [
new CKEditorWebpackPlugin( {
// Note: The plugin is currently able to build just one language at a time.
languages: [ 'pl' ]
// Main language that will be built in to the main bundle.
language: 'en',

// Additional languages that will be emitted to the `outputDirectory`.
// This option can be set to array of language codes or `'all'` to build all found languages.
// The bundle is optimized for one language when this option is omitted.
additionalLanguages: 'all',

// Optional directory for emitted translations, `'lang'` by default.
// Relative to the webpack's output.
outputDirectory: 'lang',

// Optional flag indicates breaking the build process when the error is found.
throwErrorOnMissingTranslation: false
Copy link
Member

Choose a reason for hiding this comment

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

Is false a default value? In documentation, in code samples, we should present real usage and no one will change false to false :P Plus, the comment above is unclear now – if you'd turn it on here, we could simply document that it "Will cause the building process to fail if a translation for one of the strings is missing".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I just wanted to list available options with their default values.

Copy link
Member

Choose a reason for hiding this comment

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

You can mention the default value of each option in a comment.

} ),

// Other webpack plugins...
]
// ...
```

3. Run webpack. The CKEditor plugin for webpack will replace the {@link module:utils/locale~Locale#t `t()`} function calls used in the source code with localized language strings.
3. Run webpack. If the `additionalLanguages` option is not set, the CKEditor plugin for webpack will replace the {@link module:utils/locale~Locale#t `t()`} function call parameters used in the source code with localized language strings. Otherwise the CKEditor plugin for webpack will replace the {@link module:utils/locale~Locale#t `t()`} function call parameters with short ids and emit the translation files that should land in the `'lang'` directory (or different, if the `outputDirectory` option is specified).

4. If you want to change the language after the build ends, you will need to edit the `index.html` file, add the translation file and set the UI language to the target one.

```html
<script src="../build/ckeditor.js"></script>
<script src="../build/lang/pl.js"></script>
<script>
ClassicEditor.create( document.querySelector( '#editor' ), {
Copy link
Member

Choose a reason for hiding this comment

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

Better Consistent formatting:

ClassicEditor
    .create( {
    } )
    .then()
    .catch();

language: 'pl'
} )
.then( editor => {
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
} );
</script>
```

<info-box>
We are aware that the current localization method is not sufficient for all needs. It neither supports different bundlers (e.g. Rollup or Browserify) nor building multiple languages (to make it possible to pick one at runtime). We will be extending the localization possiblities in the near future.
We are aware that the current localization method is not sufficient for all needs. It doesn't support different bundlers (e.g. Rollup or Browserify). We will be extending the localization possibilities in the future.

You can read more about the used techniques and future plans in the ["Implement translation services" issue](https://github.com/ckeditor/ckeditor5/issues/387).
You can read more about the used techniques in the ["Implement translation services" issue](https://github.com/ckeditor/ckeditor5/issues/387) and ["Implement translation services v2" issue](https://github.com/ckeditor/ckeditor5/issues/624).
</info-box>
45 changes: 45 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
0 info it worked if it ends with ok
Copy link
Contributor

Choose a reason for hiding this comment

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

I dunno why I was reading this commit but this caught my attention :): npm-debug.log

1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'docs' ]
2 info using npm@3.10.10
3 info using node@v6.10.0
4 verbose run-script [ 'predocs', 'docs', 'postdocs' ]
5 info lifecycle ckeditor5@1.0.0-alpha.2~predocs: ckeditor5@1.0.0-alpha.2
6 silly lifecycle ckeditor5@1.0.0-alpha.2~predocs: no script for predocs, continuing
7 info lifecycle ckeditor5@1.0.0-alpha.2~docs: ckeditor5@1.0.0-alpha.2
8 verbose lifecycle ckeditor5@1.0.0-alpha.2~docs: unsafe-perm in lifecycle true
9 verbose lifecycle ckeditor5@1.0.0-alpha.2~docs: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/szymon/projects/ckeditor5/node_modules/.bin:/home/szymon/bin:/home/szymon/.local/bin:/home/szymon/bin:/home/szymon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
10 verbose lifecycle ckeditor5@1.0.0-alpha.2~docs: CWD: /home/szymon/projects/ckeditor5
11 silly lifecycle ckeditor5@1.0.0-alpha.2~docs: Args: [ '-c', 'node ./scripts/docs/build-docs.js' ]
12 silly lifecycle ckeditor5@1.0.0-alpha.2~docs: Returned: code: 1 signal: null
13 info lifecycle ckeditor5@1.0.0-alpha.2~docs: Failed to exec docs script
14 verbose stack Error: ckeditor5@1.0.0-alpha.2 docs: `node ./scripts/docs/build-docs.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:877:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid ckeditor5@1.0.0-alpha.2
16 verbose cwd /home/szymon/projects/ckeditor5
17 error Linux 4.13.0-17-generic
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "docs"
19 error node v6.10.0
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error ckeditor5@1.0.0-alpha.2 docs: `node ./scripts/docs/build-docs.js`
22 error Exit status 1
23 error Failed at the ckeditor5@1.0.0-alpha.2 docs script 'node ./scripts/docs/build-docs.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the ckeditor5 package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node ./scripts/docs/build-docs.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs ckeditor5
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls ckeditor5
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
2 changes: 1 addition & 1 deletion scripts/docs/snippet-adapter/snippetadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function getWebpackConfig( config ) {
const plugins = [
new ExtractTextPlugin( 'snippet.css' ),
new CKEditorWebpackPlugin( {
languages: [ config.language || 'en' ]
language: config.language || 'en'
} ),
new webpack.BannerPlugin( {
banner: bundler.getLicenseBanner(),
Expand Down