Merge branch 'fork/maoxuner/fix/lang-doc'

This commit is contained in:
金毛88
2026-07-21 22:48:41 +08:00
2 changed files with 16 additions and 20 deletions

View File

@@ -60,25 +60,23 @@ To add new translation texts, simply find `src/locales/langs/` in the correspond
**src/locales/langs/zh-CN/\*.json** **src/locales/langs/zh-CN/\*.json**
````ts
```json ```json
{ {
"about": { "about": {
"desc": "Vben Admin 是一个现代的管理模版。" "desc": "Vben Admin 是一个现代的管理模版。"
} }
} }
```` ```
**src/locales/langs/en-US.ts** **src/locales/langs/en-US/\*.json**
````ts
```json ```json
{ {
"about": { "about": {
"desc": "Vben Admin is a modern management template." "desc": "Vben Admin is a modern management template."
} }
} }
```` ```
## Using Translation Texts ## Using Translation Texts
@@ -91,11 +89,11 @@ With `@vben/locales`, you can easily use translation texts:
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
const items = computed(() => [{ title: $t('about.desc') }]); const items = computed(() => [{ title: $t('demos.title') }]);
</script> </script>
<template> <template>
<div>{{ $t('about.desc') }}</div> <div>{{ $t('demos.title') }}</div>
<template v-for="item in items.value"> <template v-for="item in items">
<div>{{ item.title }}</div> <div>{{ item.title }}</div>
</template> </template>
</template> </template>
@@ -105,8 +103,8 @@ const items = computed(() => [{ title: $t('about.desc') }]);
If you need to add a new language pack, follow these steps: If you need to add a new language pack, follow these steps:
- Add the corresponding language pack file in the `packages/locales/langs` directory, for example, `zh-TW.json`, and translate the respective texts. - Create the corresponding language pack folder and files under `packages/locales/langs` (e.g., `zh-TW/*.json`) and translate the texts accordingly.
- In the corresponding application, locate the `src/locales/langs` file and add the new language pack `zh-TW.json`. - In the corresponding application, find the `src/locales/langs` directory and create the same language pack folder and files (e.g., `zh-TW/*.json`).
- Add the corresponding language in `packages/constants/src/core.ts`: - Add the corresponding language in `packages/constants/src/core.ts`:
```ts ```ts

View File

@@ -60,25 +60,23 @@ updateLocale('en-US');
**src/locales/langs/zh-CN/\*.json** **src/locales/langs/zh-CN/\*.json**
````ts
```json ```json
{ {
"about": { "about": {
"desc": "Vben Admin 是一个现代的管理模版。" "desc": "Vben Admin 是一个现代的管理模版。"
} }
} }
```` ```
**src/locales/langs/en-US.ts** **src/locales/langs/en-US/\*.json**
````ts
```json ```json
{ {
"about": { "about": {
"desc": "Vben Admin is a modern management template." "desc": "Vben Admin is a modern management template."
} }
} }
```` ```
## 使用翻译文本 ## 使用翻译文本
@@ -91,11 +89,11 @@ updateLocale('en-US');
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
const items = computed(() => [{ title: $t('about.desc') }]); const items = computed(() => [{ title: $t('demos.title') }]);
</script> </script>
<template> <template>
<div>{{ $t('about.desc') }}</div> <div>{{ $t('demos.title') }}</div>
<template v-for="item in items.value"> <template v-for="item in items">
<div>{{ item.title }}</div> <div>{{ item.title }}</div>
</template> </template>
</template> </template>
@@ -105,8 +103,8 @@ const items = computed(() => [{ title: $t('about.desc') }]);
如果你需要新增语言包,需要按照以下步骤进行: 如果你需要新增语言包,需要按照以下步骤进行:
- 在 `packages/locales/langs` 目录下新增对应的语言包文件,例:`zh-TW.json`,并翻译对应的文本。 - 在 `packages/locales/langs` 目录下新增对应的语言包文件夹和文件,例:`zh-TW/*.json`,并翻译对应的文本。
- 在对应的应用内,找到 `src/locales/langs` 文件,新增对应的语言包 `zh-TW.json` - 在对应的应用内,找到 `src/locales/langs` 目录,新增对应的语言包文件夹和文件 `zh-TW/*.json`。
- 在 `packages/constants/src/core.ts`内,新增对应的语言: - 在 `packages/constants/src/core.ts`内,新增对应的语言:
```ts ```ts