Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/objectui-i18n-guide-locale-tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@objectstack/skills': patch
---

docs(skills): the objectui i18n guide teaches the platform locale table's tags (`zh-Hans`, `zh-Hant`, `pt-BR`) for the built-in packs, a language switcher fed by `PLATFORM_LOCALES`, and the read aliases that keep a stored `zh` / `zh-CN` / `zh-TW` / `pt` resolving

Clause-②: no
Metadata-protocol: none
34 changes: 13 additions & 21 deletions skills/objectui/guides/i18n.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# ObjectUI Internationalization (i18n)

Multi-language support via `@object-ui/i18n`.

## Setup

```typescript
Expand All @@ -10,10 +8,10 @@ import { I18nProvider, createI18n } from '@object-ui/i18n';
const i18n = createI18n({
defaultLanguage: 'en',
fallbackLanguage: 'en',
detectBrowserLanguage: true, // Auto-detect from navigator
detectBrowserLanguage: true,
resources: {
en: { common: { save: 'Save', cancel: 'Cancel' } },
zh: { common: { save: '保存', cancel: '取消' } },
'zh-Hans': { common: { save: '保存', cancel: '取消' } },
},
});

Expand All @@ -28,27 +26,29 @@ function App() {

## Built-in locales

The package includes translations for:
- English (`en`), Chinese (`zh`), Japanese (`ja`), Korean (`ko`)
- German (`de`), French (`fr`), Spanish (`es`), Portuguese (`pt`)
- Russian (`ru`), Arabic (`ar`)
One pack per row of the platform locale table (`PLATFORM_LOCALES`, `@objectstack/spec/system`),
keyed by tag: `en`, `zh-Hans`, `zh-Hant`, `es`, `ar`, `fr`, `pt-BR`, `ru`, `de`, `ja`, `ko`
(`@object-ui/i18n/locales/<tag>`). No `zh` or `pt` pack: a stored `zh` / `zh-CN` resolves
to `zh-Hans`, `zh-TW` to `zh-Hant` and `pt` to `pt-BR` via the table's read aliases
(`resolveBuiltInLanguage`). Write the tag.

## useObjectTranslation hook

<!-- os:check -->
```typescript
import { useObjectTranslation } from '@object-ui/i18n';
import { resolveBuiltInLanguage, useObjectTranslation } from '@object-ui/i18n';
import { PLATFORM_LOCALES } from '@objectstack/spec/system';

function Header() {
const { t, language, changeLanguage, direction } = useObjectTranslation();

return (
<header dir={direction}>
<h1>{t('common.appTitle')}</h1>
<select value={language} onChange={(e) => changeLanguage(e.target.value)}>
<option value="en">English</option>
<option value="zh">中文</option>
<option value="ar">العربية</option>
<select value={resolveBuiltInLanguage(language) ?? language} onChange={(e) => changeLanguage(e.target.value)}>
{PLATFORM_LOCALES.map(({ tag, label }) => (
<option key={tag} value={tag}>{label}</option>
))}
</select>
</header>
);
Expand All @@ -75,11 +75,6 @@ For large apps, load translations on demand instead of bundling all locales:

RTL is automatic for Arabic, Hebrew, and other RTL languages. The provider updates `document.dir` when the language changes.

```typescript
const { direction } = useObjectTranslation();
// direction: 'ltr' | 'rtl'
```

For Tailwind layout adjustments, use RTL-aware utilities:

```html
Expand Down Expand Up @@ -153,8 +148,6 @@ that travels without a bundle carries its own languages.

## Language-aware + responsive page

When combining with `@object-ui/mobile` for responsive layouts:

```typescript
import { I18nProvider } from '@object-ui/i18n';
import { useBreakpoint } from '@object-ui/mobile';
Expand All @@ -176,7 +169,6 @@ function App() {

## Common mistakes

- Bundling all locale files upfront — use lazy loading for apps with many languages.
- Forgetting `dir={direction}` on root elements — RTL layout won't apply.
- Using `{key, defaultValue}` translation objects — that key-reference vocabulary was retired.
`@objectstack/spec` rejects the object with its own message: *an inline
Expand Down
Loading