@ciridae/ui 2.78.0 → 2.78.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.
@@ -799,7 +799,7 @@ export declare function createCiridaeLocale(locale: string, { agentNoun, labels,
799
799
  export type CiridaeLocaleProviderProps = {
800
800
  /** What the product calls its agents; required, the kit has no default. */
801
801
  agentNoun: CiridaeAgentNoun;
802
- /** A BCP 47 tag such as `de-DE`; the browser's language when left out. */
802
+ /** A BCP 47 tag such as `de-DE`; the browser's language when left out, `en-US` if Intl rejects it. */
803
803
  locale?: string;
804
804
  /** Labels the product rewords or translates; anything left out stays English. */
805
805
  labels?: CiridaeLabelOverrides;
@@ -852,7 +852,7 @@ let browserLocale = null;
852
852
  * provider. Reading the agent noun there throws: the kit has no default for it.
853
853
  */
854
854
  function defaultLocale() {
855
- browserLocale ?? (browserLocale = createCiridaeLocaleFromLabels(globalThis.navigator?.language || "en-US", "ltr", {
855
+ browserLocale ?? (browserLocale = createCiridaeLocaleFromLabels(readBrowserLanguage(), "ltr", {
856
856
  ...englishLabels,
857
857
  chat: {
858
858
  ...englishLabels.chat,
@@ -866,13 +866,29 @@ function defaultLocale() {
866
866
  }));
867
867
  return browserLocale;
868
868
  }
869
+ /**
870
+ * The browser's language, or `en-US` when there is none or Intl rejects it: a crawler can report a
871
+ * tag such as `en-US@posix`, which every Intl formatter refuses with a RangeError.
872
+ */
873
+ function readBrowserLanguage() {
874
+ const language = globalThis.navigator?.language || "en-US";
875
+ try {
876
+ return Intl.getCanonicalLocales(language)[0] ?? "en-US";
877
+ }
878
+ catch (error) {
879
+ if (!(error instanceof RangeError))
880
+ throw error;
881
+ console.warn(`Formatting in en-US: Intl rejects the browser's language ${language}`, error);
882
+ return "en-US";
883
+ }
884
+ }
869
885
  function agentNounIsRequiredError() {
870
886
  return new Error("The kit has no word for an agent: wrap the app in CiridaeLocaleProvider and pass agentNoun.");
871
887
  }
872
888
  const LocaleContext = createContext(null);
873
889
  export function CiridaeLocaleProvider({ agentNoun, locale, labels, dir = "ltr", children, }) {
874
890
  const { singular: agentNounSingular, plural: agentNounPlural } = agentNoun;
875
- const value = useMemo(() => createCiridaeLocale(locale ?? (globalThis.navigator?.language || "en-US"), {
891
+ const value = useMemo(() => createCiridaeLocale(locale ?? readBrowserLanguage(), {
876
892
  agentNoun: { singular: agentNounSingular, plural: agentNounPlural },
877
893
  labels,
878
894
  dir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciridae/ui",
3
- "version": "2.78.0",
3
+ "version": "2.78.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",