Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Refactor i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina Contrino committed Nov 3, 2017
1 parent 0a7345d commit 248776b
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 89 deletions.
23 changes: 2 additions & 21 deletions app/src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import i18n from 'i18next'; // eslint-disable-line import/no-extraneous-dependencies
import languages from './languages';
import setup from '../../i18n/i18n-setup';

const resources = Object.keys(languages).reduce((accumulator, key) => {
accumulator[key] = {
common: languages[key].common,
};
return accumulator;
}, {});

i18n
.init({
fallbackLng: 'en',
resources,
lang: 'en',
ns: ['common'],
defaultNS: 'common',
saveMissing: true,
debug: false,
keySeparator: '>',
nsSeparator: '|',
});
const i18n = setup();

export default i18n;
12 changes: 0 additions & 12 deletions app/src/languages.js

This file was deleted.

File renamed without changes
File renamed without changes
27 changes: 27 additions & 0 deletions i18n/i18n-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import i18n from 'i18next';
import languages from './languages';

const setup = () => {
const resources = Object.keys(languages).reduce((accumulator, key) => {
accumulator[key] = {
common: languages[key].common,
};
return accumulator;
}, {});


return i18n
.init({
fallbackLng: 'en',
resources,
lang: 'en',
ns: ['common'],
defaultNS: 'common',
saveMissing: true,
debug: false,
keySeparator: '>',
nsSeparator: '|',
});
};

export default setup;
13 changes: 13 additions & 0 deletions i18n/languages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const languages = {
en: {
name: 'English',
common: require('./locales/en/common.json'),
flag: require('./flags/en.png'),
},
de: {
name: 'Deutsch',
common: require('./locales/de/common.json'),
flag: require('./flags/de.png'),
},
};
export default languages;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dist:win": "build --win --ia32 --x64",
"dist:mac": "build --mac",
"dist:linux": "build --linux --ia32 --x64 --armv7l",
"copy-files": "cpx \"./src/{index.html,assets/**/*,locales/**/*}\" ./app/build/",
"copy-files": "cpx \"./src/{index.html,assets/**/*}\" ./app/build/",
"clean-build": "rm -rf app/build",
"clean-dist": "rm -rf dist",
"eslint": "eslint ./src/ ./app/src/ ./app/config/ ./features/",
Expand Down
2 changes: 1 addition & 1 deletion src/components/languageDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { translate } from 'react-i18next';
import React from 'react';

import i18n from '../../i18n';
import languages from '../../constants/languages';
import languages from '../../../i18n/languages';

const languagesSource = Object.keys(languages).map(key => ({
value: key,
Expand Down
14 changes: 0 additions & 14 deletions src/constants/languages.js

This file was deleted.

42 changes: 2 additions & 40 deletions src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
import i18n from 'i18next';
import languages from './constants/languages';
import setup from '../i18n/i18n-setup';

const resources = Object.keys(languages).reduce((accumulator, key) => {
accumulator[key] = {
common: languages[key].common,
};
return accumulator;
}, {});

i18n
.init({
fallbackLng: 'en',
resources,
react: {
// wait: true, // globally set to wait for loaded translations in translate hoc
// exposeNamespace: true // exposes namespace on data-i18next-options to be used in eg.
},

// have a common namespace used around the full app
ns: ['common'],
defaultNS: 'common',

keySeparator: '>',
nsSeparator: '|',

debug: false,

// cache: {
// enabled: true,
// },

interpolation: {
escapeValue: false, // not needed for react!!
formatSeparator: ',',
format: (value, format) => {
if (format === 'uppercase') return value.toUpperCase();
return value;
},
},
});
const i18n = setup();

export default i18n;

0 comments on commit 248776b

Please sign in to comment.