Browse Source

Merge remote-tracking branch 'origin/development'

liangan 1 week ago
parent
commit
ccb5822468
2 changed files with 19 additions and 2 deletions
  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句缺一不可!!!