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;
}
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) {
return allLanguages[locale];
}
@@ -746,6 +772,7 @@ export function translateError(message, translateFn) {
export function i18nFunctions(i18nGlobal) {
return {
getAllLanguageInfos: getAllLanguageInfos,
getAllLanguageInfoArray: (includeSystemDefault) => getAllLanguageInfoArray(i18nGlobal.t, includeSystemDefault),
getLanguageInfo: getLanguageInfo,
getDefaultLanguage: getDefaultLanguage,
getCurrentLanguageInfo: () => getCurrentLanguageInfo(i18nGlobal),
@@ -270,28 +270,7 @@ export default {
computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore),
allLanguages() {
const ret = [];
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;
return this.$locale.getAllLanguageInfoArray(true);
},
allCurrencies() {
return this.$locale.getAllCurrencies();
+1 -22
View File
@@ -274,28 +274,7 @@ export default {
computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore),
allLanguages() {
const ret = [];
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;
return this.$locale.getAllLanguageInfoArray(true);
},
allCurrencies() {
return this.$locale.getAllCurrencies();