@seij/common-ui 0.1.5 → 0.1.6

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.
@@ -3,6 +3,6 @@ import { I18n } from './i18n.types';
3
3
  export interface I18nProviderProps {
4
4
  children: React.ReactNode;
5
5
  }
6
- export declare function I18nProvider({ children }: I18nProviderProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function I18nProvider({ children }: I18nProviderProps): import("react/jsx-runtime").JSX.Element | null;
7
7
  export declare function useI18n(): I18n;
8
8
  //# sourceMappingURL=i18n.react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.react.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/i18n.react.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAQpC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAa3D;AAED,wBAAgB,OAAO,IAAI,IAAI,CAI9B"}
1
+ {"version":3,"file":"i18n.react.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/i18n.react.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkE,MAAM,OAAO,CAAC;AAEvF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAQpC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,kDAsB3D;AAED,wBAAgB,OAAO,IAAI,IAAI,CAI9B"}
@@ -1,19 +1,23 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import { createContext as i, useContext as c, useState as u, useMemo as a } from "react";
3
- import { I18nServiceInstance as t } from "./i18n.service.js";
4
- const r = i({ i18nService: t, lastChange: 0 });
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import { createContext as a, useContext as f, useState as r, useMemo as m, useEffect as v } from "react";
3
+ import { I18nServiceInstance as n } from "./i18n.service.js";
4
+ const s = a({ i18nService: n, lastChange: 0 });
5
5
  function x({ children: e }) {
6
- const [n, v] = u(0), o = a(
6
+ const [t, I] = r(0), [o, i] = r(!1), c = m(
7
7
  () => ({
8
- i18nService: t,
9
- lastChange: n
8
+ i18nService: n,
9
+ lastChange: t
10
10
  }),
11
- [n]
11
+ [t]
12
12
  );
13
- return /* @__PURE__ */ s(r.Provider, { value: o, children: e });
13
+ return v(() => {
14
+ n.readyPromise.then(() => {
15
+ i(!0);
16
+ });
17
+ }, []), o ? /* @__PURE__ */ u(s.Provider, { value: c, children: e }) : null;
14
18
  }
15
19
  function C() {
16
- const e = c(r);
20
+ const e = f(s);
17
21
  if (!e) throw new Error("useI18n must be used within I18nProvider");
18
22
  return e.i18nService;
19
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.react.js","sources":["../../../src/lib/i18n/i18n.react.tsx"],"sourcesContent":["// i18n/I18nProvider.tsx\nimport React, { createContext, useContext, useMemo, useState } from \"react\";\nimport { I18nService, I18nServiceInstance } from \"./i18n.service\";\nimport { I18n } from \"./i18n.types\";\n\ntype I18nCtxType = {\n i18nService: I18nService;\n lastChange: number;\n};\nconst I18nCtx = createContext<I18nCtxType>({ i18nService: I18nServiceInstance, lastChange: 0 });\n\nexport interface I18nProviderProps {\n children: React.ReactNode;\n}\n\nexport function I18nProvider({ children }: I18nProviderProps) {\n // Detects the locale: first used the forced one, then initial, then use autodetection\n\n const [instanceTs, setInstanceTs] = useState(0);\n const value: I18nCtxType = useMemo(\n () => ({\n i18nService: I18nServiceInstance,\n lastChange: instanceTs,\n }),\n [instanceTs],\n );\n\n return <I18nCtx.Provider value={value}>{children}</I18nCtx.Provider>;\n}\n\nexport function useI18n(): I18n {\n const v = useContext(I18nCtx);\n if (!v) throw new Error(\"useI18n must be used within I18nProvider\");\n return v.i18nService;\n}\n"],"names":["I18nCtx","createContext","I18nServiceInstance","I18nProvider","children","instanceTs","setInstanceTs","useState","value","useMemo","jsx","useI18n","v","useContext"],"mappings":";;;AASA,MAAMA,IAAUC,EAA2B,EAAE,aAAaC,GAAqB,YAAY,GAAG;AAMvF,SAASC,EAAa,EAAE,UAAAC,KAA+B;AAG5D,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAS,CAAC,GACxCC,IAAqBC;AAAA,IACzB,OAAO;AAAA,MACL,aAAaP;AAAA,MACb,YAAYG;AAAA,IAAA;AAAA,IAEd,CAACA,CAAU;AAAA,EAAA;AAGb,SAAO,gBAAAK,EAACV,EAAQ,UAAR,EAAiB,OAAAQ,GAAe,UAAAJ,EAAA,CAAS;AACnD;AAEO,SAASO,IAAgB;AAC9B,QAAMC,IAAIC,EAAWb,CAAO;AAC5B,MAAI,CAACY,EAAG,OAAM,IAAI,MAAM,0CAA0C;AAClE,SAAOA,EAAE;AACX;"}
1
+ {"version":3,"file":"i18n.react.js","sources":["../../../src/lib/i18n/i18n.react.tsx"],"sourcesContent":["// i18n/I18nProvider.tsx\nimport React, { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport { i18NextInstance, I18nService, I18nServiceInstance } from \"./i18n.service\";\nimport { I18n } from \"./i18n.types\";\n\ntype I18nCtxType = {\n i18nService: I18nService;\n lastChange: number;\n};\nconst I18nCtx = createContext<I18nCtxType>({ i18nService: I18nServiceInstance, lastChange: 0 });\n\nexport interface I18nProviderProps {\n children: React.ReactNode;\n}\n\nexport function I18nProvider({ children }: I18nProviderProps) {\n // Detects the locale: first used the forced one, then initial, then use autodetection\n\n const [instanceTs, setInstanceTs] = useState(0);\n const [ready, setReady] = useState<boolean>(false)\n const value: I18nCtxType = useMemo(\n () => ({\n i18nService: I18nServiceInstance,\n lastChange: instanceTs,\n }),\n [instanceTs],\n );\n\n useEffect(() => {\n I18nServiceInstance.readyPromise.then(()=>{\n setReady(true)\n })\n }, [])\n\n if (!ready) return null\n\n return <I18nCtx.Provider value={value}>{children}</I18nCtx.Provider>;\n}\n\nexport function useI18n(): I18n {\n const v = useContext(I18nCtx);\n if (!v) throw new Error(\"useI18n must be used within I18nProvider\");\n return v.i18nService;\n}\n"],"names":["I18nCtx","createContext","I18nServiceInstance","I18nProvider","children","instanceTs","setInstanceTs","useState","ready","setReady","value","useMemo","useEffect","jsx","useI18n","v","useContext"],"mappings":";;;AASA,MAAMA,IAAUC,EAA2B,EAAE,aAAaC,GAAqB,YAAY,GAAG;AAMvF,SAASC,EAAa,EAAE,UAAAC,KAA+B;AAG5D,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAS,CAAC,GACxC,CAACC,GAAOC,CAAQ,IAAIF,EAAkB,EAAK,GAC3CG,IAAqBC;AAAA,IACzB,OAAO;AAAA,MACL,aAAaT;AAAA,MACb,YAAYG;AAAA,IAAA;AAAA,IAEd,CAACA,CAAU;AAAA,EAAA;AASb,SANAO,EAAU,MAAM;AACd,IAAAV,EAAoB,aAAa,KAAK,MAAI;AACxC,MAAAO,EAAS,EAAI;AAAA,IACf,CAAC;AAAA,EACH,GAAG,CAAA,CAAE,GAEAD,IAEE,gBAAAK,EAACb,EAAQ,UAAR,EAAiB,OAAAU,GAAe,UAAAN,EAAA,CAAS,IAF9B;AAGrB;AAEO,SAASU,IAAgB;AAC9B,QAAMC,IAAIC,EAAWhB,CAAO;AAC5B,MAAI,CAACe,EAAG,OAAM,IAAI,MAAM,0CAA0C;AAClE,SAAOA,EAAE;AACX;"}
@@ -2,7 +2,7 @@ import { i18n } from 'i18next';
2
2
  import { I18n } from './i18n.types';
3
3
  export declare const i18NextInstance: i18n;
4
4
  export declare class I18nService implements I18n {
5
- readyPromise: import('i18next').TFunction<"translation", undefined>;
5
+ readyPromise: Promise<import('i18next').TFunction<"translation", undefined>>;
6
6
  getLocale: () => string;
7
7
  rich: (id: string, values?: Record<string, unknown | ((chunks: string) => React.ReactNode)>) => React.ReactNode;
8
8
  t: (id: string, values?: Record<string, unknown>) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.service.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/i18n.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAKpC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,eAAO,MAAM,eAAe,EAAE,IAA+B,CAAC;AAiB9D,qBAAa,WAAY,YAAW,IAAI;IACtC,YAAY,wDAA8B;IAE1C,SAAS,QAAO,MAAM,CAEpB;IAEF,IAAI,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC,KAAG,KAAK,CAAC,SAAS,CAE5G;IAEF,CAAC,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,CAExD;IAEF,OAAO,uCAEL;IAEF,QAAQ,eAEN;IAEF,GAAG,GAAI,QAAQ,MAAM,yBAEnB;IAEF,EAAE,GAAI,QAAQ,MAAM,uBAElB;IAEF,EAAE,GAAI,QAAQ,MAAM,qBAKlB;IAEF,GAAG,gCAED;IAEF,UAAU,GAAI,GAAG,IAAI,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,CAErD;IAEF,YAAY,GAAI,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,CAEhD;IAEF,UAAU,GAAI,OAAO,MAAM,EAAE,EAAE,QAAQ,MAAM,KAAG,MAAM,CAEpD;IAEF,cAAc,GAAI,GAAG,IAAI,GAAG,MAAM,KAAG,MAAM,CA4BzC;IAEF,oBAAoB,QAAO,MAAM,CAE/B;IAEF,kBAAkB,QAAO,MAAM,CAE7B;IAEF,uBAAuB,GAAI,KAAK,MAAM,KAAG,MAAM,CAU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;IAEF,cAAc,GAAI,GAAG,IAAI,GAAG,MAAM,KAAG,MAAM,CA4BzC;IAEF,oBAAoB,QAAO,MAAM,CAE/B;IAEF,kBAAkB,QAAO,MAAM,CAE7B;IAEF,uBAAuB,GAAI,KAAK,MAAM,KAAG,MAAM,CAU7C;IAEF,4BAA4B,GAAI,KAAK,MAAM,KAAG,MAAM,CAclD;IAEF,SAAS;cAWqC,MAAM;eAAS,MAAM;QATjE;IAEF,iBAAiB,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,IAAI,CAIrE;CACH;AAQD,eAAO,MAAM,mBAAmB,aAAoB,CAAC"}
@@ -5,7 +5,7 @@ import { isString as p } from "lodash-es";
5
5
  import l from "../../locales/en.js";
6
6
  import m from "../../locales/fr.js";
7
7
  import I from "i18next-browser-languagedetector";
8
- const n = h.createInstance(), D = await n.use(d).use(I).init({
8
+ const n = h.createInstance(), D = n.use(d).use(I).init({
9
9
  debug: !0,
10
10
  fallbackLng: "en",
11
11
  resources: { fr: { translation: m.messages }, en: { translation: l.messages } },
@@ -17,7 +17,7 @@ const n = h.createInstance(), D = await n.use(d).use(I).init({
17
17
  caches: ["localStorage"]
18
18
  }
19
19
  });
20
- class w {
20
+ class M {
21
21
  readyPromise = D;
22
22
  getLocale = () => n.language;
23
23
  rich = (t, e) => n.t(t, e);
@@ -59,19 +59,19 @@ class w {
59
59
  a = "";
60
60
  return a;
61
61
  };
62
- monthList = () => M(this.language());
62
+ monthList = () => b(this.language());
63
63
  registerNamespace = (t, e) => {
64
64
  for (const a of Object.keys(e))
65
65
  n.addResources(a, t, e[a]);
66
66
  };
67
67
  }
68
- function M(o) {
68
+ function b(o) {
69
69
  const t = new Intl.DateTimeFormat(o, { month: "long" });
70
70
  return Array.from({ length: 12 }, (a, r) => t.format(new Date(2e3, r, 1))).map((a, r) => ({ code: r + 1, label: a }));
71
71
  }
72
- const N = new w();
72
+ const N = new M();
73
73
  export {
74
- w as I18nService,
74
+ M as I18nService,
75
75
  N as I18nServiceInstance,
76
76
  n as i18NextInstance
77
77
  };
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.service.js","sources":["../../../src/lib/i18n/i18n.service.ts"],"sourcesContent":["import { format, formatISO, isDate, isValid, parse } from \"date-fns\";\nimport i18next from \"i18next\";\nimport type { i18n } from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport { isString } from \"lodash-es\";\nimport en from \"../../locales/en\";\nimport fr from \"../../locales/fr\";\nimport { I18n } from \"./i18n.types\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\n\nexport const i18NextInstance: i18n = i18next.createInstance();\nconst i18NextinstanceInitPromise = await i18NextInstance\n .use(ICU)\n .use(LanguageDetector)\n .init({\n debug: true,\n fallbackLng: \"en\",\n resources: { fr: { translation: fr.messages }, en: { translation: en.messages } },\n interpolation: { escapeValue: false },\n detection: {\n order: [\"querystring\", \"localStorage\", \"navigator\"],\n lookupQuerystring: \"lng\",\n lookupLocalStorage: \"lng\",\n caches: [\"localStorage\"],\n },\n });\n\nexport class I18nService implements I18n {\n readyPromise = i18NextinstanceInitPromise;\n\n getLocale = (): string => {\n return i18NextInstance.language;\n };\n\n rich = (id: string, values?: Record<string, unknown | ((chunks: string) => React.ReactNode)>): React.ReactNode => {\n return i18NextInstance.t(id, values);\n };\n\n t = (id: string, values?: Record<string, unknown>): string => {\n return i18NextInstance.t(id, values);\n };\n\n formats = () => {\n return i18NextInstance.language === \"fr\" ? fr.formats : en.formats;\n };\n\n language = () => {\n return i18NextInstance.language;\n };\n\n dtf = (style?: string) => {\n return new Intl.DateTimeFormat(this.language(), (style && this.formats().date[style]) || undefined);\n };\n\n nf = (style?: string) => {\n return new Intl.NumberFormat(this.language(), (style && this.formats().number[style]) || undefined);\n };\n\n lf = (style?: string) => {\n return new Intl.ListFormat(\n this.language(),\n (style && this.formats().list[style]) || { type: \"conjunction\", style: \"long\" },\n );\n };\n\n rtf = () => {\n return new Intl.RelativeTimeFormat(this.language(), { numeric: \"auto\" });\n };\n\n formatDate = (d: Date | number, style?: string): string => {\n return this.dtf(style).format(d);\n };\n\n formatNumber = (n: number, style?: string): string => {\n return this.nf(style).format(n);\n };\n\n formatList = (items: string[], style?: string): string => {\n return this.lf(style).format(items);\n };\n\n formatRelative = (d: Date | number): string => {\n const diff = (Number(d) - Date.now()) / 1000;\n const abs = Math.abs(diff);\n const unit =\n abs < 60\n ? \"second\"\n : abs < 3600\n ? \"minute\"\n : abs < 86400\n ? \"hour\"\n : abs < 2592000\n ? \"day\"\n : abs < 31536000\n ? \"month\"\n : \"year\";\n const value =\n unit === \"second\"\n ? Math.round(diff)\n : unit === \"minute\"\n ? Math.round(diff / 60)\n : unit === \"hour\"\n ? Math.round(diff / 3600)\n : unit === \"day\"\n ? Math.round(diff / 86400)\n : unit === \"month\"\n ? Math.round(diff / 2592000)\n : Math.round(diff / 31536000);\n return this.rtf().format(value, unit as Intl.RelativeTimeFormatUnit);\n };\n\n localDatePlaceholder = (): string => {\n return this.formats().localdate.placeholder;\n };\n\n localDateInputMask = (): string => {\n return this.formats().localdate.inputmask;\n };\n\n localDateFormattedToISO = (str: string): string => {\n const inputMask = this.formats().localdate.inputmask;\n const parsed = parse(\n str,\n inputMask,\n new Date(),\n // { locale: fr }\n );\n if (!isDate(parsed) || !isValid(parsed)) return \"\";\n return formatISO(parsed, { representation: \"date\" });\n };\n\n localDateISOToFormattedInput = (str: string): string => {\n const inputMask = this.formats().localdate.inputmask;\n let result;\n if (isString(str)) {\n const date = new Date(str);\n if (isDate(date) && isValid(date)) {\n result = format(date, inputMask);\n } else {\n result = \"\";\n }\n } else {\n result = \"\";\n }\n return result;\n };\n\n monthList = () => {\n return getMonthNames(this.language());\n };\n\n registerNamespace = (key: string, resources: Record<string, any>): void => {\n for (const lang of Object.keys(resources)) {\n i18NextInstance.addResources(lang, key, resources[lang]);\n }\n };\n}\n\nfunction getMonthNames(locale: string): { code: number; label: string }[] {\n const formatter = new Intl.DateTimeFormat(locale, { month: \"long\" });\n const months = Array.from({ length: 12 }, (_, i) => formatter.format(new Date(2000, i, 1)));\n return months.map((i, index) => ({ code: index + 1, label: i }));\n}\n\nexport const I18nServiceInstance = new I18nService();\n"],"names":["i18NextInstance","i18next","i18NextinstanceInitPromise","ICU","LanguageDetector","fr","en","I18nService","id","values","style","d","n","items","diff","abs","unit","value","str","inputMask","parsed","parse","isDate","isValid","formatISO","result","isString","date","format","getMonthNames","key","resources","lang","locale","formatter","_","i","index","I18nServiceInstance"],"mappings":";;;;;;;AAUO,MAAMA,IAAwBC,EAAQ,eAAA,GACvCC,IAA6B,MAAMF,EACtC,IAAIG,CAAG,EACP,IAAIC,CAAgB,EACpB,KAAK;AAAA,EACJ,OAAO;AAAA,EACP,aAAa;AAAA,EACb,WAAW,EAAE,IAAI,EAAE,aAAaC,EAAG,YAAY,IAAI,EAAE,aAAaC,EAAG,WAAS;AAAA,EAC9E,eAAe,EAAE,aAAa,GAAA;AAAA,EAC9B,WAAW;AAAA,IACT,OAAO,CAAC,eAAe,gBAAgB,WAAW;AAAA,IAClD,mBAAmB;AAAA,IACnB,oBAAoB;AAAA,IACpB,QAAQ,CAAC,cAAc;AAAA,EAAA;AAE3B,CAAC;AAEI,MAAMC,EAA4B;AAAA,EACvC,eAAeL;AAAA,EAEf,YAAY,MACHF,EAAgB;AAAA,EAGzB,OAAO,CAACQ,GAAYC,MACXT,EAAgB,EAAEQ,GAAIC,CAAM;AAAA,EAGrC,IAAI,CAACD,GAAYC,MACRT,EAAgB,EAAEQ,GAAIC,CAAM;AAAA,EAGrC,UAAU,MACDT,EAAgB,aAAa,OAAOK,EAAG,UAAUC,EAAG;AAAA,EAG7D,WAAW,MACFN,EAAgB;AAAA,EAGzB,MAAM,CAACU,MACE,IAAI,KAAK,eAAe,KAAK,SAAA,GAAaA,KAAS,KAAK,QAAA,EAAU,KAAKA,CAAK,KAAM,MAAS;AAAA,EAGpG,KAAK,CAACA,MACG,IAAI,KAAK,aAAa,KAAK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EAAOF,CAAM,KAAK,CAACG,EAAQH,CAAM,IAAU,KACzCI,EAAUJ,GAAQ,EAAE,gBAAgB,QAAQ;AAAA,EACrD;AAAA,EAEA,+BAA+B,CAACF,MAAwB;AACtD,UAAMC,IAAY,KAAK,QAAA,EAAU,UAAU;AAC3C,QAAIM;AACJ,QAAIC,EAASR,CAAG,GAAG;AACjB,YAAMS,IAAO,IAAI,KAAKT,CAAG;AACzB,MAAII,EAAOK,CAAI,KAAKJ,EAAQI,CAAI,IAC9BF,IAASG,EAAOD,GAAMR,CAAS,IAE/BM,IAAS;AAAA,IAEb;AACE,MAAAA,IAAS;AAEX,WAAOA;AAAA,EACT;AAAA,EAEA,YAAY,MACHI,EAAc,KAAK,UAAU;AAAA,EAGtC,oBAAoB,CAACC,GAAaC,MAAyC;AACzE,eAAWC,KAAQ,OAAO,KAAKD,CAAS;AACtC,MAAA/B,EAAgB,aAAagC,GAAMF,GAAKC,EAAUC,CAAI,CAAC;AAAA,EAE3D;AACF;AAEA,SAASH,EAAcI,GAAmD;AACxE,QAAMC,IAAY,IAAI,KAAK,eAAeD,GAAQ,EAAE,OAAO,QAAQ;AAEnE,SADe,MAAM,KAAK,EAAE,QAAQ,GAAA,GAAM,CAACE,GAAGC,MAAMF,EAAU,OAAO,IAAI,KAAK,KAAME,GAAG,CAAC,CAAC,CAAC,EAC5E,IAAI,CAACA,GAAGC,OAAW,EAAE,MAAMA,IAAQ,GAAG,OAAOD,EAAA,EAAI;AACjE;AAEO,MAAME,IAAsB,IAAI/B,EAAA;"}
1
+ {"version":3,"file":"i18n.service.js","sources":["../../../src/lib/i18n/i18n.service.ts"],"sourcesContent":["import { format, formatISO, isDate, isValid, parse } from \"date-fns\";\nimport i18next from \"i18next\";\nimport type { i18n } from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport { isString } from \"lodash-es\";\nimport en from \"../../locales/en\";\nimport fr from \"../../locales/fr\";\nimport { I18n } from \"./i18n.types\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\n\nexport const i18NextInstance: i18n = i18next.createInstance();\nconst i18NextinstanceInitPromise = i18NextInstance\n .use(ICU)\n .use(LanguageDetector)\n .init({\n debug: true,\n fallbackLng: \"en\",\n resources: { fr: { translation: fr.messages }, en: { translation: en.messages } },\n interpolation: { escapeValue: false },\n detection: {\n order: [\"querystring\", \"localStorage\", \"navigator\"],\n lookupQuerystring: \"lng\",\n lookupLocalStorage: \"lng\",\n caches: [\"localStorage\"],\n },\n });\n\nexport class I18nService implements I18n {\n readyPromise = i18NextinstanceInitPromise;\n\n getLocale = (): string => {\n return i18NextInstance.language;\n };\n\n rich = (id: string, values?: Record<string, unknown | ((chunks: string) => React.ReactNode)>): React.ReactNode => {\n return i18NextInstance.t(id, values);\n };\n\n t = (id: string, values?: Record<string, unknown>): string => {\n return i18NextInstance.t(id, values);\n };\n\n formats = () => {\n return i18NextInstance.language === \"fr\" ? fr.formats : en.formats;\n };\n\n language = () => {\n return i18NextInstance.language;\n };\n\n dtf = (style?: string) => {\n return new Intl.DateTimeFormat(this.language(), (style && this.formats().date[style]) || undefined);\n };\n\n nf = (style?: string) => {\n return new Intl.NumberFormat(this.language(), (style && this.formats().number[style]) || undefined);\n };\n\n lf = (style?: string) => {\n return new Intl.ListFormat(\n this.language(),\n (style && this.formats().list[style]) || { type: \"conjunction\", style: \"long\" },\n );\n };\n\n rtf = () => {\n return new Intl.RelativeTimeFormat(this.language(), { numeric: \"auto\" });\n };\n\n formatDate = (d: Date | number, style?: string): string => {\n return this.dtf(style).format(d);\n };\n\n formatNumber = (n: number, style?: string): string => {\n return this.nf(style).format(n);\n };\n\n formatList = (items: string[], style?: string): string => {\n return this.lf(style).format(items);\n };\n\n formatRelative = (d: Date | number): string => {\n const diff = (Number(d) - Date.now()) / 1000;\n const abs = Math.abs(diff);\n const unit =\n abs < 60\n ? \"second\"\n : abs < 3600\n ? \"minute\"\n : abs < 86400\n ? \"hour\"\n : abs < 2592000\n ? \"day\"\n : abs < 31536000\n ? \"month\"\n : \"year\";\n const value =\n unit === \"second\"\n ? Math.round(diff)\n : unit === \"minute\"\n ? Math.round(diff / 60)\n : unit === \"hour\"\n ? Math.round(diff / 3600)\n : unit === \"day\"\n ? Math.round(diff / 86400)\n : unit === \"month\"\n ? Math.round(diff / 2592000)\n : Math.round(diff / 31536000);\n return this.rtf().format(value, unit as Intl.RelativeTimeFormatUnit);\n };\n\n localDatePlaceholder = (): string => {\n return this.formats().localdate.placeholder;\n };\n\n localDateInputMask = (): string => {\n return this.formats().localdate.inputmask;\n };\n\n localDateFormattedToISO = (str: string): string => {\n const inputMask = this.formats().localdate.inputmask;\n const parsed = parse(\n str,\n inputMask,\n new Date(),\n // { locale: fr }\n );\n if (!isDate(parsed) || !isValid(parsed)) return \"\";\n return formatISO(parsed, { representation: \"date\" });\n };\n\n localDateISOToFormattedInput = (str: string): string => {\n const inputMask = this.formats().localdate.inputmask;\n let result;\n if (isString(str)) {\n const date = new Date(str);\n if (isDate(date) && isValid(date)) {\n result = format(date, inputMask);\n } else {\n result = \"\";\n }\n } else {\n result = \"\";\n }\n return result;\n };\n\n monthList = () => {\n return getMonthNames(this.language());\n };\n\n registerNamespace = (key: string, resources: Record<string, any>): void => {\n for (const lang of Object.keys(resources)) {\n i18NextInstance.addResources(lang, key, resources[lang]);\n }\n };\n}\n\nfunction getMonthNames(locale: string): { code: number; label: string }[] {\n const formatter = new Intl.DateTimeFormat(locale, { month: \"long\" });\n const months = Array.from({ length: 12 }, (_, i) => formatter.format(new Date(2000, i, 1)));\n return months.map((i, index) => ({ code: index + 1, label: i }));\n}\n\nexport const I18nServiceInstance = new I18nService();\n"],"names":["i18NextInstance","i18next","i18NextinstanceInitPromise","ICU","LanguageDetector","fr","en","I18nService","id","values","style","d","n","items","diff","abs","unit","value","str","inputMask","parsed","parse","isDate","isValid","formatISO","result","isString","date","format","getMonthNames","key","resources","lang","locale","formatter","_","i","index","I18nServiceInstance"],"mappings":";;;;;;;AAUO,MAAMA,IAAwBC,EAAQ,e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;AACE,MAAAA,IAAS;AAEX,WAAOA;AAAA,EACT;AAAA,EAEA,YAAY,MACHI,EAAc,KAAK,UAAU;AAAA,EAGtC,oBAAoB,CAACC,GAAaC,MAAyC;AACzE,eAAWC,KAAQ,OAAO,KAAKD,CAAS;AACtC,MAAA/B,EAAgB,aAAagC,GAAMF,GAAKC,EAAUC,CAAI,CAAC;AAAA,EAE3D;AACF;AAEA,SAASH,EAAcI,GAAmD;AACxE,QAAMC,IAAY,IAAI,KAAK,eAAeD,GAAQ,EAAE,OAAO,QAAQ;AAEnE,SADe,MAAM,KAAK,EAAE,QAAQ,GAAA,GAAM,CAACE,GAAGC,MAAMF,EAAU,OAAO,IAAI,KAAK,KAAME,GAAG,CAAC,CAAC,CAAC,EAC5E,IAAI,CAACA,GAAGC,OAAW,EAAE,MAAMA,IAAQ,GAAG,OAAOD,EAAA,EAAI;AACjE;AAEO,MAAME,IAAsB,IAAI/B,EAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seij/common-ui",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -10,12 +10,12 @@
10
10
  "dependencies": {
11
11
  "@fluentui/react-components": "9.72.9",
12
12
  "@fluentui/react-icons": "2.0.316",
13
- "@seij/common-types": "0.1.3",
14
13
  "i18next-browser-languagedetector": "8.2.0",
15
- "date-fns": "4.1.0",
14
+ "@seij/common-types": "0.1.3",
16
15
  "i18next": "25.7.3",
17
16
  "i18next-icu": "2.4.1",
18
17
  "lodash-es": "4.17.22",
18
+ "date-fns": "4.1.0",
19
19
  "rifm": "0.12.1"
20
20
  },
21
21
  "devDependencies": {