@ingram-tech/nk-i18n 0.1.3 → 0.2.0
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/dist/core.d.ts +17 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +1 -0
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
type MessageCatalog = Record<string, string>;
|
|
2
2
|
declare const I18N_KEY_BRAND: unique symbol;
|
|
3
|
+
declare const LOCALIZED_STRING_BRAND: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A string that has passed through a {@link Translator} — display-ready text in
|
|
6
|
+
* the active locale. It is a plain `string` at runtime (the brand is erased), so
|
|
7
|
+
* it flows anywhere a `string` is wanted; the brand only matters where a prop is
|
|
8
|
+
* tightened to require `LocalizedString`, which turns hardcoded English at that
|
|
9
|
+
* boundary into a compile error. Sites that need to pass deliberately
|
|
10
|
+
* untranslated text (a name, an id, a number) opt out with `x as LocalizedString`.
|
|
11
|
+
*/
|
|
12
|
+
export type LocalizedString = string & {
|
|
13
|
+
readonly [LOCALIZED_STRING_BRAND]: "LocalizedString";
|
|
14
|
+
};
|
|
3
15
|
/**
|
|
4
16
|
* A set of per-locale message catalogs, keyed by locale code. The English
|
|
5
17
|
* source text is used as the key, so there is no `en` catalog: a missing lookup
|
|
@@ -32,8 +44,12 @@ type DeepMessageKeys<TValue> = TValue extends string ? I18nKey<TValue> : TValue
|
|
|
32
44
|
* source the key is checked against the catalogs at compile time; without one,
|
|
33
45
|
* any literal string is allowed. The optional `values` are interpolated with
|
|
34
46
|
* ICU MessageFormat (`{name}`, `{count, number}`, plurals, …).
|
|
47
|
+
*
|
|
48
|
+
* The return is branded {@link LocalizedString} so a prop can require translated
|
|
49
|
+
* text; interpolation done here stays branded, but composing with `+` or a
|
|
50
|
+
* template literal collapses back to a plain `string`.
|
|
35
51
|
*/
|
|
36
|
-
export type Translator<TSource extends MessageSource | undefined = undefined> = <const TValue extends string>(english: AllowedMessageKey<TSource, TValue>, values?: Record<string, unknown>) =>
|
|
52
|
+
export type Translator<TSource extends MessageSource | undefined = undefined> = <const TValue extends string>(english: AllowedMessageKey<TSource, TValue>, values?: Record<string, unknown>) => LocalizedString;
|
|
37
53
|
/**
|
|
38
54
|
* Brand a tree of English source strings as translation keys so the compiler
|
|
39
55
|
* can check them. Returns the value unchanged at runtime.
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAC5C,OAAO,CAAC,MAAM,sBAAsB,EAAE,OAAO,MAAM,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IACtC,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,iBAAiB,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEtD,KAAK,OAAO,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,GAAG;IACvD,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC;CACrC,CAAC;AAEF,uEAAuE;AACvE,MAA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AC,EAAE,aAAa,GAC7B,UAAU,CAAC,OAAO,CAAC,CAerB"}
|
package/dist/core.js
CHANGED
|
@@ -61,6 +61,7 @@ export function defineI18nScope(scope) {
|
|
|
61
61
|
*/
|
|
62
62
|
export function createT(locale, messagesOrScope, runtimeMessages) {
|
|
63
63
|
const resolvedMessages = resolveMessages(runtimeMessages) ?? resolveMessages(messagesOrScope);
|
|
64
|
+
// The brand is erased at runtime; this function is the sole mint site.
|
|
64
65
|
const translate = (english, values) => {
|
|
65
66
|
const translated = resolvedMessages?.[locale]?.[english] ?? english;
|
|
66
67
|
if (!values)
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AA2FnD,MAAM,KAAK,GAAG,IAAI,GAAG,EAA6B,CAAC;AACnD,uEAAuE;AACvE,2EAA2E;AAC3E,wBAAwB;AACxB,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE7C,SAAS,MAAM,CACd,OAAe,EACf,MAAc,EACd,MAA+B;IAE/B,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,IAAI,IAAI,SAAS;gBAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3C,GAAG,GAAG,IAAI,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC7C,KAAK,CAAC,GAAG,CAAC,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CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CACtB,MAAc,EACd,eAAyB,EACzB,eAA+B;IAE/B,MAAM,gBAAgB,GACrB,eAAe,CAAC,eAAe,CAAC,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;IAEtE,uEAAuE;IACvE,MAAM,SAAS,GAAG,CACjB,OAAe,EACf,MAAgC,EACd,EAAE;QACpB,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC;QACpE,IAAI,CAAC,MAAM;YAAE,OAAO,UAA6B,CAAC;QAClD,OAAO,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAoB,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAO,SAAgC,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createT, defineI18nScope, defineMessages, type I18nScope, type Messages, type MessageSource, type TranslationKey, type Translator, } from "./core.js";
|
|
1
|
+
export { createT, defineI18nScope, defineMessages, type I18nScope, type LocalizedString, type Messages, type MessageSource, type TranslationKey, type Translator, } from "./core.js";
|
|
2
2
|
export { defineI18nConfig, deriveLocaleConstants, type I18nConfig, localeMap, type LocaleDefinition, type MissingKeysPolicy, } from "./config.js";
|
|
3
3
|
export { negotiateAcceptLanguage } from "./negotiate.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,eAAe,EACf,cAAc,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,UAAU,EACf,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,eAAe,EACf,cAAc,EACd,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,UAAU,EACf,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EACN,OAAO,EACP,eAAe,EACf,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EACN,OAAO,EACP,eAAe,EACf,cAAc,GAOd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EAErB,SAAS,GAGT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Type-safe, English-as-key i18n for Ingram Next.js sites — ICU translator, scopes, locale config, and Accept-Language negotiation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"test": "vitest run"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"intl-messageformat": "^11.2.
|
|
34
|
+
"intl-messageformat": "^11.2.10"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@ingram-tech/nk-dev": "0.
|
|
37
|
+
"@ingram-tech/nk-dev": "0.5.0",
|
|
38
38
|
"@types/react": "^19.2.17",
|
|
39
39
|
"react": "^19.2.7",
|
|
40
|
-
"typescript": "^
|
|
41
|
-
"vitest": "^4.1.
|
|
40
|
+
"typescript": "^7.0.2",
|
|
41
|
+
"vitest": "^4.1.10"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": "^18.0.0 || ^19.0.0"
|