Frontend internationalization (i18n)
The frontend uses vue-i18n to provide a Chinese, English, and Japanese interface, and Element Plus's built-in text switches along with the language.
Directory structure
web/src/i18n/
├── index.ts # createI18n, locale detection, switching entry point
└── locales/
├── zh-CN/
│ ├── common.ts # shared strings (navigation, route titles, actions, errors, etc.)
│ ├── index.ts # aggregates common and the modules under views
│ └── views/*.ts # strings split by page/feature
├── en-US/
│ └── ... # key tree fully mirroring zh-CN
└── ja-JP/
└── ... # key tree fully mirroring en-USviews/*.ts files are loaded automatically via import.meta.glob, so adding a module file requires no changes to the aggregation entry point.
The language preference is stored in localStorage under axmipic.locale.v1; on the first visit it is inferred from the browser language: Chinese environments use zh-CN, Japanese environments use ja-JP, and everything else uses en-US. The language can be switched both from the top bar in the console and from the floating button on public pages.
Using it in components
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
</script>
<template>
<el-button :title="t('common.refresh')">{{ t('common.save') }}</el-button>
<p>{{ t('users.selection.count', { count: selected.length }) }}</p>
</template>- Template attributes use bindings:
:label,:placeholder,:title,:aria-label,:empty-text. - Interpolation always uses
{name}; pass an object at the call site rather than concatenating strings. - Strings in
ElMessage,ElMessageBox, and form validation rules must also go throught(). - Outside a setup context (stores, utility functions, API clients), use
translate('key'). - Chinese text in module-level constant arrays does not update when the language changes; put it in
computed(() => [...])or rendert(item.labelKey)in the template.
Adding new strings
- Add the same keys to
zh-CN/views/<module>.ts,en-US/views/<module>.ts, andja-JP/views/<module>.ts; all key trees must be exactly identical. - Keep the user-visible original wording in Chinese, and use concise, natural English and Japanese for the other locales.
- For dynamic labels that must still update after a language switch, use
computed. - Do not translate user data, API paths, enum values, configuration keys, storage driver identifiers, or URLs.
Caveats
@must be escaped: vue-i18n treats@as linked-message syntax. To display a literal@, write{'@'}, e.g.you{\'@\'}example.com(single-quoted strings need escaping).|means plural: do not use a bare|in ordinary strings.- Literal
{or}in strings must likewise be escaped according to vue-i18n syntax. - Switching the language also updates
<html lang>, the page title, andmeta[name="description"]; server error messages that have already been fetched and cached are not translated automatically — re-requesting will use the frontend fallback text in the new language. - The Element Plus locale pack is injected according to the current language in
el-config-providerinApp.vue; when adding a language, the corresponding Element Plus locale must be added as well.
Adding a language
- Create a new locale directory under
src/i18n/locales/and copy the complete key tree. - Register it in
SUPPORTED_LOCALES,LOCALE_OPTIONS, andmessagesinsrc/i18n/index.ts. - Add the Element Plus locale mapping in
App.vue. - Run
pnpm typecheckandpnpm build, and check that everyt()key exists in all languages.
Validation
cd web
pnpm typecheck # type checking
pnpm build # build the embedded artifactsBefore committing, it is recommended to confirm there is no missed user-visible Chinese (comments excluded) with the following command:
grep -rnP '[\x{4e00}-\x{9fa5}]' src --include=*.vue --include=*.ts | grep -v 'src/i18n/locales'