feat(i18n): standardize bilingual catalogs and tooling
This commit is contained in:
+13
-15
@@ -28,8 +28,8 @@ Create `i18n.config.json` in that application:
|
||||
|
||||
```json
|
||||
{
|
||||
"sourceLocale": "en",
|
||||
"locales": ["en", "zh-Hans"],
|
||||
"sourceLocale": "en-US",
|
||||
"locales": ["en-US", "zh-Hans"],
|
||||
"catalogPath": "src/locales/{locale}/messages",
|
||||
"catalogSources": [
|
||||
"@workspace/ui/locales/{locale}",
|
||||
@@ -96,7 +96,7 @@ function Root({
|
||||
<I18nProvider
|
||||
locale={locale}
|
||||
locales={[
|
||||
{ locale: "en", label: "English" },
|
||||
{ locale: "en-US", label: "English" },
|
||||
{ locale: "zh-Hans", label: "简体中文" },
|
||||
]}
|
||||
catalogs={{ [locale]: messages }}
|
||||
@@ -126,22 +126,22 @@ function Greeting() {
|
||||
}
|
||||
```
|
||||
|
||||
`@workspace/ui` and every `@workspace/blocks` block provide `de`, `en`, `es`,
|
||||
`fr`, `ja`, `ko`, `zh-Hans`, and `zh-Hant` as independent locale subpaths.
|
||||
Import only the blocks and languages enabled by the application:
|
||||
`@workspace/ui`, `@workspace/lexical`, and every `@workspace/blocks` block
|
||||
provide only `en-US` and `zh-Hans` as independent locale subpaths. Import only
|
||||
the blocks and language enabled by the application:
|
||||
|
||||
```ts
|
||||
import {
|
||||
calendarLocale,
|
||||
messages as uiJapanese,
|
||||
} from "@workspace/ui/locales/ja"
|
||||
import { messages as navigationJapanese } from "@workspace/blocks/navigation/locales/ja"
|
||||
messages as uiEnglish,
|
||||
} from "@workspace/ui/locales/en-US"
|
||||
import { messages as navigationEnglish } from "@workspace/blocks/navigation/locales/en-US"
|
||||
```
|
||||
|
||||
The UI root `locales` entry and each block-specific `locales` entry export
|
||||
metadata and types only. They do not statically import catalogs. For example,
|
||||
using `@workspace/blocks/navigation` and
|
||||
`@workspace/blocks/navigation/locales/ja` does not import appearance, chats,
|
||||
`@workspace/blocks/navigation/locales/en-US` does not import appearance, chats,
|
||||
layout, notifications, or their translations. The UI locale entry also
|
||||
exposes its matching `react-day-picker` `calendarLocale`.
|
||||
|
||||
@@ -182,7 +182,7 @@ and available locales from the provider, while the Vite `i18n()` plugin serves
|
||||
catalog reads, updates, extraction, and compilation.
|
||||
|
||||
```tsx
|
||||
<I18nProvider locale="zh-Hans" locales={["en", "zh-Hans"]}>
|
||||
<I18nProvider locale="zh-Hans" locales={["en-US", "zh-Hans"]}>
|
||||
<App />
|
||||
{import.meta.env.DEV && <I18nDevtool dark={"ui\\:dark"} />}
|
||||
</I18nProvider>
|
||||
@@ -205,8 +205,7 @@ Pass a BCP 47 language tag with `locale` to select it explicitly:
|
||||
|
||||
When `locale` is omitted, the Devtool selects the first supported entry from
|
||||
`navigator.languages` and falls back to English. Built-in control-panel
|
||||
locales are English, German, Spanish, French, Japanese, Korean, Simplified
|
||||
Chinese, and Traditional Chinese.
|
||||
locales are English (`en-US`) and Simplified Chinese (`zh-Hans`).
|
||||
|
||||
Lower-level `MessagePanel`, `MessageRepositoryProvider`, and repository types
|
||||
remain available from `@workspace/i18n/devtool`.
|
||||
@@ -222,7 +221,6 @@ Run inside the consuming application so the CLI discovers that application's
|
||||
`i18n.config.json`:
|
||||
|
||||
```sh
|
||||
bun run i18n new ja
|
||||
bun run i18n extract
|
||||
bun run i18n compile
|
||||
bun run i18n ui
|
||||
@@ -249,4 +247,4 @@ bun run i18n:compile
|
||||
|
||||
The application's `i18n.config.json` is the single machine-editable source of
|
||||
truth. Runtime catalog access, Devtool actions, extraction, and compilation all
|
||||
derive their Lingui configuration from it.
|
||||
derive their Lingui configuration from it.
|
||||
Reference in New Issue
Block a user