Commit 891e494e authored by Matija Obreza's avatar Matija Obreza
Browse files

i18n: split translations by language to locales/{lng}/{ns}.json

parent dc97d542
......@@ -170,13 +170,9 @@ module.exports = {
new HtmlWebpackExcludeAssetsPlugin(),
// Used with i18next-http-backend plugin
// new CopyWebpackPlugin([
// { from: 'assets/images', to: 'images'},
// { from: 'assets/templates', to: 'templates'},
// { from: 'locales', to: 'locales'},
// { from: 'generated/locales', to: 'locales'},
// { from: '../../node_modules/leaflet/dist/images', to: 'images'},
// { from: '../../node_modules/ckeditor/', to: 'scripts/ckeditor'}
// { from: 'src/locales', to: 'locales'},
// ]),
],
......
import i18n from 'i18next';
// import HttpApi from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';
import translations from 'translations.json';
import transEn from 'locales/en/translations.json';
import transRu from 'locales/ru/translations.json';
// the translations
// Bundled resources
const resources = {
en: { translations: { ...transEn } },
ru: { translations: { ...transRu } },
};
// console.log('Translations', resources);
const initI18n = (lang) => {
return i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources: translations,
lng: lang,
// HttpApi loader options
// const loaderOptions = {
// loadPath: '/locales/{{lng}}/{{ns}}.json',
// // allow cross domain requests
// crossDomain: true,
// // allow credentials on cross domain requests
// withCredentials: false,
// };
interpolation: {
escapeValue: false,
},
});
const initI18n = (language = 'en') => {
const I = i18n
// .use(HttpApi)
.use(initReactI18next) // passes i18n down to react-i18next
.init({
lng: language,
lowerCaseLng: true,
fallbackLng: 'en',
ns: ['translations' ],
defaultNS: 'translations',
// fallbackNS: ''
preload: [],
load: 'languageOnly',
react: {
useSuspense: false,
},
resources: resources,
// partialBundledLanguages: true,
// backend: loaderOptions, // backend options
interpolation: {
escapeValue: false,
formatSeparator: ',',
format: (value, format, lng) => {
if (!value) {
return value;
} else if (format === 'uppercase') {
return value.toUpperCase();
} else if (format === 'lowercase') {
return value.toLowerCase();
} else if (format === 'number') {
return value && value.toLocaleString();
}
return value;
},
},
}, (err, t) => {
if (err) return console.log('Something went wrong loading', err);
return t('key');
});
return I;
}
export default initI18n;
{
"loading": "Loading",
"pag": {
"first": "First",
"prev": "Prev",
"next": "Next",
"last": "Last"
},
"error": {
"notFound": "Not Found"
}
}
{
"pag": {
"first": "Первая",
"prev": "Предыдущая",
"next": "Следующая",
"last": "Последняя"
},
"error": {
"notFound": "Страница не найдена"
}
}
\ No newline at end of file
{
"en": {
"translation": {
"nav": {
"home": "Home",
"apiInfo": "API info"
},
"pag": {
"first": "First",
"prev": "Prev",
"next": "Next",
"last": "Last"
},
"error": {
"notFound": "Not Found"
}
}
},
"ru": {
"translation": {
"nav": {
"home": "Дом",
"apiInfo": "ИПП Информация"
},
"pag": {
"first": "Первая",
"prev": "Предыдущая",
"next": "Следующая",
"last": "Последняя"
},
"error": {
"notFound": "Страница не найдена"
}
}
}
}
......@@ -3,13 +3,14 @@ import React from 'react';
import { AccessionService } from '@genesys/client/service';
import { Property } from './Property';
import AccessionDetails from '@genesys/client/model/accession/AccessionDetails';
import { WithTranslation, withTranslation } from 'react-i18next';
interface IAccessionDetailsPage {
match: any;
apiUrl: string;
}
export default class AccessionDetailsPage extends React.Component<IAccessionDetailsPage, any> {
class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithTranslation, any> {
public constructor(props) {
super(props);
}
......@@ -36,13 +37,13 @@ export default class AccessionDetailsPage extends React.Component<IAccessionDeta
public render() {
const { accession } = this.state;
const { apiUrl } = this.props;
const { apiUrl, t } = this.props;
let propertyIndex = 0;
if (accession === null) {
return (
<div>Loading...</div>
<div>{ t('loading') }</div>
);
} else {
const details = accession.details;
......@@ -147,3 +148,5 @@ export default class AccessionDetailsPage extends React.Component<IAccessionDeta
}
};
}
export default withTranslation()(AccessionDetailsPage);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment