Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Commit a7c170d

Browse files
authored
Merge pull request #505 from onaio/dashboard-translations
Dashboard translations
2 parents b5335bf + 23900f5 commit a7c170d

15 files changed

Lines changed: 374 additions & 2 deletions

File tree

docs/translations/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Translation Docs
2+
3+
This directory contains documentation on translation configs and dependencies.
4+
5+
## Translation Switcher
6+
7+
All language configs reside inside APP object and will be responsible for driving the translation switcher.
8+
9+
```json
10+
"languageSwitcherConfigs": {
11+
"English": {
12+
"param": "en"
13+
},
14+
"ជនជាតិខ្មែរ": {
15+
"param": "khmer"
16+
}
17+
},
18+
```
19+
20+
You can have the translation switcher on the map or have it on the superset iframe views. To choose this set this flag accordingly.
21+
22+
```json
23+
"mapLanguageTranslation": false,
24+
```
25+
26+
## Components Translations
27+
28+
A look up object will be responsible for handling the various translations. The strings for the various components will reside in the languageTranslation object keyed by the language with the translations for the various strings as values.
29+
30+
NB - The language key in languageTranslation object must match param value provided on languageSwitcherConfigs params.
31+
32+
All components i.e legend, titlebar, layers, menu sections or subsections will require the entire string to be translated added to the lookup object, except for the popup which will require every individual string to be added on the lookup object.
33+
34+
### Iframe translations
35+
36+
The Iframe translation currently works by switching the iframe link and can be added to the languageTranslations lookup object as shown below
37+
38+
```json
39+
"languageTranslations": {
40+
"khmer": {
41+
// Provide the full string for layers, titlebar, menu section and subsections.
42+
"Domain 2: Capacity of the child protection system": "ជនជាតិខ្មែរ ជនជាតិខ្មែរ ជនជាតិខ្មែរ",
43+
"Indicator 2.2 RCFs ": "ជនជាតិខ្មែរ ជនជាតិខ្មែរ",
44+
"RCI": "ជនជា",
45+
"Number of RCIs in the country (all residential care facilities)": "ជនជាតិខ្មែរ ជនជាតិខ្មែរ ជនជាតិខ្មែរ ជនជាតិខ្មែរ ជនជាតិខ្មែរ ជនជាតិខ្មែរ",
46+
" Source: Inspection Database, 2018": "ជនជាតិខ្មែរ ជនជាតិខ្មែរ តិខ្មែរ ជនជា តិខ្មែរ",
47+
// replace current iframe with the translated kind
48+
"splashPage": {
49+
"link": "https://discover.ona.io/superset/dashboard/517/?standalone=true"
50+
},
51+
"Cambodia Child Protection Profile 2018": "ជនជាតិខ្មែរ",
52+
// titlebar strings
53+
"Powered by": "ជនជាតិខ្មែរ",
54+
"Data Map": "ជនជា",
55+
// popup strings (must be supplied individually)
56+
"Mondul": "ជនជា"
57+
}
58+
},
59+
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"d3": "^4.13.0",
7878
"highcharts": "^6.0.4",
7979
"history": "^4.9.0",
80+
"html2plaintext": "2.0.0",
8081
"i": "^0.3.6",
8182
"js-cookie": "^2.2.0",
8283
"jsx-loader": "^0.13.2",

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,7 @@ gisida.localStorage = {};
8080
gisida.localStorage.loadState = require('./utils/localStorage').loadState;
8181
gisida.localStorage.saveState = require('./utils/localStorage').saveState;
8282
gisida.isTokenExpired = require('./utils/isTokenExpired').default;
83+
gisida.translationHook = require('./utils/translationHook').default;
84+
gisida.htmlTextTranslations = require('./utils/htmlTextTranslations').default;
8385

8486
module.exports = gisida;

src/map/addPopUp.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Mustache from 'mustache';
22
import { getCurrentState } from '../store/actions/actions';
3+
import htmlTextTranslations from '../utils/htmlTextTranslations';
34
import commaFormatting from './../utils/commaFormatting';
45

56
/**
@@ -24,7 +25,8 @@ export default function addMousemoveEvent(mapId, mapboxGLMap, dispatch) {
2425
popup.remove();
2526
// Get layers from current state
2627
const currentState = dispatch(getCurrentState());
27-
const { layers, timeseries, activeLayerId } = currentState[mapId];
28+
const { layers, timeseries, activeLayerId, } = currentState[mapId];
29+
const { APP: { languageTranslations }, CURRENTLANGUAGE } = currentState;
2830
// Generate list of active layers
2931
const activeLayers = [];
3032
Object.keys(layers).forEach(key => {
@@ -253,6 +255,8 @@ export default function addMousemoveEvent(mapId, mapboxGLMap, dispatch) {
253255

254256
// Add popup if content exists
255257
if (content) {
258+
/** Translate popup Values */
259+
content = htmlTextTranslations(content, true, languageTranslations, CURRENTLANGUAGE)
256260
popup
257261
.setLngLat(map.unproject(e.point))
258262
.setHTML(content)

src/store/actions/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ export const buildCategories = (groups, mapLayers) => ({
340340
mapLayers,
341341
});
342342

343+
export const setLanguage = (mapId, language) => {
344+
return {
345+
type: types.SET_LANGUAGE,
346+
language,
347+
mapId
348+
}
349+
};
350+
343351
export default {
344352
initApp,
345353
initStyles,
@@ -389,4 +397,5 @@ export default {
389397
fetchFormsError,
390398
logoutUser,
391399
buildCategories,
400+
setLanguage,
392401
};

src/store/constants/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const TOGGLE_MENU = 'TOGGLE_MENU';
2929
export const RESET_FILTERED_LAYER = 'RESET_FILTERED_LAYER';
3030
export const TOGGLE_CATEGORIES = 'TOGGLE_CATEGORIES';
3131
export const BUILD_CATEGORIES = 'BUILD_CATEGORIES';
32+
export const SET_LANGUAGE = 'SET_LANGUAGE';
3233

3334
// Auth action types
3435
export const INIT_AUTH = 'INIT_AUTH';

src/store/initStore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
MAP,
1515
AUTH,
1616
CATEGORIES,
17+
CURRENTLANGUAGE
1718
} from './reducers';
1819

1920
import { loadJSON } from '../utils/files';
@@ -32,6 +33,7 @@ const defaultReducers = {
3233
AUTH,
3334
'map-1': MAP,
3435
CATEGORIES,
36+
CURRENTLANGUAGE
3537
};
3638

3739
/**

src/store/reducers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export { default as SUPERSET_CONFIGS } from './superset-config';
99
export { default as MAP } from './map/';
1010
export { default as AUTH } from './auth';
1111
export { default as CATEGORIES } from './categories';
12+
export { default as CURRENTLANGUAGE } from './language';

src/store/reducers/language.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { SET_LANGUAGE } from '../constants/actionTypes';
2+
3+
export default function CURRENTLANGUAGE(state = {}, action) {
4+
switch (action.type) {
5+
case SET_LANGUAGE: {
6+
return {
7+
...state,
8+
...action.language,
9+
mapId: action.mapId,
10+
};
11+
}
12+
default:
13+
return state;
14+
}
15+
}

src/types/actionsInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ export interface Actions {
4747
locationUpdated(MapId:string):AnyAction;
4848
setLocation(mapId:string, loc:any):AnyAction;
4949
toggleMapLocation(loc:any):AnyAction;
50+
setLanguage(mapId:string, language:any):AnyAction;
5051
}

0 commit comments

Comments
 (0)