Skip to content

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-US

views/*.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 ​

vue
<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 through t().
  • 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 render t(item.labelKey) in the template.

Adding new strings ​

  1. Add the same keys to zh-CN/views/<module>.ts, en-US/views/<module>.ts, and ja-JP/views/<module>.ts; all key trees must be exactly identical.
  2. Keep the user-visible original wording in Chinese, and use concise, natural English and Japanese for the other locales.
  3. For dynamic labels that must still update after a language switch, use computed.
  4. 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, and meta[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-provider in App.vue; when adding a language, the corresponding Element Plus locale must be added as well.

Adding a language ​

  1. Create a new locale directory under src/i18n/locales/ and copy the complete key tree.
  2. Register it in SUPPORTED_LOCALES, LOCALE_OPTIONS, and messages in src/i18n/index.ts.
  3. Add the Element Plus locale mapping in App.vue.
  4. Run pnpm typecheck and pnpm build, and check that every t() key exists in all languages.

Validation ​

bash
cd web
pnpm typecheck   # type checking
pnpm build       # build the embedded artifacts

Before committing, it is recommended to confirm there is no missed user-visible Chinese (comments excluded) with the following command:

bash
grep -rnP '[\x{4e00}-\x{9fa5}]' src --include=*.vue --include=*.ts | grep -v 'src/i18n/locales'

Released under the MIT License