Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
i18next.init({
languages: ['sv'],
fallbackLng: ['sv'],
resources: {
sv: {
translation: sv,
},
},
});
// Update this to reflect what language your page should use
const lang = () => {
return 'sv';
};
i18next.changeLanguage(lang());
export default i18next;
updateLanguage() {
const newLanguage = this.props.route.match.params.lang || this.state.defaultLanguage;
if (i18n.language !== newLanguage) {
this.languageIsChanging = true;
i18n.changeLanguage(newLanguage, () => {
this.languageIsChanging = false;
// if the component is not mounted, we don't care
// (next time it mounts, it will render with the right language context)
if (this.componentIsMounted) {
// after we change the i18n language, we need to force-update React,
// since otherwise React won't know that the dictionary has changed
// because it is stored in i18next state not React state
this.forceUpdate();
}
});
}
}
const changeLng = (lng: string) => {
i18next.changeLanguage(lng)
}
AsyncStorage.getItem('@BertyApp:i18n-language', (err, language) => {
if (err) {
return
}
if (!languages.hasOwnProperty(language)) {
return
}
i18n.changeLanguage(language)
})
})
return new Promise((resolve) => {
i18next.changeLanguage(language, resolve);
});
}
AsyncStorage.getItem('@BertyApp:i18n-language', (err, language) => {
if (err) {
return
}
if (!languages.hasOwnProperty(language)) {
return
}
i18n.changeLanguage(language)
})
})
const dispatchRoute = (dispatch, routeUrl, params) => {
const routeParams = parseRouteUrl(routeUrl);
if (!routeParams) {
return;
}
if (routeParams.lang) {
i18n.changeLanguage(routeParams.lang);
}
const route = routeParams.sitecoreRoute ? `/${routeParams.sitecoreRoute}` : '/';
dispatch({
type: types.ROUTE_CHANGE_STARTED,
payload: {
path: route,
},
});
const language = routeParams.lang || DEFAULT_LANGUAGE;
fetchRouteData(route, language, params)
.then((data) => {
dispatch(push(routeUrl));
dispatch({
type: types.ROUTE_CHANGE_COMPLETED,
(lng: string) => {
i18n.changeLanguage(lng);
setV(i18n.language);
},
];
i18next.changeLanguage(langCode).then(() => {
resolve(langCode);
});
})
.fail(e => {
if (langCode != "en") {
this.reset("en").then(() => {
resolve(langCode);
});
return;
}
reject(e);
});
return;
}
i18next.changeLanguage(langCode).then(() => {
resolve(langCode);
});
return;
}
resolve(langCode);
});
}
export function changeCurrentLanguage(language: Language): void {
i18n.changeLanguage(language);
}