Skip to content

Commit

Permalink
[I18n] Update I18n readme (#26631)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeanidShutau authored Dec 5, 2018
1 parent 83325bf commit 0b6e8af
Showing 1 changed file with 11 additions and 44 deletions.
55 changes: 11 additions & 44 deletions packages/kbn-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,7 @@ message syntax.

## Localization files

Localization files have [JSON5](https://github.com/json5/json5) format.

The main benefits of using `JSON5`:

- Objects may have a single trailing comma.
- Single and multi-line comments are allowed.
- Strings may span multiple lines by escaping new line characters.

Short example:

```js
{
// comments
unquoted: 'and you can quote me on that',
singleQuotes: 'I can use "double quotes" here',
lineBreaks: "Wow! \
No \\n's!",
hexadecimal: 0xdecaf,
leadingDecimalPoint: .8675309, andTrailing: 8675309.,
positiveSign: +1,
trailingComma: 'in objects', andIn: ['arrays',],
"backwardsCompatible": "with JSON",
}
```
Localization files are JSON files.

Using comments can help to understand which section of the application
the localization key is used for. Also `namespaces`
Expand Down Expand Up @@ -107,7 +84,7 @@ when missing translations
For the detailed explanation, see the section below
- `getFormats()` - returns current formats
- `getRegisteredLocales()` - returns array of locales having translations
- `translate(id: string, [{values: object, defaultMessage: string, description: string}])`
- `translate(id: string, { values: object, defaultMessage: string, description: string })`
translate message by id. `description` is optional context comment that will be extracted
by i18n tools and added as a comment next to translation message at `defaultMessages.json`.
- `init(messages: Map<string, string>)` - initializes the engine
Expand Down Expand Up @@ -384,13 +361,13 @@ when missing translations
- `init(messages: Map<string, string>)` - initializes the engine

The translation `service` provides only one method:
- `i18n(id: string, [{values: object, defaultMessage: string, description: string }])`
- `i18n(id: string, { values: object, defaultMessage: string, description: string })`
translate message by id

The translation `filter` is used for attributes translation and has
the following syntax:
```
{{'translationId' | i18n[:{ values: object, defaultMessage: string, description: string }]}}
{{ ::'translationId' | i18n: { values: object, defaultMessage: string, description: string } }}
```

Where:
Expand Down Expand Up @@ -452,20 +429,10 @@ In order to translate attributes in AngularJS we should use `i18nFilter`:
>
```

## Build tools

In order to simplify localization process, some build tools will be added:
- tool for verifying all translations have translatable strings
- tool for checking unused translation strings
- tool for extracting default messages from templates

While `react-intl` has
[babel-plugin-react-intl](https://github.com/yahoo/babel-plugin-react-intl)
library which extracts string messages for translation, angular wrapper requires
own implementation of such tool. In order to extracrt translation keys from the
template, we have to parse it and create AST object. There is a
[babel-plugin-syntax-jsx](https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-jsx)
plugin which helps to parse JSX syntax and then create AST object. Unfortunately,
there are no babel plugins to parse angular templates. One of the solution can be internal
[`$parse.$$getAst`](https://github.com/angular/angular.js/blob/master/src/ng/parse.js#L1819)
angular method.
## I18n tools

In order to simplify localization process, some additional tools were implemented:
- tool for verifying all translations have translatable strings and extracting default messages from templates
- tool for verifying translation files and integrating them to Kibana

[I18n tools documentation](../../src/dev/i18n/README.md)

0 comments on commit 0b6e8af

Please sign in to comment.