2
0

2 Commity 71675be095 ... ccb5822468

Autor SHA1 Správa Dátum
  liangan ccb5822468 Merge remote-tracking branch 'origin/development' 1 týždeň pred
  liangan d228606a01 fix: 多语言修复 1 týždeň pred
2 zmenil súbory, kde vykonal 19 pridanie a 2 odobranie
  1. 11 1
      src/locale/index.ts
  2. 8 1
      src/pages/mine/setting.vue

+ 11 - 1
src/locale/index.ts

@@ -12,8 +12,18 @@ const messages = {
   'zh-Hans': zhHans, // key 不能乱写,查看截图 screenshots/i18n.png
   bn,
 }
+
+const supportedLocales = ['en', 'zh-Hans', 'bn'] as const
+type SupportedLocale = typeof supportedLocales[number]
+
+function normalizeLocale(locale: string | undefined | null): SupportedLocale {
+  if (supportedLocales.includes(locale as SupportedLocale))
+    return locale as SupportedLocale
+  return 'bn'
+}
+
 const i18n = createI18n({
-  locale: uni.getLocale() === 'bn' ? 'bn' : 'bn', // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
+  locale: normalizeLocale(uni.getLocale()), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
   messages,
   allowComposition: true,
 })

+ 8 - 1
src/pages/mine/setting.vue

@@ -24,7 +24,14 @@ const columns = computed(() => {
     { label: 'বাংলা', value: 'bn' },
   ]
 })
-const language = ref(uni.getLocale() === 'bn' ? 'bn' : 'bn')
+function normalizeLocale(locale: string | undefined | null) {
+  const supportedLocales = ['en', 'zh-Hans', 'bn']
+  if (supportedLocales.includes(locale as any))
+    return locale as any
+  return 'bn'
+}
+
+const language = ref(normalizeLocale(uni.getLocale()))
 function changeLanguage(data: any) {
   console.log(data)
   // 下面2句缺一不可!!!