From 69bb020e5c9a001bc5d2b75e31fd580a8e42a237 Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sun, 15 Apr 2018 22:42:58 +1200 Subject: [PATCH 1/5] Add instructions for changing translated strings Add instructions to the developer documentation for proper housekeeping of the translations when editing strings. --- docs/translating-dev.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/translating-dev.md b/docs/translating-dev.md index 3209f1e400..b72c902b51 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -26,6 +26,11 @@ function getColorName(hex) { } ``` +## Editing existing strings + +1. Edit every occurrence of the string in `src/i18n/strings/en_EN.json` and inside `_t()` and `_td()` in the JSX files. +1. Remove every translation of this string from `src/i18n/strings/*.json`, _except_ for `src/i18n/strings/en_EN.json`, as that string no longer exists. + ## Adding new strings 1. Check if the import ``import { _t } from 'matrix-react-sdk/lib/languageHandler';`` is present. If not add it to the other import statements. Also import `_td` if needed. From 6d74d5f8b7d11259d71246614392bbb40072056a Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sat, 21 Apr 2018 21:36:41 +1200 Subject: [PATCH 2/5] Correct instructions to use the i18n scripts As per code review feedback, we should use the npm run scripts i18n and i18n-prune instead of editing the i18n JSON files directly. --- docs/translating-dev.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/translating-dev.md b/docs/translating-dev.md index b72c902b51..c2ad0986f8 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -28,8 +28,9 @@ function getColorName(hex) { ## Editing existing strings -1. Edit every occurrence of the string in `src/i18n/strings/en_EN.json` and inside `_t()` and `_td()` in the JSX files. -1. Remove every translation of this string from `src/i18n/strings/*.json`, _except_ for `src/i18n/strings/en_EN.json`, as that string no longer exists. +1. Edit every occurrence of the string inside `_t()` and `_td()` in the JSX files. +1. Run `npm run i18n` to update `src/i18n/strings/en_EN.json`. (Be sure to run this in the same project as the JSX files you just edited.) +1. Run `npm run i18n-prune` to remove the old string from `src/i18n/strings/*.json`. ## Adding new strings From a8e578f5b8beefd4149f8b92a7276113d1edcd6b Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sat, 21 Apr 2018 21:52:56 +1200 Subject: [PATCH 3/5] Move and reword note about out-of-date dev setup Replace an inline, parenthetical note about possible failures of the `npm run` scripts with additional items in the Requirements section. --- docs/translating-dev.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/translating-dev.md b/docs/translating-dev.md index c2ad0986f8..3238bd7349 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -3,6 +3,8 @@ ## Requirements - A working [Development Setup](../../#setting-up-a-dev-environment) + - Including up-to-date versions of matrix-react-sdk and matrix-js-sdk +- Node 8 or later - Be able to understand English - Be able to understand the language you want to translate riot-web into @@ -36,7 +38,7 @@ function getColorName(hex) { 1. Check if the import ``import { _t } from 'matrix-react-sdk/lib/languageHandler';`` is present. If not add it to the other import statements. Also import `_td` if needed. 1. Add ``_t()`` to your string. (Don't forget curly braces when you assign an expression to JSX attributes in the render method). If the string is introduced at a point before the translation system has not yet been initialized, use `_td()` instead, and call `_t()` at the appropriate time. - 1. Run `npm run i18n` to update ``src/i18n/strings/en_EN.json`` (if it fails because it can't find the script, your dev environment predates the script, so reinstall/link react-sdk with `npm link ../matrix-react-sdk`). If it segfaults, you may be on Node 6, so try a newer version of node. + 1. Run `npm run i18n` to update ``src/i18n/strings/en_EN.json`` 1. If you added a string with a plural, you can add other English plural variants to ``src/i18n/strings/en_EN.json`` (remeber to edit the one in the same project as the source file containing your new translation). ## Adding variables inside a string. From c26cde2f6f56398c3eab0e2db4f7dd9cb8abdc14 Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sun, 29 Apr 2018 14:08:03 +1200 Subject: [PATCH 4/5] Correct npm command name in documentation The `npm run` command `i18n-prune` is actually `prunei18n`. --- docs/translating-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/translating-dev.md b/docs/translating-dev.md index 3238bd7349..28cd6242d9 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -32,7 +32,7 @@ function getColorName(hex) { 1. Edit every occurrence of the string inside `_t()` and `_td()` in the JSX files. 1. Run `npm run i18n` to update `src/i18n/strings/en_EN.json`. (Be sure to run this in the same project as the JSX files you just edited.) -1. Run `npm run i18n-prune` to remove the old string from `src/i18n/strings/*.json`. +1. Run `npm run prunei18n` to remove the old string from `src/i18n/strings/*.json`. ## Adding new strings From 95b09cde60eb3c050add78d5e884db78660d74b0 Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sun, 29 Apr 2018 14:08:57 +1200 Subject: [PATCH 5/5] Reorder sections in translating documentation Move "Editing existing strings" to after "Adding new strings". --- docs/translating-dev.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/translating-dev.md b/docs/translating-dev.md index 28cd6242d9..d058c7cdbd 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -28,12 +28,6 @@ function getColorName(hex) { } ``` -## Editing existing strings - -1. Edit every occurrence of the string inside `_t()` and `_td()` in the JSX files. -1. Run `npm run i18n` to update `src/i18n/strings/en_EN.json`. (Be sure to run this in the same project as the JSX files you just edited.) -1. Run `npm run prunei18n` to remove the old string from `src/i18n/strings/*.json`. - ## Adding new strings 1. Check if the import ``import { _t } from 'matrix-react-sdk/lib/languageHandler';`` is present. If not add it to the other import statements. Also import `_td` if needed. @@ -41,6 +35,12 @@ function getColorName(hex) { 1. Run `npm run i18n` to update ``src/i18n/strings/en_EN.json`` 1. If you added a string with a plural, you can add other English plural variants to ``src/i18n/strings/en_EN.json`` (remeber to edit the one in the same project as the source file containing your new translation). +## Editing existing strings + +1. Edit every occurrence of the string inside `_t()` and `_td()` in the JSX files. +1. Run `npm run i18n` to update `src/i18n/strings/en_EN.json`. (Be sure to run this in the same project as the JSX files you just edited.) +1. Run `npm run prunei18n` to remove the old string from `src/i18n/strings/*.json`. + ## Adding variables inside a string. 1. Extend your ``_t()`` call. Instead of ``_t(STRING)`` use ``_t(STRING, {})``