Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getLocale = () => {
let languageCode = 'en'
try {
languageCode = i18n.language.split('-')[0]
} catch (e) {
// noop
}
if (loadedLocales[languageCode] !== undefined) {
return loadedLocales[languageCode]
}
return loadedLocales['en']
}
SyncService.get().then((data) => {
data = data || {};
const savedSettings = data['settings-v1.0'] || {};
const languageChanged = savedSettings.language !== i18next.language;
store.dispatch(loaded(savedSettings));
const settings = store.getState().settings;
localStorage.setItem('dimLanguage', settings.language);
if (languageChanged) {
i18next.changeLanguage(settings.language);
}
readyResolve();
// Start saving settings changes
unsubscribe = saveSettingsOnUpdate();
});
}
// the current language is English. We expect the hard-coded default
// language of all non-configurable UI to be English.
if (
(i18next.language === config.flavor.defaultLanguage.code ||
isFetchingTranslation[key] ||
key === fallbackValue) &&
isValidNonConfigurableI18nKey(key, i18next.language)
) {
return;
}
isFetchingTranslation[key] = true;
const response = await translationServiceClient.translate({
text: fallbackValue,
target: i18next.language,
});
// eslint-disable-next-line require-atomic-updates
isFetchingTranslation[key] = false;
if (response) {
i18next.addResource(i18next.language, ns, key, response.body);
} else {
i18next.addResource(i18next.language, ns, key, fallbackValue);
}
},
});
messageDispatcher.subscribe('App', (message) => {
if (message.type === 'nav') {
this.setState({curNav: message.message});
} else if (message.type === 'profile') {
this.fetchApi();
} else if (message.type === 'loggedIn') {
this.setState({loggedIn: message.message}, () => {
console.log("loggedIn", this.state.loggedIn);
if (!this.state.loggedIn) {
this.fetchApi();
}
});
} else if (message.type === 'lang') {
this.setState({lang: i18next.language});
} else if (message.type === 'delete') {
if (message.role === 'user') {
var confirmModal = {
title: i18next.t("admin.confirm-delete-user-title", {user: message.user.name}),
message: i18next.t("admin.confirm-delete-user", {username: message.user.username, name: message.user.name}),
callback: this.confirmDeleteUser
}
this.setState({confirmModal: confirmModal, curUser: message.user}, () => {
$("#confirmModal").modal({keyboard: false, show: true});
});
} else if (message.role === 'client') {
var confirmModal = {
title: i18next.t("admin.confirm-delete-client-title", {client: message.client.name}),
message: i18next.t("admin.confirm-delete-client", {clientId: message.client.client_id, name: message.client.name}),
callback: this.confirmDeleteClient
}
},() => {
moment.locale(languageToMomentLocale(i18n.language));
setDefaultLocale(i18n.language);
});
export function getCurrentLanguage() {
if (i18next.language) {
return i18next.language;
}
return 'en';
}
export function getCurrentLanguage(): string {
return i18n.language;
}
const openChangeLanguagePopper = event => {
setValue(i18next.language.substring(0, 2));
setAnchorEl(anchorEl ? null : event.currentTarget);
};
this.state.config.lang.forEach((lang, i) => {
if (lang === i18next.language) {
langList.push(<a href="#">{lang}</a>);
} else {
langList.push(<a href="#"> this.changeLang(e, lang)} key={i}>{lang}</a>);
}
});
this.state.schemeList.forEach((scheme, index) => {