Skip to content

Commit 2275bf4

Browse files
committed
Updated the code links that are mentioned in Technical Part since the codes have benn updated and pointed out the different code block.
Added the details on Nav.js and i18n.js.
1 parent d32cb71 commit 2275bf4

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

developer_docs/translations.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,47 @@ In order to simplify the translations process the following rules of thumb were
1010
## Technical Part
1111

1212
* There is only one file to translate all the texts in any specific language, which is located under the directory, in respective locale [subdirectory](https://github.com/processing/p5.js-web-editor/tree/develop/translations/locales)
13-
* The new language code must be added to [client/i18n.js](https://github.com/processing/p5.js-web-editor/blob/develop/client/i18n.js#L7)
14-
* New languages will need to be selected using a dropdown in Nav component, specifically in function [renderLanguageMenu.](https://github.com/processing/p5.js-web-editor/blob/develop/client/components/Nav.jsx#L550)
13+
* The new language code must be added to [client/i18n.js](https://github.com/processing/p5.js-web-editor/blob/develop/client/i18n.js#L8)
14+
* New languages will need to be selected using a dropdown in Nav component, specifically in function [renderLanguageMenu.](https://github.com/processing/p5.js-web-editor/blob/develop/client/components/Nav.jsx#L611)
1515
* Need to add `TRANSLATIONS_ENABLED=true` to `.env` to activate dropdown for the languages.
1616

17+
#### Nav.js
18+
Need to add the following code to add a new language as a dropdown menu.
19+
```js
20+
<li className="nav__dropdown-item">
21+
<button
22+
onFocus={this.handleFocusForLang}
23+
onBlur={this.handleBlur}
24+
value="newLanguageValue"
25+
onClick={e => this.handleLangSelection(e)}
26+
>
27+
new language name in the new language ex: 日本語 (Japanese)
28+
</button>
29+
</li>
30+
```
31+
32+
#### i18n.js
33+
In terms of `i18n.js`, you will need to update 2 things. One is to import a new language from `date-fns/locale`. The other is to add a new language to `languageMap`.
34+
35+
```js
36+
import { enUS, es, ja, newLanguage } from 'date-fns/locale';
37+
const availableLanguages = ['en-US', 'es-419', 'ja', 'newLanguage'];
38+
```
39+
40+
```js
41+
export function languageKeyToDateLocale(lang) {
42+
const languageMap = {
43+
'en-US': enUS,
44+
'es-419': es,
45+
'ja': ja
46+
'newLanguage': newLanguage
47+
};
48+
return languageMap[lang];
49+
}
50+
```
51+
52+
53+
1754
## Translations
1855

1956
* Every component should introduce its own subset of keys inside a dictionary named after the component.

0 commit comments

Comments
 (0)