@betteroffice/docx-i18n 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,10 @@ UI locale strings, types, and runtime helpers for the
|
|
|
5
5
|
editor. `en` is the source of truth; community locales mirror its shape and fall
|
|
6
6
|
back to English for any untranslated key.
|
|
7
7
|
|
|
8
|
-
> **
|
|
8
|
+
> **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
|
|
9
|
+
> components, collaboration — are settling and unlikely to change shape. Smaller
|
|
10
|
+
> APIs may still move between releases; breaking changes are always listed in
|
|
11
|
+
> the changelog.
|
|
9
12
|
|
|
10
13
|
```bash
|
|
11
14
|
bun add @betteroffice/docx-i18n
|
|
@@ -17,6 +20,7 @@ Pass a typed locale to the editor's `i18n` prop:
|
|
|
17
20
|
|
|
18
21
|
```tsx
|
|
19
22
|
import { de } from '@betteroffice/docx-i18n';
|
|
23
|
+
import { DocxEditor } from '@betteroffice/docx-react';
|
|
20
24
|
|
|
21
25
|
<DocxEditor documentBuffer={file} i18n={de} />;
|
|
22
26
|
```
|
|
@@ -24,47 +28,32 @@ import { de } from '@betteroffice/docx-i18n';
|
|
|
24
28
|
Override individual strings by spreading a locale:
|
|
25
29
|
|
|
26
30
|
```ts
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const myLocale = { ...de, toolbar: { ...de.toolbar, bold: 'Fettdruck' } };
|
|
31
|
+
const myLocale = { ...de, formattingBar: { ...de.formattingBar, bold: 'Fettdruck' } };
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
Keys set to `null` in any locale fall back to English.
|
|
33
35
|
|
|
34
36
|
## Locales
|
|
35
37
|
|
|
36
|
-
`en` (source), `de`, `he`, `pl`, `pt-BR`, `tr`, `zh-CN`.
|
|
37
|
-
camelCase identifiers (`ptBR`, `zhCN`).
|
|
38
|
+
`en` (source), `de`, `fr`, `he`, `hi`, `id`, `pl`, `pt-BR`, `tr`, `zh-CN`.
|
|
39
|
+
BCP-47 tags use camelCase identifiers (`ptBR`, `zhCN`).
|
|
38
40
|
|
|
39
41
|
Each locale also ships as its own subpath (`@betteroffice/docx-i18n/pl`) so an
|
|
40
42
|
app that picks the locale at runtime can code-split rather than bundle them all.
|
|
41
43
|
For lookup by tag, `import { locales } from '@betteroffice/docx-i18n'` (pulls
|
|
42
44
|
every locale into the bundle).
|
|
43
45
|
|
|
44
|
-
## Types
|
|
46
|
+
## Types and helpers
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
PartialLocaleStrings, // a community partial (null falls back)
|
|
50
|
-
TranslationKey, // 'toolbar.bold' | 'dialogs.findReplace.title' | ...
|
|
51
|
-
LocaleCode, // 'en' | 'de' | 'pt-BR' | ...
|
|
52
|
-
TFunction,
|
|
53
|
-
} from '@betteroffice/docx-i18n';
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Non-React hosts
|
|
57
|
-
|
|
58
|
-
Build a typed `t()` directly:
|
|
48
|
+
The package exports `LocaleStrings`, `PartialLocaleStrings`, `Translations`,
|
|
49
|
+
`TranslationKey`, `LocaleCode`, `TFunction`, `createT`, and `deepMerge`. For
|
|
50
|
+
non-React hosts, build a typed `t()` directly:
|
|
59
51
|
|
|
60
52
|
```ts
|
|
61
53
|
import { createT, deepMerge, en, de, type LocaleStrings } from '@betteroffice/docx-i18n';
|
|
62
54
|
|
|
63
55
|
const t = createT(deepMerge(en, de) as LocaleStrings, 'de');
|
|
64
|
-
t('
|
|
56
|
+
t('formattingBar.bold'); // 'Fett'
|
|
65
57
|
```
|
|
66
58
|
|
|
67
|
-
Add keys to `en.json`, then `bun run i18n:fix` from the repo root to sync the
|
|
68
|
-
community locales (new keys land as `null`).
|
|
69
|
-
|
|
70
59
|
Docs: https://betteroffice.dev · Apache-2.0.
|