code refactor

This commit is contained in:
MaysWind
2023-07-07 23:48:32 +08:00
parent 062a13b2c2
commit 9d0b874488
3 changed files with 29 additions and 44 deletions
+27
View File
@@ -153,6 +153,32 @@ function getAllLanguageInfos() {
return allLanguages; return allLanguages;
} }
function getAllLanguageInfoArray(translateFn, includeSystemDefault) {
const ret = [];
if (includeSystemDefault) {
ret.push({
code: '',
displayName: translateFn('System Default')
});
}
for (const code in allLanguages) {
if (!Object.prototype.hasOwnProperty.call(allLanguages, code)) {
continue;
}
const languageInfo = allLanguages[code];
ret.push({
code: code,
displayName: languageInfo.displayName
});
}
return ret;
}
function getLanguageInfo(locale) { function getLanguageInfo(locale) {
return allLanguages[locale]; return allLanguages[locale];
} }
@@ -746,6 +772,7 @@ export function translateError(message, translateFn) {
export function i18nFunctions(i18nGlobal) { export function i18nFunctions(i18nGlobal) {
return { return {
getAllLanguageInfos: getAllLanguageInfos, getAllLanguageInfos: getAllLanguageInfos,
getAllLanguageInfoArray: (includeSystemDefault) => getAllLanguageInfoArray(i18nGlobal.t, includeSystemDefault),
getLanguageInfo: getLanguageInfo, getLanguageInfo: getLanguageInfo,
getDefaultLanguage: getDefaultLanguage, getDefaultLanguage: getDefaultLanguage,
getCurrentLanguageInfo: () => getCurrentLanguageInfo(i18nGlobal), getCurrentLanguageInfo: () => getCurrentLanguageInfo(i18nGlobal),
@@ -270,28 +270,7 @@ export default {
computed: { computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore), ...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore),
allLanguages() { allLanguages() {
const ret = []; return this.$locale.getAllLanguageInfoArray(true);
const allLanguageInfo = this.$locale.getAllLanguageInfos();
ret.push({
code: '',
displayName: this.$t('System Default')
});
for (let code in allLanguageInfo) {
if (!Object.prototype.hasOwnProperty.call(allLanguageInfo, code)) {
continue;
}
const languageInfo = allLanguageInfo[code];
ret.push({
code: code,
displayName: languageInfo.displayName
});
}
return ret;
}, },
allCurrencies() { allCurrencies() {
return this.$locale.getAllCurrencies(); return this.$locale.getAllCurrencies();
+1 -22
View File
@@ -274,28 +274,7 @@ export default {
computed: { computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore), ...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore),
allLanguages() { allLanguages() {
const ret = []; return this.$locale.getAllLanguageInfoArray(true);
const allLanguageInfo = this.$locale.getAllLanguageInfos();
ret.push({
code: '',
displayName: this.$t('System Default')
});
for (let code in allLanguageInfo) {
if (!Object.prototype.hasOwnProperty.call(allLanguageInfo, code)) {
continue;
}
const languageInfo = allLanguageInfo[code];
ret.push({
code: code,
displayName: languageInfo.displayName
});
}
return ret;
}, },
allCurrencies() { allCurrencies() {
return this.$locale.getAllCurrencies(); return this.$locale.getAllCurrencies();