@rexezuge/i18n 1.0.0 → 1.0.2

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 +45 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @rexezuge/i18n
2
+
3
+ Backend string bundle with twelve locales and `Accept-Language`-aware lookup.
4
+
5
+ Zero dependencies. The bundle is one `common` group; the locale table, the fallback chain, and the lookup are the parts every consumer boundary needs.
6
+
7
+ ```bash
8
+ pnpm add @rexezuge/i18n
9
+ ```
10
+
11
+ Supported locales: `en`, `de`, `fr`, `es`, `it`, `nl`, `pt`, `pl`, `ja`, `ko`, `zh-CN`, `zh-TW`.
12
+
13
+ ---
14
+
15
+ ## 1. Lookup
16
+
17
+ ```ts
18
+ import { getLocalizedStrings, resolveLocalizedStrings } from '@rexezuge/i18n';
19
+
20
+ getLocalizedStrings('fr'); // French bundle; null/undefined/''/unknown all land on en — never undefined
21
+ resolveLocalizedStrings(acceptLanguageHeader, user.storedLocale); // header first, stored preference second
22
+ ```
23
+
24
+ `resolveLocalizedStrings(locale, fallback)` models the header-plus-stored-preference pair: the stored preference only speaks when the header does not express a real choice (an explicit `en` header and an absent header are deliberately indistinguishable, so a browser sending `en` while the user picked `ja` still gets `ja`).
25
+
26
+ ## 2. Shape
27
+
28
+ ```ts
29
+ import { LOCALE_STRINGS, normalizeLocale, SUPPORTED_LOCALES, type BackendStrings } from '@rexezuge/i18n';
30
+
31
+ normalizeLocale('pt-BR'); // 'pt' — BCP 47 canonicalization shared with @rexezuge/shared
32
+ const bundle: BackendStrings = LOCALE_STRINGS.en;
33
+ ```
34
+
35
+ `LOCALE_STRINGS` is typed as a total `Record`, so adding a locale to `SUPPORTED_LOCALES` without adding a bundle is a compile error rather than a runtime `undefined` at the boundary. Individual bundles (`enStrings`, `deStrings`, …) are also exported for migration scripts, tests, and bundle-level integrity checks. Locale-file parity (keys, empty values, `{{placeholder}}` parity) is enforced by `@rexezuge/tooling`'s `validate-locales` script.
36
+
37
+ ---
38
+
39
+ ## Verifying this package
40
+
41
+ ```bash
42
+ pnpm --filter @rexezuge/i18n exec tsc -p tsconfig.json
43
+ pnpm --filter @rexezuge/i18n typecheck
44
+ pnpm --filter @rexezuge/i18n test
45
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/i18n",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,7 @@
29
29
  "typescript": "6.0.3",
30
30
  "vitest": "4.1.11"
31
31
  },
32
+ "description": "Backend string bundle with twelve locales and Accept-Language-aware lookup.",
32
33
  "scripts": {
33
34
  "build": "tsc -p tsconfig.json",
34
35
  "typecheck": "tsc -p tsconfig.test.json --noEmit",