按设计稿修改,中英文,ios图标问题,statusbar等
This commit is contained in:
1 parent
b6e6905d05
commit
5462cf5abe
37 files changed
+1641
-975
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
import zh from './locales/zh.json';
|
||||
import en from './locales/en.json';
|
||||
|
||||
const LANGUAGE_KEY = '@app_language';
|
||||
|
||||
// 语言配置类型
|
||||
export interface LanguageOption {
|
||||
key: string;
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
// 语言选项
|
||||
export const LANGUAGES: LanguageOption[] = [
|
||||
{
|
||||
key: 'zh',
|
||||
label: '中文',
|
||||
value: 'zh',
|
||||
},
|
||||
{
|
||||
key: 'en',
|
||||
label: 'English',
|
||||
value: 'en',
|
||||
},
|
||||
];
|
||||
|
||||
// 获取存储的语言
|
||||
export const getStoredLanguage = async (): Promise<string> => {
|
||||
try {
|
||||
const language = await AsyncStorage.getItem(LANGUAGE_KEY);
|
||||
return language || 'zh';
|
||||
} catch (error) {
|
||||
return 'zh';
|
||||
}
|
||||
};
|
||||
|
||||
// 保存语言选择
|
||||
export const saveLanguage = async (language: string): Promise<void> => {
|
||||
try {
|
||||
await AsyncStorage.setItem(LANGUAGE_KEY, language);
|
||||
} catch (error) {
|
||||
console.error('保存语言失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化 i18n
|
||||
i18n
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
compatibilityJSON: 'v3',
|
||||
resources: {
|
||||
zh: { translation: zh },
|
||||
en: { translation: en },
|
||||
},
|
||||
lng: 'zh',
|
||||
fallbackLng: 'zh',
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
// 从存储中加载语言设置
|
||||
getStoredLanguage().then((language) => {
|
||||
i18n.changeLanguage(language);
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Reference in new issue
Block a user