123456789101112131415161718192021222324252627282930313233343536 |
- //引入配置文件
- import { createI18n } from "vue-i18n"; //引入vue-1i8n
- import en from './en.json'; // 英文
- import zhHans from './zh-Hans.json'; // 中文
- import { ref } from 'vue'
- // const userLanguage = ref( uni.getLocale() || 'zh-Hans');
- const userLanguage = ref('zh-Hans');
- uni.setStorageSync('userLanguage', userLanguage.value); // 存储到缓存
- //创建配置
- const i18n = createI18n({
- locale: userLanguage.value,
- fallbackLocale: 'zh-Hans',
- messages: {
- 'en':en,
- 'zh-Hans':zhHans
- },
- })
-
- async function setLanguage(language) {
- userLanguage.value = language;
- uni.setStorageSync('userLanguage', language); // 存储到缓存
- uni.setLocale(language)
- location.reload(); // 刷新页面
- }
- function t(key,params){
- return i18n.global.t(key,params)
- }
- //导出配置
- export default i18n
- export {
- setLanguage,
- t
- }
|