use local storage to cache locale choice
This commit is contained in:
parent
a15dd897ae
commit
af9abdaf4f
20
js/l10n.js
20
js/l10n.js
|
@ -72,6 +72,11 @@ l10n.MESSAGES = {
|
|||
*/
|
||||
l10n.current = 0;
|
||||
|
||||
/**
|
||||
* Local storage key.
|
||||
*/
|
||||
l10n.localStorageKey = 'sim8800locale';
|
||||
|
||||
/**
|
||||
* Switches to the next locale.
|
||||
*/
|
||||
|
@ -79,6 +84,21 @@ l10n.nextLocale = function() {
|
|||
l10n.current++;
|
||||
l10n.current = l10n.current % l10n.LOCALES.length;
|
||||
l10n.updateMessages();
|
||||
localStorage.setItem(l10n.localStorageKey, l10n.current);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restores the last locale from local storage.
|
||||
*/
|
||||
l10n.restoreLocale = function() {
|
||||
var val = localStorage.getItem(l10n.localStorageKey);
|
||||
if (val) {
|
||||
var index = parseInt(val);
|
||||
if (!isNaN(index)) {
|
||||
l10n.current = index % l10n.LOCALES.length;
|
||||
l10n.updateMessages();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -553,6 +553,9 @@ panel.sim = null;
|
|||
* Initializes thie UI.
|
||||
*/
|
||||
panel.init = function() {
|
||||
// Restores the last locale if it exists.
|
||||
l10n.restoreLocale();
|
||||
|
||||
// Initializes event listener for nav buttons.
|
||||
var button = document.getElementById('locale');
|
||||
button.addEventListener('click', l10n.nextLocale, false);
|
||||
|
|
Loading…
Reference in New Issue
Block a user