@betteroffice/docx-i18n 0.0.1 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +26 -73
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -1,117 +1,70 @@
1
1
  # @betteroffice/docx-i18n
2
2
 
3
- Shared locale strings, types, and runtime helpers for the [OpenOOXML DOCX editor](https://betteroffice.dev) adapters. One source of truth for translations consumed by `@betteroffice/docx-react` and `@betteroffice/docx-vue`.
3
+ UI locale strings, types, and runtime helpers for the
4
+ [`@betteroffice/docx-react`](https://www.npmjs.com/package/@betteroffice/docx-react)
5
+ editor. `en` is the source of truth; community locales mirror its shape and fall
6
+ back to English for any untranslated key.
4
7
 
5
- ## Quick Start
8
+ > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
6
9
 
7
10
  ```bash
8
- npm install @betteroffice/docx-i18n
11
+ bun add @betteroffice/docx-i18n
9
12
  ```
10
13
 
14
+ ## Usage
15
+
11
16
  Pass a typed locale to the editor's `i18n` prop:
12
17
 
13
18
  ```tsx
14
- // React
15
19
  import { de } from '@betteroffice/docx-i18n';
16
- <DocxEditor documentBuffer={file} i18n={de} />
17
20
 
18
- // Vue
19
- import { de } from '@betteroffice/docx-i18n';
20
- <DocxEditor :document-buffer="file" :i18n="de" />
21
+ <DocxEditor documentBuffer={file} i18n={de} />;
21
22
  ```
22
23
 
23
- Mix a community locale with custom overrides:
24
+ Override individual strings by spreading a locale:
24
25
 
25
26
  ```ts
26
27
  import { de } from '@betteroffice/docx-i18n';
27
28
 
28
- const myLocale = {
29
- ...de,
30
- toolbar: { ...de.toolbar, bold: 'Fettdruck' },
31
- };
29
+ const myLocale = { ...de, toolbar: { ...de.toolbar, bold: 'Fettdruck' } };
32
30
  ```
33
31
 
34
32
  Keys set to `null` in any locale fall back to English.
35
33
 
36
- ## Packages
37
-
38
- | Package | Description |
39
- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
40
- | [`@betteroffice/docx-react`](https://www.npmjs.com/package/@betteroffice/docx-react) | <img src="https://cdn.simpleicons.org/react/61DAFB" width="20" align="middle" /> &nbsp; React adapter. Toolbar, paged editor, plugins. |
41
- | [`@betteroffice/docx-vue`](https://www.npmjs.com/package/@betteroffice/docx-vue) | <img src="https://cdn.simpleicons.org/vuedotjs/4FC08D" width="20" align="middle" /> &nbsp; Vue 3 adapter. Toolbar, paged editor, plugins. |
42
- | [`@betteroffice/docx`](https://www.npmjs.com/package/@betteroffice/docx) | Framework-agnostic core: OOXML parser, serializer, layout engine, ProseMirror schema. Depend on this if you fork the React or Vue adapter. |
43
- | [`@betteroffice/docx-i18n`](https://www.npmjs.com/package/@betteroffice/docx-i18n) | Shared locale strings and types consumed by both adapters. |
44
-
45
- > **Forking the adapter?** Keep your fork thin. Depend on `@betteroffice/docx` directly so parser, serializer, and rendering fixes land in your build automatically, without backporting each upstream change by hand.
46
-
47
- ## Available locales
48
-
49
- | Code | Export | Language |
50
- | ------- | ------ | ------------------- |
51
- | `en` | `en` | English (source) |
52
- | `de` | `de` | German |
53
- | `he` | `he` | Hebrew |
54
- | `pl` | `pl` | Polish |
55
- | `pt-BR` | `ptBR` | Portuguese (Brazil) |
56
- | `tr` | `tr` | Turkish |
57
- | `zh-CN` | `zhCN` | Simplified Chinese |
58
-
59
- BCP-47 codes (`pt-BR`, `zh-CN`) use camelCase JS identifiers (`ptBR`, `zhCN`). For runtime lookup by tag:
60
-
61
- ```ts
62
- import { locales } from '@betteroffice/docx-i18n';
63
- <DocxEditor i18n={locales[userPreferredLocale]} />
64
- ```
34
+ ## Locales
65
35
 
66
- > Importing `locales` pulls every locale into your bundle. For a smaller bundle, import only the ones you need by name; `sideEffects: false` lets the rest tree-shake.
36
+ `en` (source), `de`, `he`, `pl`, `pt-BR`, `tr`, `zh-CN`. BCP-47 tags use
37
+ camelCase identifiers (`ptBR`, `zhCN`).
67
38
 
68
- ## Per-locale subpaths
69
-
70
- For apps that pick the locale at runtime, the named exports above don't tree-shake — the bundler can't know which locale wins, so it ships them all. Use the per-locale subpaths instead. Each one bundles a single locale (~30KB) and code-splits cleanly:
71
-
72
- ```ts
73
- // Static — bundler ships only this locale's strings
74
- import pl from '@betteroffice/docx-i18n/pl';
75
-
76
- // Dynamic — splits into its own chunk, loaded on demand
77
- const pl = (await import('@betteroffice/docx-i18n/pl')).default;
78
- ```
79
-
80
- Subpaths ship for every locale: `/en`, `/de`, `/he`, `/pl`, `/pt-BR`, `/tr`, `/zh-CN`. Each also exports its locale as a named binding (`import { pl } from '@betteroffice/docx-i18n/pl'`) for callers that prefer non-default imports.
39
+ Each locale also ships as its own subpath (`@betteroffice/docx-i18n/pl`) so an
40
+ app that picks the locale at runtime can code-split rather than bundle them all.
41
+ For lookup by tag, `import { locales } from '@betteroffice/docx-i18n'` (pulls
42
+ every locale into the bundle).
81
43
 
82
44
  ## Types
83
45
 
84
46
  ```ts
85
47
  import type {
86
48
  LocaleStrings, // shape of `en`, the full source of truth
87
- PartialLocaleStrings, // shape of a community partial (null falls back)
88
- Translations, // alias for PartialLocaleStrings
49
+ PartialLocaleStrings, // a community partial (null falls back)
89
50
  TranslationKey, // 'toolbar.bold' | 'dialogs.findReplace.title' | ...
90
51
  LocaleCode, // 'en' | 'de' | 'pt-BR' | ...
91
- TFunction, // signature of the `t()` callback
52
+ TFunction,
92
53
  } from '@betteroffice/docx-i18n';
93
54
  ```
94
55
 
95
- ## Non-React/Vue hosts
56
+ ## Non-React hosts
96
57
 
97
- Build a typed `t()` outside the adapter packages:
58
+ Build a typed `t()` directly:
98
59
 
99
60
  ```ts
100
61
  import { createT, deepMerge, en, de, type LocaleStrings } from '@betteroffice/docx-i18n';
101
62
 
102
- const merged = deepMerge(en, de) as LocaleStrings;
103
- const t = createT(merged, 'de');
63
+ const t = createT(deepMerge(en, de) as LocaleStrings, 'de');
104
64
  t('toolbar.bold'); // 'Fett'
105
- t('dialogs.findReplace.matchCount', { current: 3, total: 15 }); // ICU plurals
106
65
  ```
107
66
 
108
- `en.json` is the source of truth. Add keys there, then run `bun run i18n:fix` from the repo root to sync community locales (new keys land as `null`). Full guide: [docs/i18n.md](https://github.com/openooxml/betteroffice/blob/main/docs/i18n.md).
109
-
110
- ## Contributing
111
-
112
- Contributions welcome. See [CONTRIBUTING.md](https://github.com/openooxml/betteroffice/blob/main/CONTRIBUTING.md) for setup, tests, and the one-time CLA signature.
113
-
114
- ## Commercial Support
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`).
115
69
 
116
- > [!TIP]
117
- > Questions or feature requests? Open an issue at **[github.com/openooxml/betteroffice](https://github.com/openooxml/betteroffice/issues)**.
70
+ Docs: https://betteroffice.dev · Apache-2.0.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@betteroffice/docx-i18n",
3
- "version": "0.0.1",
4
- "description": "Shared UI locale strings and types for the @betteroffice/docx editor adapters (React and Vue).",
3
+ "version": "0.0.3",
4
+ "description": "UI locale strings and types for the @betteroffice/docx-react editor.",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.mjs",
7
7
  "module": "./dist/index.mjs",
@@ -67,7 +67,9 @@
67
67
  },
68
68
  "keywords": [
69
69
  "docx",
70
+ "ooxml",
70
71
  "editor",
72
+ "react",
71
73
  "i18n",
72
74
  "locales",
73
75
  "translations"