@domphy/i18n 0.19.0

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/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var g=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var K=(a,n)=>{for(var s in n)g(a,s,{get:n[s],enumerable:!0})},R=(a,n,s,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of m(n))!S.call(a,i)&&i!==s&&g(a,i,{get:()=>n[i],enumerable:!(o=k(n,i))||o.enumerable});return a};var w=a=>R(g({},"__esModule",{value:!0}),a);var h={};K(h,{createI18n:()=>O});module.exports=w(h);var T=require("@domphy/core"),d=require("i18next");function I(a,n){let s=globalThis,o=s[a];return o||(o={instance:(0,d.createInstance)(),localeState:(0,T.toState)(n),initialized:!1},s[a]=o),o}function O(a){let{globalKey:n,namespace:s,locales:o,defaultLocale:i}=a,L=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,{[s]:t}]));function c(){return I(n,i)}async function u(e=i){let t=c();if(t.initialized){await f(e);return}t.initialized=!0,await t.instance.init({lng:e,fallbackLng:i,defaultNS:s,ns:[s],interpolation:{escapeValue:!1},resources:L,initImmediate:!1}),t.localeState.set(e)}async function f(e){let t=c();if(!t.initialized){await u(e);return}t.instance.language!==e&&(await t.instance.changeLanguage(e),t.localeState.set(e))}function p(){let e=c().instance.language;return e in o?e:i}function y(e={}){let{storageKey:t,pathSegment:l=!0}=e;if(l)try{let r=location.pathname.split("/")[1];if(r&&r in o)return r}catch{}if(t)try{let r=localStorage.getItem(t);if(r&&r in o)return r}catch{}return i}function x(e,t,l){let r=c();return typeof e=="function"?(r.localeState.get(e),r.instance.t(t,l)):r.instance.t(e,t)}return{t:x,get locale(){return c().localeState},initI18n:u,setLocale:f,getLocale:p,detectLocale:y}}0&&(module.exports={createI18n});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// @domphy/i18n — generic i18next wrapper with Domphy reactivity.\n//\n// Why globalThis: Vite sometimes bundles a workspace package separately into\n// each consuming chunk. Without the global pin, every chunk creates its own\n// i18next instance — one caller mutates it, another reads blank labels.\n//\n// Usage:\n// // i18n.ts\n// import { createI18n } from '@domphy/i18n'\n// import en from './locales/en.json'\n// import vi from './locales/vi.json'\n// export type Locale = 'en' | 'vi'\n// export const i18n = createI18n<'en' | 'vi', typeof en>({\n// globalKey: '__myapp_i18n__',\n// namespace: 'app',\n// locales: { en, vi },\n// defaultLocale: 'en',\n// })\n\nimport { type Listener, toState } from \"@domphy/core\"\nimport { createInstance, type i18n } from \"i18next\"\n\nexport type { i18n }\n\nexport interface DetectOptions {\n /** localStorage key to read persisted locale from. */\n storageKey?: string\n /** Whether to try reading locale from the first URL path segment (e.g. /vi/...). */\n pathSegment?: boolean\n}\n\nexport interface CreateI18nOptions<TLocale extends string> {\n /** Unique key under globalThis — must differ per app to avoid cross-app collision. */\n globalKey: string\n /** i18next resource namespace. */\n namespace: string\n /** Translation objects keyed by locale code. */\n locales: Record<TLocale, Record<string, unknown>>\n /** Locale used before initI18n / detectLocale is called. */\n defaultLocale: TLocale\n}\n\nexport interface I18nInstance<TKey extends string, TLocale extends string> {\n /** Static call: t(\"key\") — no reactivity. */\n t(key: TKey, options?: Record<string, unknown>): string\n /** Reactive call: t(listener, \"key\") — Domphy re-renders on setLocale(). */\n t(listener: Listener, key: TKey, options?: Record<string, unknown>): string\n /** Reactive locale state — subscribe in Domphy render functions. */\n locale: ReturnType<typeof toState<TLocale>>\n initI18n(locale?: TLocale): Promise<void>\n setLocale(locale: TLocale): Promise<void>\n getLocale(): TLocale\n detectLocale(options?: DetectOptions): TLocale\n}\n\ninterface Store<TLocale extends string> {\n instance: i18n\n localeState: ReturnType<typeof toState<TLocale>>\n initialized: boolean\n}\n\nfunction getOrCreateStore<TLocale extends string>(\n globalKey: string,\n defaultLocale: TLocale,\n): Store<TLocale> {\n const g = globalThis as unknown as Record<string, Store<TLocale> | undefined>\n let store = g[globalKey]\n if (!store) {\n store = {\n instance: createInstance(),\n localeState: toState<TLocale>(defaultLocale),\n initialized: false,\n }\n g[globalKey] = store\n }\n return store\n}\n\nexport function createI18n<TLocale extends string, TMessages extends Record<string, unknown> = Record<string, unknown>>(\n options: CreateI18nOptions<TLocale>,\n): I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale> {\n const { globalKey, namespace, locales, defaultLocale } = options\n\n const resources = Object.fromEntries(\n Object.entries(locales).map(([locale, messages]) => [locale, { [namespace]: messages }]),\n ) as Record<TLocale, Record<string, Record<string, unknown>>>\n\n function getStore() {\n return getOrCreateStore<TLocale>(globalKey, defaultLocale)\n }\n\n async function initI18n(locale: TLocale = defaultLocale): Promise<void> {\n const store = getStore()\n if (store.initialized) {\n await setLocale(locale)\n return\n }\n store.initialized = true\n await store.instance.init({\n lng: locale,\n fallbackLng: defaultLocale,\n defaultNS: namespace,\n ns: [namespace],\n interpolation: { escapeValue: false },\n resources,\n initImmediate: false,\n })\n store.localeState.set(locale)\n }\n\n async function setLocale(locale: TLocale): Promise<void> {\n const store = getStore()\n if (!store.initialized) {\n await initI18n(locale)\n return\n }\n if (store.instance.language === locale) return\n await store.instance.changeLanguage(locale)\n store.localeState.set(locale)\n }\n\n function getLocale(): TLocale {\n const lang = getStore().instance.language\n return (lang in locales ? lang : defaultLocale) as TLocale\n }\n\n function detectLocale(opts: DetectOptions = {}): TLocale {\n const { storageKey, pathSegment = true } = opts\n if (pathSegment) {\n try {\n const seg = location.pathname.split(\"/\")[1]\n if (seg && seg in locales) return seg as TLocale\n } catch { /* SSR */ }\n }\n if (storageKey) {\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored && stored in locales) return stored as TLocale\n } catch { /* SSR / private mode */ }\n }\n return defaultLocale\n }\n\n function t(\n a: Extract<keyof FlattenKeys<TMessages>, string> | Listener,\n b?: Extract<keyof FlattenKeys<TMessages>, string> | Record<string, unknown>,\n c?: Record<string, unknown>,\n ): string {\n const store = getStore()\n if (typeof a === \"function\") {\n store.localeState.get(a as Listener)\n return store.instance.t(b as string, c) as string\n }\n return store.instance.t(a as string, b as Record<string, unknown> | undefined) as string\n }\n\n return {\n t,\n get locale() { return getStore().localeState },\n initI18n,\n setLocale,\n getLocale,\n detectLocale,\n } as I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale>\n}\n\n// Utility: flatten nested object keys to dot-notation string literals.\n// FlattenKeys<{ a: { b: string }, c: string }> = \"a.b\" | \"c\"\ntype FlattenKeys<T, Prefix extends string = \"\"> = {\n [K in Extract<keyof T, string>]: T[K] extends Record<string, unknown>\n ? FlattenKeys<T[K], `${Prefix}${K}.`>\n : `${Prefix}${K}`\n}[Extract<keyof T, string>]\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAmBA,IAAAI,EAAuC,wBACvCC,EAA0C,mBAyC1C,SAASC,EACPC,EACAC,EACgB,CAChB,IAAMC,EAAI,WACNC,EAAQD,EAAEF,CAAS,EACvB,OAAKG,IACHA,EAAQ,CACN,YAAU,kBAAe,EACzB,eAAa,WAAiBF,CAAa,EAC3C,YAAa,EACf,EACAC,EAAEF,CAAS,EAAIG,GAEVA,CACT,CAEO,SAASR,EACdS,EACsE,CACtE,GAAM,CAAE,UAAAJ,EAAW,UAAAK,EAAW,QAAAC,EAAS,cAAAL,CAAc,EAAIG,EAEnDG,EAAY,OAAO,YACvB,OAAO,QAAQD,CAAO,EAAE,IAAI,CAAC,CAACE,EAAQC,CAAQ,IAAM,CAACD,EAAQ,CAAE,CAACH,CAAS,EAAGI,CAAS,CAAC,CAAC,CACzF,EAEA,SAASC,GAAW,CAClB,OAAOX,EAA0BC,EAAWC,CAAa,CAC3D,CAEA,eAAeU,EAASH,EAAkBP,EAA8B,CACtE,IAAME,EAAQO,EAAS,EACvB,GAAIP,EAAM,YAAa,CACrB,MAAMS,EAAUJ,CAAM,EACtB,MACF,CACAL,EAAM,YAAc,GACpB,MAAMA,EAAM,SAAS,KAAK,CACxB,IAAKK,EACL,YAAaP,EACb,UAAWI,EACX,GAAI,CAACA,CAAS,EACd,cAAe,CAAE,YAAa,EAAM,EACpC,UAAAE,EACA,cAAe,EACjB,CAAC,EACDJ,EAAM,YAAY,IAAIK,CAAM,CAC9B,CAEA,eAAeI,EAAUJ,EAAgC,CACvD,IAAML,EAAQO,EAAS,EACvB,GAAI,CAACP,EAAM,YAAa,CACtB,MAAMQ,EAASH,CAAM,EACrB,MACF,CACIL,EAAM,SAAS,WAAaK,IAChC,MAAML,EAAM,SAAS,eAAeK,CAAM,EAC1CL,EAAM,YAAY,IAAIK,CAAM,EAC9B,CAEA,SAASK,GAAqB,CAC5B,IAAMC,EAAOJ,EAAS,EAAE,SAAS,SACjC,OAAQI,KAAQR,EAAUQ,EAAOb,CACnC,CAEA,SAASc,EAAaC,EAAsB,CAAC,EAAY,CACvD,GAAM,CAAE,WAAAC,EAAY,YAAAC,EAAc,EAAK,EAAIF,EAC3C,GAAIE,EACF,GAAI,CACF,IAAMC,EAAM,SAAS,SAAS,MAAM,GAAG,EAAE,CAAC,EAC1C,GAAIA,GAAOA,KAAOb,EAAS,OAAOa,CACpC,MAAQ,CAAY,CAEtB,GAAIF,EACF,GAAI,CACF,IAAMG,EAAS,aAAa,QAAQH,CAAU,EAC9C,GAAIG,GAAUA,KAAUd,EAAS,OAAOc,CAC1C,MAAQ,CAA2B,CAErC,OAAOnB,CACT,CAEA,SAASoB,EACPC,EACAC,EACAC,EACQ,CACR,IAAMrB,EAAQO,EAAS,EACvB,OAAI,OAAOY,GAAM,YACfnB,EAAM,YAAY,IAAImB,CAAa,EAC5BnB,EAAM,SAAS,EAAEoB,EAAaC,CAAC,GAEjCrB,EAAM,SAAS,EAAEmB,EAAaC,CAAwC,CAC/E,CAEA,MAAO,CACL,EAAAF,EACA,IAAI,QAAS,CAAE,OAAOX,EAAS,EAAE,WAAY,EAC7C,SAAAC,EACA,UAAAC,EACA,UAAAC,EACA,aAAAE,CACF,CACF","names":["index_exports","__export","createI18n","__toCommonJS","import_core","import_i18next","getOrCreateStore","globalKey","defaultLocale","g","store","options","namespace","locales","resources","locale","messages","getStore","initI18n","setLocale","getLocale","lang","detectLocale","opts","storageKey","pathSegment","seg","stored","t","a","b","c"]}
@@ -0,0 +1,37 @@
1
+ import { Listener, toState } from '@domphy/core';
2
+ export { i18n } from 'i18next';
3
+
4
+ interface DetectOptions {
5
+ /** localStorage key to read persisted locale from. */
6
+ storageKey?: string;
7
+ /** Whether to try reading locale from the first URL path segment (e.g. /vi/...). */
8
+ pathSegment?: boolean;
9
+ }
10
+ interface CreateI18nOptions<TLocale extends string> {
11
+ /** Unique key under globalThis — must differ per app to avoid cross-app collision. */
12
+ globalKey: string;
13
+ /** i18next resource namespace. */
14
+ namespace: string;
15
+ /** Translation objects keyed by locale code. */
16
+ locales: Record<TLocale, Record<string, unknown>>;
17
+ /** Locale used before initI18n / detectLocale is called. */
18
+ defaultLocale: TLocale;
19
+ }
20
+ interface I18nInstance<TKey extends string, TLocale extends string> {
21
+ /** Static call: t("key") — no reactivity. */
22
+ t(key: TKey, options?: Record<string, unknown>): string;
23
+ /** Reactive call: t(listener, "key") — Domphy re-renders on setLocale(). */
24
+ t(listener: Listener, key: TKey, options?: Record<string, unknown>): string;
25
+ /** Reactive locale state — subscribe in Domphy render functions. */
26
+ locale: ReturnType<typeof toState<TLocale>>;
27
+ initI18n(locale?: TLocale): Promise<void>;
28
+ setLocale(locale: TLocale): Promise<void>;
29
+ getLocale(): TLocale;
30
+ detectLocale(options?: DetectOptions): TLocale;
31
+ }
32
+ declare function createI18n<TLocale extends string, TMessages extends Record<string, unknown> = Record<string, unknown>>(options: CreateI18nOptions<TLocale>): I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale>;
33
+ type FlattenKeys<T, Prefix extends string = ""> = {
34
+ [K in Extract<keyof T, string>]: T[K] extends Record<string, unknown> ? FlattenKeys<T[K], `${Prefix}${K}.`> : `${Prefix}${K}`;
35
+ }[Extract<keyof T, string>];
36
+
37
+ export { type CreateI18nOptions, type DetectOptions, type I18nInstance, createI18n };
@@ -0,0 +1,37 @@
1
+ import { Listener, toState } from '@domphy/core';
2
+ export { i18n } from 'i18next';
3
+
4
+ interface DetectOptions {
5
+ /** localStorage key to read persisted locale from. */
6
+ storageKey?: string;
7
+ /** Whether to try reading locale from the first URL path segment (e.g. /vi/...). */
8
+ pathSegment?: boolean;
9
+ }
10
+ interface CreateI18nOptions<TLocale extends string> {
11
+ /** Unique key under globalThis — must differ per app to avoid cross-app collision. */
12
+ globalKey: string;
13
+ /** i18next resource namespace. */
14
+ namespace: string;
15
+ /** Translation objects keyed by locale code. */
16
+ locales: Record<TLocale, Record<string, unknown>>;
17
+ /** Locale used before initI18n / detectLocale is called. */
18
+ defaultLocale: TLocale;
19
+ }
20
+ interface I18nInstance<TKey extends string, TLocale extends string> {
21
+ /** Static call: t("key") — no reactivity. */
22
+ t(key: TKey, options?: Record<string, unknown>): string;
23
+ /** Reactive call: t(listener, "key") — Domphy re-renders on setLocale(). */
24
+ t(listener: Listener, key: TKey, options?: Record<string, unknown>): string;
25
+ /** Reactive locale state — subscribe in Domphy render functions. */
26
+ locale: ReturnType<typeof toState<TLocale>>;
27
+ initI18n(locale?: TLocale): Promise<void>;
28
+ setLocale(locale: TLocale): Promise<void>;
29
+ getLocale(): TLocale;
30
+ detectLocale(options?: DetectOptions): TLocale;
31
+ }
32
+ declare function createI18n<TLocale extends string, TMessages extends Record<string, unknown> = Record<string, unknown>>(options: CreateI18nOptions<TLocale>): I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale>;
33
+ type FlattenKeys<T, Prefix extends string = ""> = {
34
+ [K in Extract<keyof T, string>]: T[K] extends Record<string, unknown> ? FlattenKeys<T[K], `${Prefix}${K}.`> : `${Prefix}${K}`;
35
+ }[Extract<keyof T, string>];
36
+
37
+ export { type CreateI18nOptions, type DetectOptions, type I18nInstance, createI18n };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{toState as p}from"@domphy/core";import{createInstance as y}from"i18next";function x(r,c){let o=globalThis,a=o[r];return a||(a={instance:y(),localeState:p(c),initialized:!1},o[r]=a),a}function S(r){let{globalKey:c,namespace:o,locales:a,defaultLocale:s}=r,f=Object.fromEntries(Object.entries(a).map(([e,t])=>[e,{[o]:t}]));function i(){return x(c,s)}async function g(e=s){let t=i();if(t.initialized){await u(e);return}t.initialized=!0,await t.instance.init({lng:e,fallbackLng:s,defaultNS:o,ns:[o],interpolation:{escapeValue:!1},resources:f,initImmediate:!1}),t.localeState.set(e)}async function u(e){let t=i();if(!t.initialized){await g(e);return}t.instance.language!==e&&(await t.instance.changeLanguage(e),t.localeState.set(e))}function T(){let e=i().instance.language;return e in a?e:s}function d(e={}){let{storageKey:t,pathSegment:l=!0}=e;if(l)try{let n=location.pathname.split("/")[1];if(n&&n in a)return n}catch{}if(t)try{let n=localStorage.getItem(t);if(n&&n in a)return n}catch{}return s}function L(e,t,l){let n=i();return typeof e=="function"?(n.localeState.get(e),n.instance.t(t,l)):n.instance.t(e,t)}return{t:L,get locale(){return i().localeState},initI18n:g,setLocale:u,getLocale:T,detectLocale:d}}export{S as createI18n};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// @domphy/i18n — generic i18next wrapper with Domphy reactivity.\n//\n// Why globalThis: Vite sometimes bundles a workspace package separately into\n// each consuming chunk. Without the global pin, every chunk creates its own\n// i18next instance — one caller mutates it, another reads blank labels.\n//\n// Usage:\n// // i18n.ts\n// import { createI18n } from '@domphy/i18n'\n// import en from './locales/en.json'\n// import vi from './locales/vi.json'\n// export type Locale = 'en' | 'vi'\n// export const i18n = createI18n<'en' | 'vi', typeof en>({\n// globalKey: '__myapp_i18n__',\n// namespace: 'app',\n// locales: { en, vi },\n// defaultLocale: 'en',\n// })\n\nimport { type Listener, toState } from \"@domphy/core\"\nimport { createInstance, type i18n } from \"i18next\"\n\nexport type { i18n }\n\nexport interface DetectOptions {\n /** localStorage key to read persisted locale from. */\n storageKey?: string\n /** Whether to try reading locale from the first URL path segment (e.g. /vi/...). */\n pathSegment?: boolean\n}\n\nexport interface CreateI18nOptions<TLocale extends string> {\n /** Unique key under globalThis — must differ per app to avoid cross-app collision. */\n globalKey: string\n /** i18next resource namespace. */\n namespace: string\n /** Translation objects keyed by locale code. */\n locales: Record<TLocale, Record<string, unknown>>\n /** Locale used before initI18n / detectLocale is called. */\n defaultLocale: TLocale\n}\n\nexport interface I18nInstance<TKey extends string, TLocale extends string> {\n /** Static call: t(\"key\") — no reactivity. */\n t(key: TKey, options?: Record<string, unknown>): string\n /** Reactive call: t(listener, \"key\") — Domphy re-renders on setLocale(). */\n t(listener: Listener, key: TKey, options?: Record<string, unknown>): string\n /** Reactive locale state — subscribe in Domphy render functions. */\n locale: ReturnType<typeof toState<TLocale>>\n initI18n(locale?: TLocale): Promise<void>\n setLocale(locale: TLocale): Promise<void>\n getLocale(): TLocale\n detectLocale(options?: DetectOptions): TLocale\n}\n\ninterface Store<TLocale extends string> {\n instance: i18n\n localeState: ReturnType<typeof toState<TLocale>>\n initialized: boolean\n}\n\nfunction getOrCreateStore<TLocale extends string>(\n globalKey: string,\n defaultLocale: TLocale,\n): Store<TLocale> {\n const g = globalThis as unknown as Record<string, Store<TLocale> | undefined>\n let store = g[globalKey]\n if (!store) {\n store = {\n instance: createInstance(),\n localeState: toState<TLocale>(defaultLocale),\n initialized: false,\n }\n g[globalKey] = store\n }\n return store\n}\n\nexport function createI18n<TLocale extends string, TMessages extends Record<string, unknown> = Record<string, unknown>>(\n options: CreateI18nOptions<TLocale>,\n): I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale> {\n const { globalKey, namespace, locales, defaultLocale } = options\n\n const resources = Object.fromEntries(\n Object.entries(locales).map(([locale, messages]) => [locale, { [namespace]: messages }]),\n ) as Record<TLocale, Record<string, Record<string, unknown>>>\n\n function getStore() {\n return getOrCreateStore<TLocale>(globalKey, defaultLocale)\n }\n\n async function initI18n(locale: TLocale = defaultLocale): Promise<void> {\n const store = getStore()\n if (store.initialized) {\n await setLocale(locale)\n return\n }\n store.initialized = true\n await store.instance.init({\n lng: locale,\n fallbackLng: defaultLocale,\n defaultNS: namespace,\n ns: [namespace],\n interpolation: { escapeValue: false },\n resources,\n initImmediate: false,\n })\n store.localeState.set(locale)\n }\n\n async function setLocale(locale: TLocale): Promise<void> {\n const store = getStore()\n if (!store.initialized) {\n await initI18n(locale)\n return\n }\n if (store.instance.language === locale) return\n await store.instance.changeLanguage(locale)\n store.localeState.set(locale)\n }\n\n function getLocale(): TLocale {\n const lang = getStore().instance.language\n return (lang in locales ? lang : defaultLocale) as TLocale\n }\n\n function detectLocale(opts: DetectOptions = {}): TLocale {\n const { storageKey, pathSegment = true } = opts\n if (pathSegment) {\n try {\n const seg = location.pathname.split(\"/\")[1]\n if (seg && seg in locales) return seg as TLocale\n } catch { /* SSR */ }\n }\n if (storageKey) {\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored && stored in locales) return stored as TLocale\n } catch { /* SSR / private mode */ }\n }\n return defaultLocale\n }\n\n function t(\n a: Extract<keyof FlattenKeys<TMessages>, string> | Listener,\n b?: Extract<keyof FlattenKeys<TMessages>, string> | Record<string, unknown>,\n c?: Record<string, unknown>,\n ): string {\n const store = getStore()\n if (typeof a === \"function\") {\n store.localeState.get(a as Listener)\n return store.instance.t(b as string, c) as string\n }\n return store.instance.t(a as string, b as Record<string, unknown> | undefined) as string\n }\n\n return {\n t,\n get locale() { return getStore().localeState },\n initI18n,\n setLocale,\n getLocale,\n detectLocale,\n } as I18nInstance<Extract<keyof FlattenKeys<TMessages>, string>, TLocale>\n}\n\n// Utility: flatten nested object keys to dot-notation string literals.\n// FlattenKeys<{ a: { b: string }, c: string }> = \"a.b\" | \"c\"\ntype FlattenKeys<T, Prefix extends string = \"\"> = {\n [K in Extract<keyof T, string>]: T[K] extends Record<string, unknown>\n ? FlattenKeys<T[K], `${Prefix}${K}.`>\n : `${Prefix}${K}`\n}[Extract<keyof T, string>]\n"],"mappings":"AAmBA,OAAwB,WAAAA,MAAe,eACvC,OAAS,kBAAAC,MAAiC,UAyC1C,SAASC,EACPC,EACAC,EACgB,CAChB,IAAMC,EAAI,WACNC,EAAQD,EAAEF,CAAS,EACvB,OAAKG,IACHA,EAAQ,CACN,SAAUL,EAAe,EACzB,YAAaD,EAAiBI,CAAa,EAC3C,YAAa,EACf,EACAC,EAAEF,CAAS,EAAIG,GAEVA,CACT,CAEO,SAASC,EACdC,EACsE,CACtE,GAAM,CAAE,UAAAL,EAAW,UAAAM,EAAW,QAAAC,EAAS,cAAAN,CAAc,EAAII,EAEnDG,EAAY,OAAO,YACvB,OAAO,QAAQD,CAAO,EAAE,IAAI,CAAC,CAACE,EAAQC,CAAQ,IAAM,CAACD,EAAQ,CAAE,CAACH,CAAS,EAAGI,CAAS,CAAC,CAAC,CACzF,EAEA,SAASC,GAAW,CAClB,OAAOZ,EAA0BC,EAAWC,CAAa,CAC3D,CAEA,eAAeW,EAASH,EAAkBR,EAA8B,CACtE,IAAME,EAAQQ,EAAS,EACvB,GAAIR,EAAM,YAAa,CACrB,MAAMU,EAAUJ,CAAM,EACtB,MACF,CACAN,EAAM,YAAc,GACpB,MAAMA,EAAM,SAAS,KAAK,CACxB,IAAKM,EACL,YAAaR,EACb,UAAWK,EACX,GAAI,CAACA,CAAS,EACd,cAAe,CAAE,YAAa,EAAM,EACpC,UAAAE,EACA,cAAe,EACjB,CAAC,EACDL,EAAM,YAAY,IAAIM,CAAM,CAC9B,CAEA,eAAeI,EAAUJ,EAAgC,CACvD,IAAMN,EAAQQ,EAAS,EACvB,GAAI,CAACR,EAAM,YAAa,CACtB,MAAMS,EAASH,CAAM,EACrB,MACF,CACIN,EAAM,SAAS,WAAaM,IAChC,MAAMN,EAAM,SAAS,eAAeM,CAAM,EAC1CN,EAAM,YAAY,IAAIM,CAAM,EAC9B,CAEA,SAASK,GAAqB,CAC5B,IAAMC,EAAOJ,EAAS,EAAE,SAAS,SACjC,OAAQI,KAAQR,EAAUQ,EAAOd,CACnC,CAEA,SAASe,EAAaC,EAAsB,CAAC,EAAY,CACvD,GAAM,CAAE,WAAAC,EAAY,YAAAC,EAAc,EAAK,EAAIF,EAC3C,GAAIE,EACF,GAAI,CACF,IAAMC,EAAM,SAAS,SAAS,MAAM,GAAG,EAAE,CAAC,EAC1C,GAAIA,GAAOA,KAAOb,EAAS,OAAOa,CACpC,MAAQ,CAAY,CAEtB,GAAIF,EACF,GAAI,CACF,IAAMG,EAAS,aAAa,QAAQH,CAAU,EAC9C,GAAIG,GAAUA,KAAUd,EAAS,OAAOc,CAC1C,MAAQ,CAA2B,CAErC,OAAOpB,CACT,CAEA,SAASqB,EACPC,EACAC,EACAC,EACQ,CACR,IAAMtB,EAAQQ,EAAS,EACvB,OAAI,OAAOY,GAAM,YACfpB,EAAM,YAAY,IAAIoB,CAAa,EAC5BpB,EAAM,SAAS,EAAEqB,EAAaC,CAAC,GAEjCtB,EAAM,SAAS,EAAEoB,EAAaC,CAAwC,CAC/E,CAEA,MAAO,CACL,EAAAF,EACA,IAAI,QAAS,CAAE,OAAOX,EAAS,EAAE,WAAY,EAC7C,SAAAC,EACA,UAAAC,EACA,UAAAC,EACA,aAAAE,CACF,CACF","names":["toState","createInstance","getOrCreateStore","globalKey","defaultLocale","g","store","createI18n","options","namespace","locales","resources","locale","messages","getStore","initI18n","setLocale","getLocale","lang","detectLocale","opts","storageKey","pathSegment","seg","stored","t","a","b","c"]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@domphy/i18n",
3
+ "version": "0.19.0",
4
+ "description": "Domphy i18n \u00e2\u20ac\u201d generic i18next wrapper with reactive Domphy integration (globalThis dedup, typed keys, t(listener, key) overload)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "pack": "tsup && npm pack",
25
+ "prepublishOnly": "npm run build",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest"
28
+ },
29
+ "keywords": [
30
+ "domphy",
31
+ "i18n",
32
+ "i18next",
33
+ "reactivity"
34
+ ],
35
+ "author": "Huu Khanh Nguyen",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/domphy/domphy.git",
40
+ "directory": "packages/i18n"
41
+ },
42
+ "dependencies": {
43
+ "i18next": "^25.0.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@domphy/core": "workspace:^"
47
+ },
48
+ "devDependencies": {
49
+ "@domphy/core": "workspace:*",
50
+ "@types/node": "^25.9.2",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^5.9.3",
53
+ "vitest": "^4.0.18"
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "README.md"
58
+ ]
59
+ }