feat: add turkish automatic recognition (#486)

* feat: add turkish automatic recognition

* Update src/store/index.js
This commit is contained in:
wenjie 2021-03-25 15:17:44 +08:00 committed by GitHub
parent 750e1997e6
commit bf61fe6e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,9 +27,12 @@ const store = new Vuex.Store(options);
if ([undefined, null].includes(store.state.settings.lang)) {
const defaultLang = "en";
// when more languages are available, use Map instead of prefer logic
const preferChinese = navigator.language.slice(0, 2) === "zh";
store.state.settings.lang = preferChinese ? "zh-CN" : defaultLang;
const langMapper = new Map()
.set("zh", "zh-CN")
.set("en", "en")
.set("tr", "tr");
store.state.settings.lang =
langMapper.get(navigator.language.slice(0, 2)) || defaultLang;
localStorage.setItem("settings", JSON.stringify(store.state.settings));
}