Skip to content

Commit 6910fe6

Browse files
authored
Merge pull request #60 from openimis/feature/OP-766
OP-766: added section about translation based on experience to help with set up it
2 parents 99f2007 + 404f35b commit 6910fe6

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Note: This image only provides the openimis frontend server. The full openIMIS d
163163
"@openimis/fe-contract": "file:../openimis-fe-contract_js",
164164
...
165165
}
166-
...
166+
...
167167
}
168168
```
169169

@@ -192,3 +192,78 @@ Note: This image only provides the openimis frontend server. The full openIMIS d
192192
- from `/openimis-fe_js`:
193193
- run this command: `node dev_tools/installModuleLocallyAll.js`. This command will execute all required steps
194194
to fetch all modules present in `openimis.json` from the git repositories and install them as editable libraries.
195+
196+
197+
## Managing translations/localization
198+
199+
### To add new translation/localisations:
200+
- create separate new module based on [frontend template module](https://github.com/openimis/openimis-fe-template_js).
201+
- this module should be named like: `openimis-fe-language_{lang}_js` for example `openimis-fe-language_es_js` (Spanish language)
202+
- add to this module such files as: `.babelrc`, `.gitignore`, `.estlintrc`
203+
- within `src/translation` add `{lang}.json` file for example `es.json`
204+
- in `index.js` within `src` modified (for example we want to have 'es' Spanish language):
205+
```js
206+
import messages_es from "./translations/es.json";
207+
208+
const DEFAULT_CONFIG = {
209+
"translations": [{ key: "es", messages: messages_es }],
210+
}
211+
212+
export const LanguageEsModule = (cfg) => {
213+
return { ...DEFAULT_CONFIG, ...cfg };
214+
}
215+
```
216+
- build your new module with translations by typing within this module `yarn build`, `yarn install` and `yarn link` commands.
217+
- in `tblLanguages` on database level add new language for example 'es' (Spanish language)
218+
- within assembly frontend module `openimis-fe_js` in `openimis.json` add language key for new language/localization for example:
219+
```json
220+
...
221+
"locales": [
222+
{
223+
"languages": [
224+
"es",
225+
"es-ES"
226+
],
227+
"intl": "es-ES",
228+
"fileNames": "es"
229+
},
230+
{
231+
"languages": [
232+
"en",
233+
"en-GB"
234+
],
235+
"intl": "en-GB",
236+
"fileNames": "en"
237+
},
238+
{
239+
"languages": [
240+
"fr",
241+
"fr-FR"
242+
],
243+
"intl": "fr-FR",
244+
"fileNames": "fr"
245+
}
246+
],
247+
...
248+
```
249+
- in `openimis.json` add also this newly created module with translations
250+
- within `openimis-fe_js/src` in `locales.js` add new language like below:
251+
```js
252+
export const locales = ["es-ES","en-GB","fr-FR"]
253+
export const fileNamesByLang = {"es":"es", "es-ES":"es","en":"en","en-GB":"en","fr":"fr","fr-FR":"fr"}
254+
export default {"es":"es-ES", "es-ES": "es-ES","en":"en-GB","en-GB":"en-GB","fr":"fr-FR","fr-FR":"fr-FR"}
255+
```
256+
- type `yarn build` and if success - type `yarn start` and you should see this translation in your app (go to 'users' page, select user, change language into the newly provided, refresh page and you should see texts in changed language)
257+
- there is also possibility to overwrite particular language for example 'English' into 'Gambian English' (without changes on database level). In your new translation module in index.js (for example new module called `openimis-fe-language_en_gm_js`):
258+
```js
259+
import messages_en from "./translations/en.json";
260+
261+
const DEFAULT_CONFIG = {
262+
"translations": [{ key: "en", messages: messages_en }],
263+
}
264+
265+
export const LanguageEnGmModule = (cfg) => {
266+
return { ...DEFAULT_CONFIG, ...cfg };
267+
}
268+
```
269+
- this approach overwrites default `en` language translations into `en-gm` (Gambian English) translations without adding new language on database level and without changing 'locales' in 'openimis.json' and 'locales.js' file both on assembly frontend module (openimis-fe_js).

0 commit comments

Comments
 (0)