Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
feat: 言語の強制切替
Browse files Browse the repository at this point in the history
  • Loading branch information
nzws committed Sep 2, 2018
1 parent d3b807c commit c04b9d0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
12 changes: 12 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ <h4 id="splitter-profile-name" class="acct-small" style="height: 20px"></h4>
</ons-list>
<ons-list>
<ons-list-header data-i18n="config.preferences.system.title">システム設定</ons-list-header>
<ons-list-item>
<div class="center">
Language
</div>
<div class="right">
<ons-select id="lang-conf" onchange="changeLanguage(this.value)">
<option value="">Default</option>
<option value="en">English</option>
<option value="ja">日本語</option>
</ons-select>
</div>
</ons-list-item>
<ons-list-item>
<div class="center" data-i18n="config.preferences.system.openurl.title">
リンクの開き方
Expand Down
1 change: 1 addition & 0 deletions www/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function initevent() {
i++;
}
renderPreview();
elemId('lang-conf').value = localLang ? localLang : '';
}, 500);
}

Expand Down
38 changes: 24 additions & 14 deletions www/js/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ const languages = {
en: 'English',
};

const localLang = localStorage.getItem('knzkapp_language');

const i18n_init = () =>
new Promise((resolve, reject) => {
try {
navigator.globalization.getPreferredLanguage(
function(language) {
lng = language.value;
if (lng.split('-').length == 2) lng = lng.split('-')[0];
if (!languages[lng]) lng = 'en';
i18n_init_callback(lng, resolve);
},
function() {
i18n_init_callback('en', resolve);
}
);
} catch (e) {
i18n_init_callback('en', resolve);
if (localLang) {
i18n_init_callback(localLang, resolve);
} else {
try {
navigator.globalization.getPreferredLanguage(
function(language) {
lng = language.value;
if (lng.split('-').length == 2) lng = lng.split('-')[0];
if (!languages[lng]) lng = 'en';
i18n_init_callback(lng, resolve);
},
function() {
i18n_init_callback('en', resolve);
}
);
} catch (e) {
i18n_init_callback('en', resolve);
}
}
});

Expand All @@ -45,3 +51,7 @@ function dialog_i18n(id, m) {
interpolation: { escapeValue: false },
});
}

function changeLanguage(v) {
localStorage.setItem('knzkapp_language', v);
}

0 comments on commit c04b9d0

Please sign in to comment.