|
@@ -17,13 +17,30 @@ const supportedLocales = ['en', 'zh-Hans', 'bn'] as const
|
|
|
type SupportedLocale = typeof supportedLocales[number]
|
|
type SupportedLocale = typeof supportedLocales[number]
|
|
|
|
|
|
|
|
function normalizeLocale(locale: string | undefined | null): SupportedLocale {
|
|
function normalizeLocale(locale: string | undefined | null): SupportedLocale {
|
|
|
|
|
+ if (!locale)
|
|
|
|
|
+ return 'bn'
|
|
|
if (supportedLocales.includes(locale as SupportedLocale))
|
|
if (supportedLocales.includes(locale as SupportedLocale))
|
|
|
return locale as SupportedLocale
|
|
return locale as SupportedLocale
|
|
|
|
|
+
|
|
|
|
|
+ const lower = locale.toLowerCase()
|
|
|
|
|
+ if (lower.startsWith('en'))
|
|
|
|
|
+ return 'en'
|
|
|
|
|
+
|
|
|
return 'bn'
|
|
return 'bn'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getInitialLocale(): SupportedLocale {
|
|
|
|
|
+ const storedLocale = uni.getStorageSync('app_locale')
|
|
|
|
|
+ if (storedLocale)
|
|
|
|
|
+ return normalizeLocale(storedLocale)
|
|
|
|
|
+
|
|
|
|
|
+ const systemLocale = uni.getSystemInfoSync().language || uni.getLocale()
|
|
|
|
|
+ const normalized = normalizeLocale(systemLocale)
|
|
|
|
|
+ return normalized === 'en' ? 'en' : 'bn'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const i18n = createI18n({
|
|
const i18n = createI18n({
|
|
|
- locale: normalizeLocale(uni.getLocale()), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
|
|
|
|
|
|
|
+ locale: getInitialLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
|
|
|
messages,
|
|
messages,
|
|
|
allowComposition: true,
|
|
allowComposition: true,
|
|
|
})
|
|
})
|