@entifix/i18n 0.1.2 → 0.1.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.
package/README.md CHANGED
@@ -12,6 +12,8 @@ pnpm add @entifix/i18n i18next
12
12
 
13
13
  ## Entry points
14
14
 
15
+ `fill` fills `{{name}}` placeholders of a string already translated, and `CatalogShape<T>` is the type a second locale's catalog `satisfies`.
16
+
15
17
  | Import | What it holds |
16
18
  | ----------------------- | ------------------------------------------------------------------------------------------------ |
17
19
  | `@entifix/i18n` | `defineCatalogs`, `createI18n`, `getServerTFor` |
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The same keys as `T`, every leaf a string.
3
+ *
4
+ * A second locale's catalog is declared `satisfies CatalogShape<typeof en>`,
5
+ * and `satisfies` checks an object literal both ways: a key missing from it
6
+ * and a key only it has are each a type error, so a catalog cannot drift from
7
+ * the one it translates without failing the build.
8
+ */
9
+ export type CatalogShape<T> = {
10
+ readonly [K in keyof T]: T[K] extends string ? string : CatalogShape<T[K]>;
11
+ };
12
+ //# sourceMappingURL=catalog-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-shape.d.ts","sourceRoot":"","sources":["../src/catalog-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAC5B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3E,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The same keys as `T`, every leaf a string.
3
+ *
4
+ * A second locale's catalog is declared `satisfies CatalogShape<typeof en>`,
5
+ * and `satisfies` checks an object literal both ways: a key missing from it
6
+ * and a key only it has are each a type error, so a catalog cannot drift from
7
+ * the one it translates without failing the build.
8
+ */ export { };
9
+
10
+ //# sourceMappingURL=catalog-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/catalog-shape.ts"],"sourcesContent":["/**\n * The same keys as `T`, every leaf a string.\n *\n * A second locale's catalog is declared `satisfies CatalogShape<typeof en>`,\n * and `satisfies` checks an object literal both ways: a key missing from it\n * and a key only it has are each a type error, so a catalog cannot drift from\n * the one it translates without failing the build.\n */\nexport type CatalogShape<T> = {\n readonly [K in keyof T]: T[K] extends string ? string : CatalogShape<T[K]>;\n};\n"],"names":[],"mappings":"AAAA;;;;;;;CAOC,GACD,WAEE"}
package/dist/fill.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A catalog string with its `{{name}}` placeholders filled in, for copy a
3
+ * component receives already translated: `fill('{{n}} active', { n: 2 })`.
4
+ * A placeholder with no value stays as written.
5
+ *
6
+ * Pure, and free of i18next: a client component can fill a string the server
7
+ * translated without installing a catalog.
8
+ */
9
+ export declare function fill(template: string, values: Readonly<Record<string, string | number>>): string;
10
+ //# sourceMappingURL=fill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../src/fill.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,GAChD,MAAM,CAIR"}
package/dist/fill.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A catalog string with its `{{name}}` placeholders filled in, for copy a
3
+ * component receives already translated: `fill('{{n}} active', { n: 2 })`.
4
+ * A placeholder with no value stays as written.
5
+ *
6
+ * Pure, and free of i18next: a client component can fill a string the server
7
+ * translated without installing a catalog.
8
+ */ export function fill(template, values) {
9
+ return template.replace(/\{\{(\w+)\}\}/g, (placeholder, name)=>name in values ? String(values[name]) : placeholder);
10
+ }
11
+
12
+ //# sourceMappingURL=fill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fill.ts"],"sourcesContent":["/**\n * A catalog string with its `{{name}}` placeholders filled in, for copy a\n * component receives already translated: `fill('{{n}} active', { n: 2 })`.\n * A placeholder with no value stays as written.\n *\n * Pure, and free of i18next: a client component can fill a string the server\n * translated without installing a catalog.\n */\nexport function fill(\n template: string,\n values: Readonly<Record<string, string | number>>,\n): string {\n return template.replace(/\\{\\{(\\w+)\\}\\}/g, (placeholder, name: string) =>\n name in values ? String(values[name]) : placeholder,\n );\n}\n"],"names":["fill","template","values","replace","placeholder","name","String"],"mappings":"AAAA;;;;;;;CAOC,GACD,OAAO,SAASA,KACdC,QAAgB,EAChBC,MAAiD;IAEjD,OAAOD,SAASE,OAAO,CAAC,kBAAkB,CAACC,aAAaC,OACtDA,QAAQH,SAASI,OAAOJ,MAAM,CAACG,KAAK,IAAID;AAE5C"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './catalog-shape.js';
2
+ export * from './fill.js';
1
3
  export * from './instance.js';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './catalog-shape.js';
2
+ export * from './fill.js';
1
3
  export * from './instance.js';
2
4
 
3
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './instance.js';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './catalog-shape.js';\nexport * from './fill.js';\nexport * from './instance.js';\n"],"names":[],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,YAAY;AAC1B,cAAc,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/i18n",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "i18next binding: install each package's catalogs once, translate with typed keys, and negotiate a locale.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@swc/helpers": "0.5.23",
61
- "@entifix/core": "0.1.2"
61
+ "@entifix/core": "0.1.3"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "i18next": ">=26 <27"