@eifi1/ui-kit 0.20.0 → 0.20.1
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/i18n/plurals.d.ts +3 -1
- package/dist/i18n/plurals.js +9 -2
- package/dist/i18n/plurals.js.map +1 -1
- package/package.json +1 -1
- package/src/i18n/plurals.ts +13 -3
package/dist/i18n/plurals.d.ts
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
* `_other` is the right stand-in: CLDR's `many` shares its wording with `other` in all
|
|
14
14
|
* three. An ordinal family (`key_ordinal_one`, `…_ordinal_other`) is filled from the
|
|
15
15
|
* language's ORDINAL categories. A category the catalogue already has is left alone, and
|
|
16
|
-
* the input is not changed: a new tree comes back.
|
|
16
|
+
* the input is not changed: a new tree comes back. A locale `Intl` cannot read (`""`,
|
|
17
|
+
* `"x"` — a backend `parse` called without a language) adds nothing rather than throwing,
|
|
18
|
+
* so one odd call cannot fail a whole namespace load (kastlan, 0.20 adoption).
|
|
17
19
|
*
|
|
18
20
|
* i18n.addResourceBundle(lng, "translation", withAllPlurals(catalogue, lng));
|
|
19
21
|
* // i18next-http-backend: { parse: (data, lng) => withAllPlurals(JSON.parse(data), lng) }
|
package/dist/i18n/plurals.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
function withAllPlurals(catalogue, locale) {
|
|
3
|
-
const cardinal =
|
|
4
|
-
const ordinal =
|
|
3
|
+
const cardinal = pluralCategories(locale, "cardinal");
|
|
4
|
+
const ordinal = pluralCategories(locale, "ordinal");
|
|
5
5
|
const fill = (tree) => {
|
|
6
6
|
const out = {};
|
|
7
7
|
for (const [key, value] of Object.entries(tree)) {
|
|
@@ -20,6 +20,13 @@ function withAllPlurals(catalogue, locale) {
|
|
|
20
20
|
};
|
|
21
21
|
return fill(catalogue);
|
|
22
22
|
}
|
|
23
|
+
function pluralCategories(locale, type) {
|
|
24
|
+
try {
|
|
25
|
+
return new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
23
30
|
export {
|
|
24
31
|
withAllPlurals
|
|
25
32
|
};
|
package/dist/i18n/plurals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/i18n/plurals.ts"],"sourcesContent":["/**\n * Every plural category a language has, filled from the key family's `_other` — for an\n * app's i18next catalogue, before i18next sees it.\n *\n * The apps write English's two forms, `key_one` and `key_other`, in every language: that\n * is the key set their parity tests hold each catalogue to, and no translator should have\n * to know which categories CLDR assigns. But CLDR gives French, Italian and Spanish a\n * third, `many` (1 000 000, « 1,5 million »), and i18next asks for `key_many` there and\n * nothing else — so without it the count fell down the fallback chain and printed German\n * in a French sentence. Kurvenschmiede found it and filled the gap in memory; kastlan\n * wrote the same function again (0.19 adoption). This is that function, once.\n *\n * `_other` is the right stand-in: CLDR's `many` shares its wording with `other` in all\n * three. An ordinal family (`key_ordinal_one`, `…_ordinal_other`) is filled from the\n * language's ORDINAL categories. A category the catalogue already has is left alone, and\n * the input is not changed: a new tree comes back.\n *\n * i18n.addResourceBundle(lng, \"translation\", withAllPlurals(catalogue, lng));\n * // i18next-http-backend: { parse: (data, lng) => withAllPlurals(JSON.parse(data), lng) }\n */\nexport function withAllPlurals<T extends Record<string, unknown>>(catalogue: T, locale: string): T & Record<string, unknown> {\n const cardinal =
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/plurals.ts"],"sourcesContent":["/**\n * Every plural category a language has, filled from the key family's `_other` — for an\n * app's i18next catalogue, before i18next sees it.\n *\n * The apps write English's two forms, `key_one` and `key_other`, in every language: that\n * is the key set their parity tests hold each catalogue to, and no translator should have\n * to know which categories CLDR assigns. But CLDR gives French, Italian and Spanish a\n * third, `many` (1 000 000, « 1,5 million »), and i18next asks for `key_many` there and\n * nothing else — so without it the count fell down the fallback chain and printed German\n * in a French sentence. Kurvenschmiede found it and filled the gap in memory; kastlan\n * wrote the same function again (0.19 adoption). This is that function, once.\n *\n * `_other` is the right stand-in: CLDR's `many` shares its wording with `other` in all\n * three. An ordinal family (`key_ordinal_one`, `…_ordinal_other`) is filled from the\n * language's ORDINAL categories. A category the catalogue already has is left alone, and\n * the input is not changed: a new tree comes back. A locale `Intl` cannot read (`\"\"`,\n * `\"x\"` — a backend `parse` called without a language) adds nothing rather than throwing,\n * so one odd call cannot fail a whole namespace load (kastlan, 0.20 adoption).\n *\n * i18n.addResourceBundle(lng, \"translation\", withAllPlurals(catalogue, lng));\n * // i18next-http-backend: { parse: (data, lng) => withAllPlurals(JSON.parse(data), lng) }\n */\nexport function withAllPlurals<T extends Record<string, unknown>>(catalogue: T, locale: string): T & Record<string, unknown> {\n const cardinal = pluralCategories(locale, \"cardinal\");\n const ordinal = pluralCategories(locale, \"ordinal\");\n const fill = (tree: Record<string, unknown>): Record<string, unknown> => {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(tree)) {\n out[key] =\n value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? fill(value as Record<string, unknown>)\n : value;\n }\n for (const [key, value] of Object.entries(tree)) {\n if (!key.endsWith(\"_other\") || typeof value !== \"string\") continue;\n const base = key.slice(0, -\"_other\".length);\n const categories = base.endsWith(\"_ordinal\") ? ordinal : cardinal;\n for (const category of categories) {\n const name = `${base}_${category}`;\n if (!(name in out)) out[name] = value;\n }\n }\n return out;\n };\n return fill(catalogue) as T & Record<string, unknown>;\n}\n\nfunction pluralCategories(locale: string, type: Intl.PluralRuleType): readonly string[] {\n try {\n return new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;\n } catch {\n return [];\n }\n}\n"],"mappings":";AAsBO,SAAS,eAAkD,WAAc,QAA6C;AAC3H,QAAM,WAAW,iBAAiB,QAAQ,UAAU;AACpD,QAAM,UAAU,iBAAiB,QAAQ,SAAS;AAClD,QAAM,OAAO,CAAC,SAA2D;AACvE,UAAM,MAA+B,CAAC;AACtC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC/C,UAAI,GAAG,IACL,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC/D,KAAK,KAAgC,IACrC;AAAA,IACR;AACA,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC/C,UAAI,CAAC,IAAI,SAAS,QAAQ,KAAK,OAAO,UAAU,SAAU;AAC1D,YAAM,OAAO,IAAI,MAAM,GAAG,CAAC,SAAS,MAAM;AAC1C,YAAM,aAAa,KAAK,SAAS,UAAU,IAAI,UAAU;AACzD,iBAAW,YAAY,YAAY;AACjC,cAAM,OAAO,GAAG,IAAI,IAAI,QAAQ;AAChC,YAAI,EAAE,QAAQ,KAAM,KAAI,IAAI,IAAI;AAAA,MAClC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO,KAAK,SAAS;AACvB;AAEA,SAAS,iBAAiB,QAAgB,MAA8C;AACtF,MAAI;AACF,WAAO,IAAI,KAAK,YAAY,QAAQ,EAAE,KAAK,CAAC,EAAE,gBAAgB,EAAE;AAAA,EAClE,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eifi1/ui-kit",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "App-agnostic shared design system: domain-free React components, theme and tokens.",
|
|
6
6
|
"_sideEffects": "The barrel (src/index.ts) re-exports EVERY component, including components/chart, which statically imports recharts. Without this field a bundler must assume each of those modules has side effects, so it cannot drop the unused ones: importing a Button from '@eifi1/ui-kit' dragged all 433KB of recharts into the consumer's ENTRY chunk, and Keksdose was preloading it on every page load, login included. Nothing in src/ imports for side effects (no bare imports, no CSS imports from JS, no module-level global writes) — the token stylesheet is its own './tokens.css' export — so this is safe. CSS is still listed so any future stylesheet survives. Re-checked when `flag-icons` left `dependencies` and tsup started emitting a `\"use client\"` banner: neither touches this. The flag stylesheet was never imported from JS in the first place (that was the finding), and a directive prologue is a string literal every bundler lifts out before it decides whether a module is inert.",
|
package/src/i18n/plurals.ts
CHANGED
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
* `_other` is the right stand-in: CLDR's `many` shares its wording with `other` in all
|
|
14
14
|
* three. An ordinal family (`key_ordinal_one`, `…_ordinal_other`) is filled from the
|
|
15
15
|
* language's ORDINAL categories. A category the catalogue already has is left alone, and
|
|
16
|
-
* the input is not changed: a new tree comes back.
|
|
16
|
+
* the input is not changed: a new tree comes back. A locale `Intl` cannot read (`""`,
|
|
17
|
+
* `"x"` — a backend `parse` called without a language) adds nothing rather than throwing,
|
|
18
|
+
* so one odd call cannot fail a whole namespace load (kastlan, 0.20 adoption).
|
|
17
19
|
*
|
|
18
20
|
* i18n.addResourceBundle(lng, "translation", withAllPlurals(catalogue, lng));
|
|
19
21
|
* // i18next-http-backend: { parse: (data, lng) => withAllPlurals(JSON.parse(data), lng) }
|
|
20
22
|
*/
|
|
21
23
|
export function withAllPlurals<T extends Record<string, unknown>>(catalogue: T, locale: string): T & Record<string, unknown> {
|
|
22
|
-
const cardinal =
|
|
23
|
-
const ordinal =
|
|
24
|
+
const cardinal = pluralCategories(locale, "cardinal");
|
|
25
|
+
const ordinal = pluralCategories(locale, "ordinal");
|
|
24
26
|
const fill = (tree: Record<string, unknown>): Record<string, unknown> => {
|
|
25
27
|
const out: Record<string, unknown> = {};
|
|
26
28
|
for (const [key, value] of Object.entries(tree)) {
|
|
@@ -42,3 +44,11 @@ export function withAllPlurals<T extends Record<string, unknown>>(catalogue: T,
|
|
|
42
44
|
};
|
|
43
45
|
return fill(catalogue) as T & Record<string, unknown>;
|
|
44
46
|
}
|
|
47
|
+
|
|
48
|
+
function pluralCategories(locale: string, type: Intl.PluralRuleType): readonly string[] {
|
|
49
|
+
try {
|
|
50
|
+
return new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;
|
|
51
|
+
} catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|