@gusnips/react 0.4.4 → 0.4.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,GACT,EAAE,eAAe;;;;;;;;;;;;;;;;EAqBjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAmB/E"}
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,GACT,EAAE,eAAe;;;;;;;;;;;;;;;;EAuBjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAmB/E"}
package/dist/i18n.js CHANGED
@@ -26,11 +26,13 @@ export function i18nInitOptions({ fallbackLng, supportedLngs, storageKey, queryK
26
26
  lookupLocalStorage: storageKey,
27
27
  },
28
28
  react: { useSuspense: false },
29
- // `nonExplicitSupportedLngs` is omitted deliberately, and both donors say so in the same
30
- // words. Enabling it validates the BASE subtag against `supportedLngs`, which rejects a
31
- // region-coded "pt-BR" (its base "pt" is not in the list) and silently falls the whole app
32
- // back to English. Detected sub-locales like "en-US" already resolve to their base through
33
- // i18next's ordinary fallback hierarchy, so the flag buys nothing and breaks pt-BR.
29
+ // `nonExplicitSupportedLngs` is omitted deliberately. It breaks both shapes a catalog comes in.
30
+ // Region-coded: it validates the BASE subtag against `supportedLngs`, "pt" is not in a list
31
+ // that says "pt-BR", and the whole app silently renders English — both donors say so in the
32
+ // same words. Base codes: an "en-US" browser keeps "en-US" as `i18n.language`. Beside
33
+ // `currentOnly` no catalog matches it, so the reader gets the fallback language; beside
34
+ // `languageOnly` the copy is right and every map an app keys by the tag misses — the third
35
+ // migration shipped English copy as `lang="pt-BR"`. Without the flag "en-US" settles on "en".
34
36
  };
35
37
  }
36
38
  /**
package/dist/i18n.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4BH,MAAM,UAAU,eAAe,CAAC,EAC9B,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,GACQ;IAChB,OAAO;QACL,WAAW;QACX,aAAa,EAAE,CAAC,GAAG,aAAa,CAAC;QACjC,IAAI,EAAE,aAAsB;QAC5B,aAAa,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,yBAAyB;QAChE,SAAS,EAAE;YACT,KAAK,EAAE,QAAQ;gBACb,CAAC,C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": "@gusnips/react",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "The headless runtime under a Vite + React SPA: typed fetch client with single-flight refresh, auth store, query defaults, route guards, error boundary, chunk-reload recovery, i18n bootstrap.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/i18n.test.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { createInstance } from "i18next";
1
2
  import { describe, expect, it } from "vitest";
2
- import { applyBrandVars, i18nInitOptions } from "./i18n.ts";
3
+ import { applyBrandVars, i18nInitOptions, type I18nInitOptions } from "./i18n.ts";
3
4
 
4
5
  describe("applyBrandVars", () => {
5
6
  it("fills placeholders anywhere in the tree and leaves the input alone", () => {
@@ -27,17 +28,34 @@ describe("applyBrandVars", () => {
27
28
  });
28
29
  });
29
30
 
31
+ /** For a browser saying `lng`: the app's `i18n.language`, and the catalog that answers. */
32
+ async function settle(
33
+ options: Omit<I18nInitOptions, "storageKey">,
34
+ lng: string,
35
+ ): Promise<[language: string, catalog: string]> {
36
+ const i18n = createInstance();
37
+ const resources = Object.fromEntries(
38
+ options.supportedLngs.map((tag) => [tag, { translation: { tag } }]),
39
+ );
40
+ await i18n.init({ ...i18nInitOptions({ ...options, storageKey: "app.locale" }), resources, lng });
41
+ return [i18n.language, i18n.t("tag")];
42
+ }
43
+
30
44
  describe("i18nInitOptions", () => {
31
- // The comment in both donors names the bug: `nonExplicitSupportedLngs` validates the BASE
32
- // subtag, which rejects "pt-BR" (its base "pt" is not listed) and silently falls the whole
33
- // app back to English. Its absence is load-bearing.
34
- it("does not set nonExplicitSupportedLngs", () => {
35
- const options = i18nInitOptions({
36
- fallbackLng: "en",
37
- supportedLngs: ["en", "pt-BR"],
38
- storageKey: "app.locale",
39
- });
40
- expect(options).not.toHaveProperty("nonExplicitSupportedLngs");
45
+ // `nonExplicitSupportedLngs` breaks both catalog shapes, and this pins both. Region-coded, the
46
+ // app renders English for a pt-BR reader — the bug both donors' comments name. Base codes, an
47
+ // "en-US" browser keeps "en-US" as `i18n.language`, which is what an app keys `<html lang>` and
48
+ // `og:locale` by: the third migration's site missed its lookup and shipped English copy as
49
+ // `lang="pt-BR"`.
50
+ it("settles a browser's regional tag on a language the catalogs have", async () => {
51
+ const baseCodes = { fallbackLng: "pt", supportedLngs: ["pt", "es", "en"] };
52
+ expect(await settle(baseCodes, "en-US")).toEqual(["en", "en"]);
53
+ expect(await settle(baseCodes, "es-419")).toEqual(["es", "es"]);
54
+ expect(await settle(baseCodes, "fr-FR")).toEqual(["pt", "pt"]);
55
+
56
+ const regionCoded = { fallbackLng: "en", supportedLngs: ["en", "pt-BR"] };
57
+ expect(await settle(regionCoded, "pt-BR")).toEqual(["pt-BR", "pt-BR"]);
58
+ expect(await settle(regionCoded, "en-GB")).toEqual(["en", "en"]);
41
59
  });
42
60
 
43
61
  // Only one donor had the query parameter, and it is the only detection source somebody chose
package/src/i18n.ts CHANGED
@@ -58,11 +58,13 @@ export function i18nInitOptions({
58
58
  lookupLocalStorage: storageKey,
59
59
  },
60
60
  react: { useSuspense: false },
61
- // `nonExplicitSupportedLngs` is omitted deliberately, and both donors say so in the same
62
- // words. Enabling it validates the BASE subtag against `supportedLngs`, which rejects a
63
- // region-coded "pt-BR" (its base "pt" is not in the list) and silently falls the whole app
64
- // back to English. Detected sub-locales like "en-US" already resolve to their base through
65
- // i18next's ordinary fallback hierarchy, so the flag buys nothing and breaks pt-BR.
61
+ // `nonExplicitSupportedLngs` is omitted deliberately. It breaks both shapes a catalog comes in.
62
+ // Region-coded: it validates the BASE subtag against `supportedLngs`, "pt" is not in a list
63
+ // that says "pt-BR", and the whole app silently renders English — both donors say so in the
64
+ // same words. Base codes: an "en-US" browser keeps "en-US" as `i18n.language`. Beside
65
+ // `currentOnly` no catalog matches it, so the reader gets the fallback language; beside
66
+ // `languageOnly` the copy is right and every map an app keys by the tag misses — the third
67
+ // migration shipped English copy as `lang="pt-BR"`. Without the flag "en-US" settles on "en".
66
68
  };
67
69
  }
68
70