diff --git a/.gitignore b/.gitignore index aa5e2df..b4e7cea 100644 --- a/.gitignore +++ b/.gitignore @@ -93,7 +93,6 @@ out # Nuxt.js build / generate output .nuxt -dist # Gatsby files .cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json index b283fa7..9e431c8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "cSpell.words": ["biomejs", "bunx", "fnlb", "FNLB"] + "cSpell.words": ["biomejs", "bunx", "fnlb", "FNLB", "Patatas"] } diff --git a/bun.lockb b/bun.lockb index a473df9..c3c2abc 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..323f832 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,30 @@ +// Generated by dts-bundle-generator v8.1.2 + +export declare enum Locales { + Default = "en", + De = "de", + Es = "es", + Fr = "fr", + It = "it", + Pl = "pl", + Pt = "pt", + Tr = "tr" +} +export type LocalesString = `${Locales}`; +export declare class LocaleClient { + localeObject: Record; + localeString: LocalesString; + defaultLocaleString: LocalesString; + removeDash: boolean; + constructor({ locale, localeRoute, localeModule, removeDash }: { + locale?: LocalesString; + localeRoute: string; + localeModule: string; + removeDash?: boolean; + }); + translate(key: string, variables?: Record): string; + numberToLocaleString(number: number): string; + static transformToSupportedLocale(locale: any): LocalesString; +} + +export {}; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..6cdfa6a --- /dev/null +++ b/dist/index.js @@ -0,0 +1 @@ +var s=((t)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(t,{get:(i,l)=>(typeof require!=="undefined"?require:i)[l]}):t)(function(t){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var e;(function(r){r["Default"]="en";r["De"]="de";r["Es"]="es";r["Fr"]="fr";r["It"]="it";r["Pl"]="pl";r["Pt"]="pt";r["Tr"]="tr"})(e||(e={}));class o{localeObject;localeString;defaultLocaleString;removeDash;constructor({locale:t,localeRoute:i,localeModule:l,removeDash:a=!1}){this.removeDash=a,this.defaultLocaleString=this.removeDash?e.Default.split("-")[0]:e.Default,this.localeString=this.removeDash?(t||this.defaultLocaleString).split("-")[0]:t||this.defaultLocaleString;let n;try{n=s(`../src/locales/${i}/${t}.json`)}catch{n=s(`../src/locales/${i}/${this.defaultLocaleString}.json`),this.localeString=this.defaultLocaleString}this.localeObject=n[l]}translate(t,i){return this.localeObject[t].replace(/{(.*?)}/gi,(a,n)=>{return i?.[n]??""})}numberToLocaleString(t){return t.toLocaleString(this.localeString)}static transformToSupportedLocale(t){if(typeof t!=="string")return e.Default;if(Object.values(e).includes(t))return t;return e.Default}}export{e as Locales,o as LocaleClient}; diff --git a/package.json b/package.json index 0d500d8..655e5c3 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@fnlb-project/locales", "description": "FNLB Translation Service", - "version": "1.1.0", - "main": "src/index.ts", - "types": "src/index.ts", + "version": "1.1.2", + "main": "dist/index.js", + "types": "dist/index.d.ts", "type": "module", "scripts": { "build": "bun run build.ts", @@ -25,4 +25,4 @@ "typescript": "^5.3.3" }, "packageManager": "pnpm@8.14.1" -} +} \ No newline at end of file diff --git a/src/classes/LocaleClient.ts b/src/classes/LocaleClient.ts index 120a443..c05b635 100644 --- a/src/classes/LocaleClient.ts +++ b/src/classes/LocaleClient.ts @@ -35,15 +35,19 @@ export class LocaleClient { this.localeString = this.removeDash ? ((locale || this.defaultLocaleString).split( '-' - )[0] as LocalesString) + )[0] as LocalesString) : locale || this.defaultLocaleString; let requiredLocale; try { - requiredLocale = require(`../locales/${localeRoute}/${locale}.json`); + requiredLocale = require( + `../src/locales/${localeRoute}/${locale}.json` + ); } catch { - requiredLocale = require(`../locales/${localeRoute}/${this.defaultLocaleString}.json`); + requiredLocale = require( + `../src/locales/${localeRoute}/${this.defaultLocaleString}.json` + ); this.localeString = this.defaultLocaleString; }