Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { createInstance } from 'i18next';
import { setI18n, getI18n } from 'react-i18next';
export default function getDefaultT() {
return getI18n().t.bind(getI18n());
}
if (!getI18n()) {
// eslint-disable-next-line no-console
console.warn('@talend/react-datagrid used without i18n host.');
setI18n(createInstance({}, () => {}));
}
switch (window.language.substr(0, 2).toLowerCase()) {
case 'zh':
window.language = 'zh-TW'
break
case 'ja':
window.language = 'ja-JP'
break
case 'ko':
window.language = 'ko-KR'
break
default:
window.language = 'en-US'
}
}
const i18next = I18next.createInstance()
i18next.use(reactI18nextModule).init({
lng: window.language,
fallbackLng: false,
resources: mainPoiRes,
ns: mainPoiNs,
defaultNS: 'others',
interpolation: {
escapeValue: false,
},
returnObjects: true, // allow returning objects
debug: dbg && dbg.extra('i18next').isEnabled(),
react: {
wait: false,
nsMode: 'fallback',
usePureComponent: true,
import React from 'react';
import { I18nextProvider, initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import source from '../common.json';
const i18n = i18next.createInstance();
i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
initImmediate: false,
resources: {
en: {
translation: { ...source },
},
},
fallbackLng: 'zh',
keySeparator: false,
react: {
useSuspense: false,
},
});
export default () => {
// Load translations for each language
const resources = {
de,
en,
fr,
ja,
nl,
'pt-BR': ptBr,
'zh-CN': zhCn,
'zh-TW': zhTw,
};
const instance = i18n.createInstance();
instance
.use(initReactI18next)
.init({
fallbackLng: 'en',
interpolation: {
escapeValue: false, // react is already safe from xss
},
lng: 'en',
resources,
});
return instance;
};
it('should fail to load non existent language translation', (cb) => {
const i18next = createInstance();
i18next.use(FetchBackend).init(
{
fallbackLng: 'de',
ns: 'translation',
backend: {
loadPath: 'http://localhost:3000/{{lng}}/{{ns}}.json',
},
},
(err) => {
expect(err).to.deep.equal([
'failed loading http://localhost:3000/de/translation.json',
]);
cb();
},
const initializeI18n = () => {
const i18n = i18next.createInstance();
i18n
.use(languageDetector)
.use(initReactI18next)
.init({
resources,
fallbackLng: FALLBACK_LANGUAGE,
interpolation: {
format: (value, format) => {
if (format === 'uppercase') { return value.toUpperCase(); }
return value;
},
},
});
const originalTranslator = i18n.t.bind(i18n);
i18n.t = ((key: string | string[] | ITranslateObject | ITranslateKey, options: {}) => {
export const i18n = locales => {
const i18nConfig = {
lng: defaultLocale,
fallbackLng: defaultLocale,
lowerCaseLng: true,
resources: locales || paprikaLocales,
};
const newInstance = i18next.createInstance(i18nConfig, err => {
if (err) return console.log("something went wrong loading i18next", err);
return null;
});
return newInstance;
};
static init(lng){
i18n.language = lng;
i18n.$instance = i18next.createInstance({
lng: lng,
fallbackLng: 'en',
resources: {
en: {
translation: en
},
pl: {
translation: pl
},
it: {
translation: it
},
de: {
translation: de
},
fr: {