Skip to content

Commit

Permalink
Merge pull request #170 from WildAid/add_localization_info
Browse files Browse the repository at this point in the history
Adding Localization instructions...
  • Loading branch information
Azzoo authored Sep 1, 2020
2 parents ae6e760 + c65a69d commit b9286e7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
41 changes: 41 additions & 0 deletions LOCALIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Localization information for the o-fish-web project

Localization is in src/helpers/i18n/

Every translation has a directory with its language code, and a translation.json file. e.g.:
src/helpers/i18n/en/translation.json
src/helpers/i18n/es-419/translation.json
src/helpers/i18n/fr/translation.json

When adding a NEW language, you will need to add it in 3 places in src/helpers/i18n/index.js:
1. Import it, e.g.:
` import en from './en/translation';`
` import fr from './fr/translation';`

2. Update the "default to en" to NOT include the new language:
`if (!(lang.includes('fr') || lang.includes('es'))) {`
` lang = 'en';`
`}`

3. You will need to add it into the resources, e.g.:
`const i18nOptions = {`
` resources: {`
` en: {`
` translation: en`
` },`
` fr: {`
` translation: fr`
` }`
` }`
` };`



The format is a json document where the variable name is in ALL CAPS and in quotes, e.g.:
`{`
` "LOGIN_PAGE": {`
` "LOGIN": "Connexion",`
` "FORGOT_PASSWORD": "Mot de passe oublié?",`
` "EMAIL_USERNAME": "Email/Identifiant:",`
` "PASSWORD": "Mot de passe"`

6 changes: 5 additions & 1 deletion src/helpers/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import detector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

import en from './en/translation';
import fr from './fr/translation';

let lang = navigator.language || navigator.userLanguage;

if (!(lang.includes('en') || lang.includes('fr') || lang.includes('es'))) {
if (!(lang.includes('fr') || lang.includes('es'))) {
lang = 'en';
}

Expand All @@ -17,6 +18,9 @@ const i18nOptions = {
resources: {
en: {
translation: en
},
fr: {
translation: fr
}
}
};
Expand Down

0 comments on commit b9286e7

Please sign in to comment.