|
| 1 | +--- |
| 2 | +publish: true |
| 3 | +--- |
| 4 | + |
| 5 | +# About Translation |
| 6 | + |
| 7 | +> [!Danger] This page is under development |
| 8 | +> For now, it is a list of things to remember to record. |
| 9 | +
|
| 10 | +Since Tasks X.Y.Z, we are gradually migration most user-visible text in to a translation framework - also know as internationalisation or i18n. |
| 11 | + |
| 12 | +Topics - likely to be broken out in to separate pages: |
| 13 | + |
| 14 | +- Setting up WebStorm |
| 15 | +- Overview of the translation setup |
| 16 | +- How to add a new string |
| 17 | +- How to enable translations in a new language |
| 18 | +- How to add new translations |
| 19 | + |
| 20 | +## Tools Used |
| 21 | + |
| 22 | +- i18next |
| 23 | +- i18next-browser-languagedetector |
| 24 | +- i18next-parser |
| 25 | +- WebStorm |
| 26 | + - [Easy I18n](https://plugins.jetbrains.com/plugin/16316-easy-i18n) plugin. |
| 27 | + |
| 28 | +## Files |
| 29 | + |
| 30 | +- `src/i18n/i18n.ts` |
| 31 | +- `src/i18n/locales/*.json` |
| 32 | + |
| 33 | +### Key names |
| 34 | + |
| 35 | +You can see the currently-used key names in: |
| 36 | + |
| 37 | +`src/i18n/locales/en.json` |
| 38 | + |
| 39 | +Here, they are nested, for example: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "modals": { |
| 44 | + "customStatusModal": { |
| 45 | + "editAvailableAsCommand": { |
| 46 | + "name": "Available as command" |
| 47 | + }, |
| 48 | +``` |
| 49 | + |
| 50 | +The value of that string is obtained in code with: |
| 51 | + |
| 52 | +```ts |
| 53 | +i18n.t('modals.customStatusModal.editAvailableAsCommand.name') |
| 54 | +``` |
| 55 | + |
| 56 | +In WebStorm with the Easy I18n plugin configured, hovering over that `i18n.t()` will show you the expanded text. |
| 57 | + |
| 58 | +## For Developers |
| 59 | + |
| 60 | +> [!Warning] Do not extract strings by hand |
| 61 | +> It is just too time-consuming and too error-prone. |
| 62 | +> Find a tool in your IDE that will allow you to select text, give it a label and extract it to all languages. |
| 63 | + |
| 64 | +The flow for adding a new translation value - in WebStorm... |
| 65 | + |
| 66 | +Scenarios/topics: |
| 67 | + |
| 68 | +- Simple string |
| 69 | +- Simple string with interpolation |
| 70 | +- Beware of extra backticks |
| 71 | +- `yarn extract-i18n` |
| 72 | + |
| 73 | +## WebStorm Easy I18n |
| 74 | + |
| 75 | +- Action for extracting strings |
| 76 | +- Table and tree view |
| 77 | + - Meaning of red text |
| 78 | + - Meaning of orange text |
| 79 | + |
| 80 | +## For Translators |
| 81 | + |
| 82 | +We will find a website to make it easy to add new translations. |
0 commit comments