Only parse JSON once

This commit is contained in:
andrey-git 2017-10-28 11:55:30 +03:00
parent 1a7fa6041e
commit e9d84d2a69

View File

@ -25,8 +25,16 @@ function getActiveTranslation() {
} }
let translation = null; let translation = null;
if (window.localStorage.selectedLanguage && JSON.parse(window.localStorage.selectedLanguage)) { let selectedLanguage;
translation = languageGetTranslation(JSON.parse(window.localStorage.selectedLanguage)); if (window.localStorage.selectedLanguage) {
try {
selectedLanguage = JSON.parse(window.localStorage.selectedLanguage);
} catch (e) {
// Ignore parsing error.
}
}
if (selectedLanguage) {
translation = languageGetTranslation(selectedLanguage);
if (translation) { if (translation) {
return translation; return translation;
} }