多语言篇
国际化基于 lime-i18n,语言包位于 src/i18n/locales/,默认提供简体中文与英语。
添加文案
同时修改:
src/i18n/locales/zh-CN.jsonsrc/i18n/locales/en-US.json
只加一边会导致切换语言时直接显示 key。
页面使用
uts
import { $t, getI18nText, setNavigationBarTitle } from '@/src/i18n/utils/index.uts';
const title = $t('basic.langTitle');
const label = getI18nText('basic.langPreview');
setNavigationBarTitle('basic.langTitle');$t():明确知道是 key 时使用。getI18nText():值可能是 key,也可能是中文原文时使用。setNavigationBarTitle():传 key,内部负责翻译并同步自定义导航栏。
切换语言
uts
import { useI18nStore } from '@/src/store/index.uts';
import { setTabbarItem } from '@/src/tabbar/index.uts';
const i18nStore = useI18nStore();
i18nStore.setLocale('en-US');
setTabbarItem();语言会自动持久化。自定义 TabBar 文案不是响应式的,切换后需要主动刷新。
默认语言
在 .env 中设置:
ini
VITE_DEFAULT_LOCALE=zh-CN完整 key 规则、初始语言优先级和 API 说明见 src/i18n/README.md。
