@arch-cadre/intl 0.0.41 → 0.0.42

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.
@@ -0,0 +1 @@
1
+ "use client";import{formatMessage as e,getNestedMessage as t}from"../shared/utils.mjs";import*as n from"react";import{createContext as r,useContext as i}from"react";const a=Symbol.for(`kryo-intl-context`),o=globalThis[a]||r(null);globalThis[a]||(globalThis[a]=o);function s({children:e,locale:t,messages:r}){return n.createElement(o.Provider,{value:{locale:t,messages:r}},e)}function c(){let e=i(o);if(!e)throw Error(`useLocale must be used within I18nProvider`);return e.locale}function l(){let n=i(o);if(!n)throw Error(`useTranslation must be used within I18nProvider`);let{messages:r,locale:a}=n;return{t:(n,i)=>{let a=t(r,String(n));return typeof a==`string`?e(a,i):String(n)},locale:a}}const u=l;export{s as I18nProvider,c as useLocale,l as useTranslation,u as useTranslations};
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{formatMessage as e,getNestedMessage as t,i18n as n}from"./shared/utils.mjs";import{I18nProvider as r,useLocale as i,useTranslation as a,useTranslations as o}from"./client/index.mjs";import{COOKIE_NAME as s,DEFAULT_LOCALE as c,LOCALES as l}from"./shared/constants.mjs";export{s as COOKIE_NAME,c as DEFAULT_LOCALE,r as I18nProvider,l as LOCALES,e as formatMessage,t as getNestedMessage,n as i18n,i as useLocale,a as useTranslation,o as useTranslations};
@@ -0,0 +1 @@
1
+ import{formatMessage as e,getNestedMessage as t}from"../shared/utils.mjs";import{I18nProvider as n}from"../client/index.mjs";import{COOKIE_NAME as r,DEFAULT_LOCALE as i}from"../shared/constants.mjs";import{discoverLocalePaths as a,getModuleLocalePaths as o}from"./module-loader.mjs";import s from"react";import c from"node:fs/promises";import l from"node:path";import{match as u}from"@formatjs/intl-localematcher";import d from"negotiator";import{cookies as f,headers as p}from"next/headers";function m(e,t){let n={...e};for(let r of Object.keys(t))t[r]instanceof Object&&r in e&&e[r]instanceof Object?n[r]=m(e[r],t[r]):n[r]=t[r];return n}let h=null;function g(e){h=Array.from(new Set([...h||[],...e]))}async function _(e,t){(h===null||h.length===0)&&g(await a());let n={},r=l.join(process.cwd(),`locales`),i=new Set;if(h)for(let e of h)i.add(e);if(t)for(let e of t)i.add(e);i.add(r);for(let t of Array.from(i)){let r=l.join(t,e);try{await c.access(r);let e=await c.readdir(r);for(let t of e)if(t.endsWith(`on`)){let e=l.join(r,t),i=await c.readFile(e,`utf-8`),a=JSON.parse(i);n=m(n,a)}}catch{}}return n}function v(e,t){let n=p();return u(new d({headers:Object.fromEntries(n.entries())}).languages(),e,t)}async function y({children:e}){let t=(await f()).get(r)?.value||i,a=await _(t);return s.createElement(n,{locale:t,messages:a},e)}async function b(){let n=(await f()).get(r)?.value||i,a=await _(n);return{t:(n,r)=>{let i=t(a,String(n));return typeof i==`string`?e(i,r):String(n)},locale:n}}export{y as I18nProvider,v as detectLocale,a as discoverLocalePaths,_ as getMessages,o as getModuleLocalePaths,b as getTranslation,g as registerLocalePaths};
@@ -0,0 +1 @@
1
+ import e from"node:fs/promises";import t from"node:path";import"server-only";async function n(){let n=[],r=process.cwd(),i=await(async n=>{let r=[`pnpm-workspace.yaml`,`packageon`],i=n;for(console.log(`[intl]: Searching for monorepo root starting from: ${n}`);i!==t.parse(i).root;){for(let n of r)try{if(await e.access(t.join(i,n)),n===`pnpm-workspace.yaml`)return i}catch{}i=t.dirname(i)}return null})(r);if(i){let r=t.join(i,`packages`);try{let i=await e.readdir(r,{withFileTypes:!0});for(let a of i)if(a.isDirectory()){let i=t.join(r,a.name,`locales`);try{await e.access(i),n.push(i)}catch{}}}catch{}}let a=t.join(r,`node_modules`,`@arch-cadre`);try{let r=await e.readdir(a,{withFileTypes:!0});for(let i of r){let r=t.join(a,i.name,`locales`);try{await e.access(r),n.push(r)}catch{}}}catch{}let o=t.join(r,`modules`);try{let r=await e.readdir(o,{withFileTypes:!0});for(let i of r)if(i.isDirectory()){let r=t.join(o,i.name,`locales`);try{await e.access(r),n.push(r)}catch{}}}catch{}return Array.from(new Set(n))}async function r(e=[],t=`modules`){return n()}export{n as discoverLocalePaths,r as getModuleLocalePaths};
@@ -0,0 +1 @@
1
+ const e=`NEXT_LOCALE`,t=`en`,n=[`en`,`pl`];export{e as COOKIE_NAME,t as DEFAULT_LOCALE,n as LOCALES};
@@ -0,0 +1 @@
1
+ function e(e,t){if(!e)return;if(t in e)return e[t];let n=t.split(`.`),r=e,i=0;for(;i<n.length;){if(typeof r!=`object`||!r)return;let e=!1;for(let t=n.length;t>i;t--){let a=n.slice(i,t).join(`.`);if(a in r){r=r[a],i=t,e=!0;break}}if(!e)return}return r}function t(e,t){return t?e.replace(/{(\w+)}/g,(e,n)=>t[n]===void 0?e:String(t[n])):e}const n=e=>e;export{t as formatMessage,e as getNestedMessage,n as i18n};
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@arch-cadre/intl",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "type": "module",
5
5
  "description": "Core Intl for Kryo framework",
6
6
  "types": "./dist/index.d.ts",
7
- "module": "./dist/index.js",
8
7
  "exports": {
9
- ".": "./dist/index.js",
10
- "./client": "./dist/client/index.js",
11
- "./server": "./dist/server/index.js",
8
+ ".": "./dist/index.mjs",
9
+ "./client": "./dist/client/index.mjs",
10
+ "./server": "./dist/server/index.mjs",
12
11
  "./package.json": "./package.json"
13
12
  },
14
13
  "files": [
@@ -20,7 +19,7 @@
20
19
  "switch:prod": "node scripts/switchToDist.js",
21
20
  "release": "npm publish --access public --no-git-checks",
22
21
  "dev": "tsdown --watch",
23
- "build": "tsc"
22
+ "build": "tsdown"
24
23
  },
25
24
  "dependencies": {
26
25
  "@formatjs/intl-localematcher": "^0.5.4",
@@ -1,27 +0,0 @@
1
- import * as React from "react";
2
- import type { AbstractIntlMessages, TranslationKeys } from "../types";
3
- export declare function I18nProvider({ children, locale, messages, }: {
4
- children: React.ReactNode;
5
- locale: string;
6
- messages: AbstractIntlMessages;
7
- }): React.CElement<{
8
- value: {
9
- locale: string;
10
- messages: AbstractIntlMessages;
11
- };
12
- }, React.Component<{
13
- value: {
14
- locale: string;
15
- messages: AbstractIntlMessages;
16
- };
17
- }, any, any>>;
18
- export declare function useLocale(): string;
19
- /**
20
- * Client-side hook for translations with IntelliSense support.
21
- */
22
- export declare function useTranslation(): {
23
- t: (key: TranslationKeys, values?: Record<string, any>) => string;
24
- locale: string;
25
- };
26
- export declare const useTranslations: typeof useTranslation;
27
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAgBtE,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,oBAAoB,CAAC;CAChC;;;;;;;;;;cAMA;AAED,wBAAgB,SAAS,WAMxB;AAED;;GAEG;AACH,wBAAgB,cAAc;aAQZ,eAAe,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;EAW9D;AAED,eAAO,MAAM,eAAe,uBAAiB,CAAC"}
@@ -1,39 +0,0 @@
1
- "use client";
2
- import * as React from "react";
3
- import { createContext, useContext } from "react";
4
- import { formatMessage, getNestedMessage } from "../shared/utils";
5
- const CONTEXT_SYMBOL = Symbol.for("kryo-intl-context");
6
- const IntlContext = globalThis[CONTEXT_SYMBOL] ||
7
- createContext(null);
8
- if (!globalThis[CONTEXT_SYMBOL]) {
9
- globalThis[CONTEXT_SYMBOL] = IntlContext;
10
- }
11
- export function I18nProvider({ children, locale, messages, }) {
12
- return React.createElement(IntlContext.Provider, { value: { locale, messages } }, children);
13
- }
14
- export function useLocale() {
15
- const context = useContext(IntlContext);
16
- if (!context) {
17
- throw new Error("useLocale must be used within I18nProvider");
18
- }
19
- return context.locale;
20
- }
21
- /**
22
- * Client-side hook for translations with IntelliSense support.
23
- */
24
- export function useTranslation() {
25
- const context = useContext(IntlContext);
26
- if (!context) {
27
- throw new Error("useTranslation must be used within I18nProvider");
28
- }
29
- const { messages, locale } = context;
30
- const t = (key, values) => {
31
- const message = getNestedMessage(messages, String(key));
32
- if (typeof message !== "string") {
33
- return String(key);
34
- }
35
- return formatMessage(message, values);
36
- };
37
- return { t, locale };
38
- }
39
- export const useTranslations = useTranslation;
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { I18nProvider, useLocale, useTranslation, useTranslations, } from "./client/index";
2
- export * from "./shared/constants";
3
- export * from "./shared/utils";
4
- export * from "./types";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- // Shared Types and Utilities
2
- // Re-export client hooks and components
3
- export { I18nProvider, useLocale, useTranslation, useTranslations, } from "./client/index";
4
- export * from "./shared/constants";
5
- export * from "./shared/utils";
6
- export * from "./types";
@@ -1,21 +0,0 @@
1
- import React from "react";
2
- import type { AbstractIntlMessages, TranslationKeys } from "../types";
3
- /**
4
- * Register additional directories to search for locales.
5
- * Can be called multiple times, but usually called once in RootLayout.
6
- */
7
- export declare function registerLocalePaths(paths: string[]): void;
8
- export declare function getMessages(locale: string, searchDirectories?: string[]): Promise<AbstractIntlMessages>;
9
- export declare function detectLocale(supportedLocales: string[], defaultLocale: string): string;
10
- /**
11
- * Smart Server Component that handles locale detection and message loading automatically.
12
- */
13
- export declare function I18nProvider({ children, }: {
14
- children: React.ReactNode;
15
- }): Promise<React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>>;
16
- export * from "./module-loader";
17
- export declare function getTranslation(): Promise<{
18
- t: (key: TranslationKeys, values?: Record<string, any>) => string;
19
- locale: string;
20
- }>;
21
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EACV,oBAAoB,EAEpB,eAAe,EAChB,MAAM,UAAU,CAAC;AAsBlB;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAElD;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,iBAAiB,CAAC,EAAE,MAAM,EAAE,iCA4C7B;AAED,wBAAgB,YAAY,CAC1B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,aAAa,EAAE,MAAM,UAQtB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,EACjC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,0GAOA;AAED,cAAc,iBAAiB,CAAC;AAEhC,wBAAsB,cAAc;aAQlB,eAAe,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;GAW9D"}
@@ -1,107 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { match } from "@formatjs/intl-localematcher";
4
- import Negotiator from "negotiator";
5
- import { cookies, headers } from "next/headers";
6
- import React from "react";
7
- import { I18nProvider as ClientProvider } from "../client/index";
8
- import { COOKIE_NAME, DEFAULT_LOCALE } from "../shared/constants";
9
- import { formatMessage, getNestedMessage } from "../shared/utils";
10
- import { discoverLocalePaths } from "./module-loader";
11
- function deepMerge(target, source) {
12
- const result = { ...target };
13
- for (const key of Object.keys(source)) {
14
- if (source[key] instanceof Object &&
15
- key in target &&
16
- target[key] instanceof Object) {
17
- result[key] = deepMerge(target[key], source[key]);
18
- }
19
- else {
20
- result[key] = source[key];
21
- }
22
- }
23
- return result;
24
- }
25
- // Internal state for locale paths
26
- let registeredPaths = null;
27
- /**
28
- * Register additional directories to search for locales.
29
- * Can be called multiple times, but usually called once in RootLayout.
30
- */
31
- export function registerLocalePaths(paths) {
32
- registeredPaths = Array.from(new Set([...(registeredPaths || []), ...paths]));
33
- }
34
- export async function getMessages(locale, searchDirectories) {
35
- // Auto-discovery if no paths registered
36
- if (registeredPaths === null || registeredPaths.length === 0) {
37
- const discovered = await discoverLocalePaths();
38
- registerLocalePaths(discovered);
39
- }
40
- let messages = {};
41
- const defaultDir = path.join(process.cwd(), "locales");
42
- // Use provided paths, or registered paths, or just default
43
- const directoriesToScan = new Set();
44
- if (registeredPaths) {
45
- for (const p of registeredPaths)
46
- directoriesToScan.add(p);
47
- }
48
- if (searchDirectories) {
49
- for (const p of searchDirectories)
50
- directoriesToScan.add(p);
51
- }
52
- directoriesToScan.add(defaultDir);
53
- for (const dir of Array.from(directoriesToScan)) {
54
- const localeDir = path.join(dir, locale);
55
- try {
56
- await fs.access(localeDir);
57
- const files = await fs.readdir(localeDir);
58
- for (const file of files) {
59
- if (file.endsWith("on")) {
60
- const filePath = path.join(localeDir, file);
61
- const fileContent = await fs.readFile(filePath, "utf-8");
62
- const jsonContent = JSON.parse(fileContent);
63
- messages = deepMerge(messages, jsonContent);
64
- }
65
- }
66
- }
67
- catch (error) {
68
- // Ignore missing directories
69
- }
70
- }
71
- return messages;
72
- }
73
- export function detectLocale(supportedLocales, defaultLocale) {
74
- const headerList = headers();
75
- const languages = new Negotiator({
76
- headers: Object.fromEntries(headerList.entries()),
77
- }).languages();
78
- return match(languages, supportedLocales, defaultLocale);
79
- }
80
- /**
81
- * Smart Server Component that handles locale detection and message loading automatically.
82
- */
83
- export async function I18nProvider({ children, }) {
84
- var _a;
85
- const cookieStore = await cookies();
86
- const locale = ((_a = cookieStore.get(COOKIE_NAME)) === null || _a === void 0 ? void 0 : _a.value) || DEFAULT_LOCALE;
87
- const messages = await getMessages(locale);
88
- // @ts-expect-error
89
- return React.createElement(ClientProvider, { locale, messages }, children);
90
- }
91
- export * from "./module-loader";
92
- export async function getTranslation() {
93
- var _a;
94
- const cookieStore = await cookies();
95
- const locale = ((_a = cookieStore.get(COOKIE_NAME)) === null || _a === void 0 ? void 0 : _a.value) || DEFAULT_LOCALE;
96
- // If paths haven't been registered yet, we might be in a race condition.
97
- // In a real production app, we might want to have a deterministic way to load these.
98
- const messages = await getMessages(locale);
99
- const t = (key, values) => {
100
- const message = getNestedMessage(messages, String(key));
101
- if (typeof message !== "string") {
102
- return String(key);
103
- }
104
- return formatMessage(message, values);
105
- };
106
- return { t, locale };
107
- }
@@ -1,7 +0,0 @@
1
- import "server-only";
2
- export declare function discoverLocalePaths(): Promise<string[]>;
3
- /**
4
- * Legacy support or manual overrides
5
- */
6
- export declare function getModuleLocalePaths(packageModules?: string[], localModulesDir?: string): Promise<string[]>;
7
- //# sourceMappingURL=module-loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module-loader.d.ts","sourceRoot":"","sources":["../../src/server/module-loader.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAIrB,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CA2E7D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,cAAc,GAAE,MAAM,EAAO,EAC7B,eAAe,GAAE,MAAkB,GAClC,OAAO,CAAC,MAAM,EAAE,CAAC,CAInB"}
@@ -1,84 +0,0 @@
1
- import "server-only";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- export async function discoverLocalePaths() {
5
- const paths = [];
6
- const root = process.cwd();
7
- // Helper to find monorepo root (looking for pnpm-workspace.yaml or turboon)
8
- const findMonorepoRoot = async (current) => {
9
- const indicators = ["pnpm-workspace.yaml", "packageon"];
10
- let dir = current;
11
- console.log(`[intl]: Searching for monorepo root starting from: ${current}`);
12
- while (dir !== path.parse(dir).root) {
13
- for (const indicator of indicators) {
14
- try {
15
- await fs.access(path.join(dir, indicator));
16
- // If we find pnpm-workspace.yaml, this is definitely it
17
- if (indicator === "pnpm-workspace.yaml")
18
- return dir;
19
- }
20
- catch { }
21
- }
22
- dir = path.dirname(dir);
23
- }
24
- return null;
25
- };
26
- const monorepoRoot = await findMonorepoRoot(root);
27
- // 1. Monorepo 'packages' scan
28
- if (monorepoRoot) {
29
- const packagesDir = path.join(monorepoRoot, "packages");
30
- try {
31
- const entries = await fs.readdir(packagesDir, { withFileTypes: true });
32
- for (const entry of entries) {
33
- if (entry.isDirectory()) {
34
- const localePath = path.join(packagesDir, entry.name, "locales");
35
- try {
36
- await fs.access(localePath);
37
- paths.push(localePath);
38
- }
39
- catch { }
40
- }
41
- }
42
- }
43
- catch (e) { }
44
- }
45
- // 2. node_modules/@arch-cadre scan (relative to app root)
46
- const nodeModulesKryo = path.join(root, "node_modules", "@arch-cadre");
47
- try {
48
- const entries = await fs.readdir(nodeModulesKryo, { withFileTypes: true });
49
- for (const entry of entries) {
50
- const localePath = path.join(nodeModulesKryo, entry.name, "locales");
51
- try {
52
- await fs.access(localePath);
53
- paths.push(localePath);
54
- }
55
- catch { }
56
- }
57
- }
58
- catch (e) { }
59
- // 3. Local 'modules' scan (relative to app root)
60
- const localModulesDir = path.join(root, "modules");
61
- try {
62
- const entries = await fs.readdir(localModulesDir, { withFileTypes: true });
63
- for (const entry of entries) {
64
- if (entry.isDirectory()) {
65
- const localePath = path.join(localModulesDir, entry.name, "locales");
66
- try {
67
- await fs.access(localePath);
68
- paths.push(localePath);
69
- }
70
- catch { }
71
- }
72
- }
73
- }
74
- catch (e) { }
75
- return Array.from(new Set(paths));
76
- }
77
- /**
78
- * Legacy support or manual overrides
79
- */
80
- export async function getModuleLocalePaths(packageModules = [], localModulesDir = "modules") {
81
- // ... rest of the existing function if we want to keep it,
82
- // but we'll probably favor discoverLocalePaths
83
- return discoverLocalePaths();
84
- }
@@ -1,4 +0,0 @@
1
- export declare const COOKIE_NAME = "NEXT_LOCALE";
2
- export declare const DEFAULT_LOCALE = "en";
3
- export declare const LOCALES: string[];
4
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,OAAO,UAAe,CAAC"}
@@ -1,3 +0,0 @@
1
- export const COOKIE_NAME = "NEXT_LOCALE";
2
- export const DEFAULT_LOCALE = "en";
3
- export const LOCALES = ["en", "pl"];
@@ -1,9 +0,0 @@
1
- import type { AbstractIntlMessages } from "../types";
2
- export declare function getNestedMessage(messages: AbstractIntlMessages | undefined, path: string): string | AbstractIntlMessages | undefined;
3
- export declare function formatMessage(message: string, values?: Record<string, any>): string;
4
- /**
5
- * Identity function used as a marker for static analysis tools to extract
6
- * translation keys that are defined as plain strings but translated later.
7
- */
8
- export declare const i18n: (key: string) => string;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,GAAG,SAAS,EAC1C,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAiC3C;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,MAAM,CAMR;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,MAAM,KAAG,MAAa,CAAC"}
@@ -1,43 +0,0 @@
1
- export function getNestedMessage(messages, path) {
2
- if (!messages)
3
- return undefined;
4
- // Try direct match first (optimization + exact match with dots)
5
- if (path in messages)
6
- return messages[path];
7
- const parts = path.split(".");
8
- let current = messages;
9
- let i = 0;
10
- while (i < parts.length) {
11
- if (typeof current !== "object" || current === null)
12
- return undefined;
13
- // Try to match longest possible key from current position
14
- let found = false;
15
- for (let j = parts.length; j > i; j--) {
16
- const keyAttempt = parts.slice(i, j).join(".");
17
- if (keyAttempt in current) {
18
- current = current[keyAttempt];
19
- i = j;
20
- found = true;
21
- break;
22
- }
23
- }
24
- if (!found) {
25
- // If we can't match anything, check if we are at the end and looking for a partial key?
26
- // But strictly, we failed to traverse.
27
- return undefined;
28
- }
29
- }
30
- return current;
31
- }
32
- export function formatMessage(message, values) {
33
- if (!values)
34
- return message;
35
- return message.replace(/{(\w+)}/g, (match, key) => {
36
- return values[key] !== undefined ? String(values[key]) : match;
37
- });
38
- }
39
- /**
40
- * Identity function used as a marker for static analysis tools to extract
41
- * translation keys that are defined as plain strings but translated later.
42
- */
43
- export const i18n = (key) => key;
package/dist/types.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import type messages from "../locales/en/global.json";
2
- type JsonDataType = typeof messages;
3
- export interface IntlMessages extends JsonDataType {
4
- }
5
- /**
6
- * Global namespace augmentation for translation messages.
7
- */
8
- declare global {
9
- interface IntlMessages {
10
- }
11
- }
12
- export type AbstractIntlMessages = Record<string, any>;
13
- /**
14
- * Recursive type to get all nested keys joined by dots.
15
- */
16
- export type NestedKeyOf<ObjectType> = {
17
- [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
18
- }[keyof ObjectType & (string | number)];
19
- /**
20
- * Gets translation keys for a specific namespace or all keys if none is provided.
21
- */
22
- export type TranslationKeys<N = undefined> = N extends keyof IntlMessages ? NestedKeyOf<IntlMessages[N]> | (string & {}) : NestedKeyOf<IntlMessages> | (string & {});
23
- export {};
24
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAEtD,KAAK,YAAY,GAAG,OAAO,QAAQ,CAAC;AAEpC,MAAM,WAAW,YAAa,SAAQ,YAAY;CAAI;AAEtD;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,YAAY;KAAI;CAC3B;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,UAAU,IAAI;KACnC,GAAG,IAAI,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,MAAM,GAC3E,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,GACnD,GAAG,GAAG,EAAE;CACX,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,SAAS,IAAI,CAAC,SAAS,MAAM,YAAY,GACrE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAC5C,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};