Skip to content

Commit

Permalink
Add guards around localStorage in case user disables it (#1399)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin authored Feb 25, 2021
1 parent e3a3a3a commit 681f481
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions source/javascripts/app/_lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ under the License.
history.pushState({}, '', '?' + generateNewQueryString(language) + '#' + hash);

// save language as next default
localStorage.setItem("language", language);
if (localStorage) {
localStorage.setItem("language", language);
}
}

function setupLanguages(l) {
var defaultLanguage = localStorage.getItem("language");
var defaultLanguage = null;
if (localStorage) {
defaultLanguage = localStorage.getItem("language");
}

languages = l;

Expand All @@ -142,7 +147,9 @@ under the License.
// the language is in the URL, so use that language!
activateLanguage(presetLanguage);

localStorage.setItem("language", presetLanguage);
if (localStorage) {
localStorage.setItem("language", presetLanguage);
}
} else if ((defaultLanguage !== null) && (jQuery.inArray(defaultLanguage, languages) != -1)) {
// the language was the last selected one saved in localstorage, so use that language!
activateLanguage(defaultLanguage);
Expand Down

0 comments on commit 681f481

Please sign in to comment.