@ooneex/translation 0.0.1 → 0.0.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.
- package/dist/index.d.ts +1 -7
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -5
- package/package.json +14 -6
- package/dist/ooneex-translation-0.0.1.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -8,10 +8,4 @@ type LocaleInfoType = {
|
|
|
8
8
|
code: LocaleType;
|
|
9
9
|
region: string | null;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
lang?: LocaleType;
|
|
13
|
-
params?: Record<string, boolean | number | bigint | string>;
|
|
14
|
-
dict?: Record<string, unknown>;
|
|
15
|
-
count?: number;
|
|
16
|
-
}) => T;
|
|
17
|
-
export { trans, locales, TranslationException, LocaleType, LocaleInfoType };
|
|
11
|
+
export { locales, TranslationException, LocaleType, LocaleInfoType };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var r=["ar","bg","cs","da","de","el","en","eo","es","et","eu","fi","fr","hu","hy","it","ja","ko","lt","nl","no","pl","pt","ro","ru","sk","sv","th","uk","zh","zh-tw"];import{Exception as n}from"@ooneex/exception";import{HttpStatus as s}from"@ooneex/http-status";class o extends n{constructor(t,e={}){super(t,{status:s.Code.NotFound,data:e});this.name="TranslationException"}}export{r as locales,o as TranslationException};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=59F3A1792C61C99864756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["src/locales.ts", "src/TranslationException.ts"
|
|
3
|
+
"sources": ["src/locales.ts", "src/TranslationException.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"export const locales = [\n \"ar\",\n \"bg\",\n \"cs\",\n \"da\",\n \"de\",\n \"el\",\n \"en\",\n \"eo\",\n \"es\",\n \"et\",\n \"eu\",\n \"fi\",\n \"fr\",\n \"hu\",\n \"hy\",\n \"it\",\n \"ja\",\n \"ko\",\n \"lt\",\n \"nl\",\n \"no\",\n \"pl\",\n \"pt\",\n \"ro\",\n \"ru\",\n \"sk\",\n \"sv\",\n \"th\",\n \"uk\",\n \"zh\",\n \"zh-tw\",\n] as const;\n",
|
|
6
|
-
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class TranslationException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.NotFound,\n data,\n });\n this.name = \"TranslationException\";\n }\n}\n"
|
|
7
|
-
"import { TranslationException } from \"./TranslationException\";\nimport type { LocaleType } from \"./types\";\n\nconst getNestedValue = (dict: unknown, path: string): unknown =>\n path\n .split(\".\")\n .reduce(\n (current, key) =>\n current && typeof current === \"object\" && current !== null && key in current\n ? (current as Record<string, unknown>)[key]\n : undefined,\n dict,\n );\n\nexport const trans = <T extends string>(\n key: string | Record<LocaleType, string>,\n options?: {\n lang?: LocaleType;\n params?: Record<string, boolean | number | bigint | string>;\n dict?: Record<string, unknown>;\n count?: number;\n },\n): T => {\n const { lang = \"en\", params, dict, count } = options || {};\n let text = \"\";\n\n if (typeof key === \"string\" && dict) {\n let translationKey = key;\n\n // Handle pluralization\n if (count !== undefined) {\n if (count === 0) {\n // Try zero form first, fallback to plural\n const zeroKey = `${key}_zero`;\n const zeroEntry = getNestedValue(dict, zeroKey) as Record<LocaleType, string>;\n if (zeroEntry) {\n translationKey = zeroKey;\n } else {\n translationKey = `${key}_plural`;\n }\n } else if (count === 1) {\n // Use singular form (original key)\n translationKey = key;\n } else {\n // Use plural form\n translationKey = `${key}_plural`;\n }\n }\n\n const translationEntry = getNestedValue(dict, translationKey) as Record<LocaleType, string>;\n\n if (translationEntry) {\n text = translationEntry[lang as keyof typeof translationEntry] || translationEntry.en || key;\n } else {\n // Fallback to original key if plural form not found\n if (translationKey !== key) {\n const fallbackEntry = getNestedValue(dict, key) as Record<LocaleType, string>;\n if (fallbackEntry) {\n text = fallbackEntry[lang as keyof typeof fallbackEntry] || fallbackEntry.en || key;\n } else {\n throw new TranslationException(`Translation key \"${key}\" not found`);\n }\n } else {\n throw new TranslationException(`Translation key \"${key}\" not found`);\n }\n }\n } else if (typeof key === \"object\") {\n text = key[lang as keyof typeof key] || key.en;\n }\n\n if (!text) {\n throw new TranslationException(\"Translation value is empty\");\n }\n\n // Replace parameters\n if (params) {\n for (const [paramKey, value] of Object.entries(params)) {\n text = (text as string).replace(`{{ ${paramKey} }}`, value.toString());\n }\n }\n\n // Replace count parameter if provided\n if (count !== undefined) {\n text = (text as string).replace(/\\{\\{ count \\}\\}/g, count.toString());\n }\n\n return text as T;\n};\n"
|
|
6
|
+
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class TranslationException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.NotFound,\n data,\n });\n this.name = \"TranslationException\";\n }\n}\n"
|
|
8
7
|
],
|
|
9
|
-
"mappings": "AAAO,IAAM,EAAU,CACrB,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,OACF,EChCA,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA6B,CAAU,CAClD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,SACxB,MACF,CAAC,EACD,KAAK,KAAO,uBAEhB
|
|
10
|
-
"debugId": "
|
|
8
|
+
"mappings": "AAAO,IAAM,EAAU,CACrB,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,OACF,EChCA,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA6B,CAAU,CAClD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,SACxB,MACF,CAAC,EACD,KAAK,KAAO,uBAEhB",
|
|
9
|
+
"debugId": "59F3A1792C61C99864756E2164756E21",
|
|
11
10
|
"names": []
|
|
12
11
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/translation",
|
|
3
|
-
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"description": "Internationalization (i18n) and localization utilities for multi-language support in Ooneex applications",
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -25,13 +25,21 @@
|
|
|
25
25
|
"test": "bun test tests",
|
|
26
26
|
"build": "bunup",
|
|
27
27
|
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
-
"publish
|
|
29
|
-
"
|
|
30
|
-
"publish:dry": "bun publish --dry-run"
|
|
28
|
+
"npm:publish": "bun publish --tolerate-republish --access public",
|
|
29
|
+
"wuchale": "bunx wuchale"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"@ooneex/exception": "0.0.1",
|
|
34
33
|
"@ooneex/http-status": "0.0.1"
|
|
35
34
|
},
|
|
36
|
-
"devDependencies": {}
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"bun",
|
|
38
|
+
"i18n",
|
|
39
|
+
"l10n",
|
|
40
|
+
"localization",
|
|
41
|
+
"ooneex",
|
|
42
|
+
"translation",
|
|
43
|
+
"typescript"
|
|
44
|
+
]
|
|
37
45
|
}
|
|
Binary file
|