@stacksjs/i18n 0.70.83 → 0.70.85
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.js +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var GG=import.meta.require;function JG(G,J){return KG(J)(G)}function KG(G){let J=G.split("-")[0]?.toLowerCase()??G.toLowerCase(),K=j[J];if(K)return K;return()=>"other"}function M(G,J="|"){let K=G.split(J).map((U)=>U.trim()),Z=new Map;if(K.length===1)Z.set("other",K[0]??"");else if(K.length===2)Z.set("one",K[0]??""),Z.set("other",K[1]??"");else if(K.length===3)Z.set("zero",K[0]??""),Z.set("one",K[1]??""),Z.set("other",K[2]??"");else if(K.length>=4){let U=["zero","one","two","few","many","other"];for(let _=0;_<K.length&&_<U.length;_++){let $=U[_],B=K[_];if($!==void 0&&B!==void 0)Z.set($,B)}}return Z}function S(G,J,K){let Z=JG(J,K);if(G.has(Z))return G.get(Z);if(G.has("other"))return G.get("other");let U=G.values().next();return U.done?"":U.value}var j={en:(G)=>G===1?"one":"other",de:(G)=>G===1?"one":"other",nl:(G)=>G===1?"one":"other",es:(G)=>G===1?"one":"other",it:(G)=>G===1?"one":"other",pt:(G)=>G===1?"one":"other",sv:(G)=>G===1?"one":"other",da:(G)=>G===1?"one":"other",no:(G)=>G===1?"one":"other",fi:(G)=>G===1?"one":"other",el:(G)=>G===1?"one":"other",he:(G)=>G===1?"one":"other",hu:(G)=>G===1?"one":"other",tr:(G)=>G===1?"one":"other",zh:()=>"other",ja:()=>"other",ko:()=>"other",vi:()=>"other",th:()=>"other",id:()=>"other",ms:()=>"other",fr:(G)=>G===0||G===1?"one":"other",ru:(G)=>{let J=G%10,K=G%100;if(J===1&&K!==11)return"one";if(J>=2&&J<=4&&(K<12||K>14))return"few";if(J===0||J>=5&&J<=9||K>=11&&K<=14)return"many";return"other"},uk:(G)=>{let J=G%10,K=G%100;if(J===1&&K!==11)return"one";if(J>=2&&J<=4&&(K<12||K>14))return"few";if(J===0||J>=5&&J<=9||K>=11&&K<=14)return"many";return"other"},pl:(G)=>{let J=G%10,K=G%100;if(G===1)return"one";if(J>=2&&J<=4&&(K<12||K>14))return"few";if(J===0||J===1||J>=5&&J<=9||K>=12&&K<=14)return"many";return"other"},cs:(G)=>{if(G===1)return"one";if(G>=2&&G<=4)return"few";return"other"},sk:(G)=>{if(G===1)return"one";if(G>=2&&G<=4)return"few";return"other"},ar:(G)=>{if(G===0)return"zero";if(G===1)return"one";if(G===2)return"two";let J=G%100;if(J>=3&&J<=10)return"few";if(J>=11&&J<=99)return"many";return"other"},cy:(G)=>{if(G===0)return"zero";if(G===1)return"one";if(G===2)return"two";if(G===3)return"few";if(G===6)return"many";return"other"},sl:(G)=>{let J=G%100;if(J===1)return"one";if(J===2)return"two";if(J===3||J===4)return"few";return"other"},ga:(G)=>{if(G===1)return"one";if(G===2)return"two";if(G>=3&&G<=6)return"few";if(G>=7&&G<=10)return"many";return"other"},lt:(G)=>{let J=G%10,K=G%100;if(J===1&&(K<11||K>19))return"one";if(J>=2&&J<=9&&(K<11||K>19))return"few";return"other"},lv:(G)=>{let J=G%10,K=G%100;if(G===0)return"zero";if(J===1&&K!==11)return"one";return"other"},ro:(G)=>{if(G===1)return"one";let J=G%100;if(G===0||J>=1&&J<=19)return"few";return"other"},hi:(G)=>G===0||G===1?"one":"other"};function bG(){return Object.keys(j)}function vG(G){return(G.split("-")[0]?.toLowerCase()??G.toLowerCase())in j}function hG(G,J){let K=G.split("-")[0]?.toLowerCase()??G.toLowerCase();j[K]=J}var g={locale:"en",fallbackLocale:"en",availableLocales:["en"],messages:{},warnMissing:!0,escapeValues:!1,keySeparator:".",pluralSeparator:"|"},H="en",R="en",N={},F={...g};class D{_locale;_fallbackLocale;_messages;_config;constructor(G={}){this._config={...g,...G},this._locale=this._config.locale,this._fallbackLocale=this._config.fallbackLocale,this._messages=this._config.messages||{}}get locale(){return this._locale}set locale(G){this._locale=G}get fallbackLocale(){return this._fallbackLocale}get availableLocales(){return Object.keys(this._messages)}t=(G,J,K)=>{return this.translate(G,J,K)};tc=(G,J,K,Z)=>{return this.translatePlural(G,J,K,Z)};te=(G,J)=>{return this.hasTranslation(G,J)};tm=(G,J)=>{return this.getMessage(G,J??this.locale)};setLocale=(G)=>{this._locale=G};addTranslations=(G,J)=>{if(!this._messages[G])this._messages[G]={};this._messages[G]=P(this._messages[G],J)};d=(G,J)=>{let K=typeof G==="number"?new Date(G):G,Z=this._config.dateTimeFormats?.[this._locale]?.[J||"short"]||{};return new Intl.DateTimeFormat(this._locale,Z).format(K)};n=(G,J)=>{let K=this._config.numberFormats?.[this._locale]?.[J||"decimal"]||{};return new Intl.NumberFormat(this._locale,K).format(G)};translate(G,J,K){let Z=K||this._locale,U=this.getMessage(G,Z);if(U===void 0){let _=Z.indexOf("-");if(_>0){let $=Z.slice(0,_);if($!==this._fallbackLocale)U=this.getMessage(G,$)}}if(U===void 0&&Z!==this._fallbackLocale)U=this.getMessage(G,this._fallbackLocale);if(U===void 0){if(this._config.warnMissing)console.warn(`[i18n] Missing translation: "${G}" for locale "${Z}"`);if(this._config.missingHandler){let _=this._config.missingHandler(Z,G);if(_!==void 0)return _}return G}if(typeof U!=="string")return G;return this.interpolate(U,J)}translatePlural(G,J,K,Z){let U=Z||this._locale,_=this.getMessage(G,U);if(_===void 0&&U!==this._fallbackLocale)_=this.getMessage(G,this._fallbackLocale);if(_===void 0||typeof _!=="string"){if(this._config.warnMissing)console.warn(`[i18n] Missing plural translation: "${G}" for locale "${U}"`);return G}let $=M(_,this._config.pluralSeparator),B=S($,J,U),X={count:J,n:J,...K};return this.interpolate(B,X)}hasTranslation(G,J){let K=J||this._locale;return this.getMessage(G,K)!==void 0}getMessage(G,J){let K=this._messages[J];if(!K)return;let Z=G.split(this._config.keySeparator||"."),U=K;for(let _ of Z){if(U===void 0||typeof U==="string")return;U=U[_]}return U}interpolate(G,J){if(!J)return G;return G.replace(/\{(\w+)\}/g,(K,Z)=>{let U=J[Z];if(U===void 0||U===null)return K;let _=String(U);return this._config.escapeValues?XG(_):_})}}function x(G){H=G}function E(){return H}function yG(G){R=G}function V(){return Object.keys(N)}function q(G,J){if(!N[G])N[G]={};N[G]=P(N[G],J)}function O(G){for(let[J,K]of Object.entries(G))q(J,K)}function p(G,J){return T(G,J||H)!==void 0}function T(G,J){let K=N[J];if(!K)return;let Z=G.split(F.keySeparator||"."),U=K;for(let _ of Z){if(U===void 0||typeof U==="string")return;U=U[_]}return U}function m(G,J){if(!J)return G;return G.replace(/\{(\w+)\}/g,(K,Z)=>{let U=J[Z];if(U===void 0||U===null)return K;return String(U)})}function d(G,J,K){let Z=K||H,U=T(G,Z);if(U===void 0&&Z!==R)U=T(G,R);if(U===void 0){if(F.warnMissing)console.warn(`[i18n] Missing translation: "${G}" for locale "${Z}"`);return G}if(typeof U!=="string")return G;return m(U,J)}var UG=d;function ZG(G,J,K,Z){let U=Z||H,_=T(G,U);if(_===void 0&&U!==R)_=T(G,R);if(_===void 0||typeof _!=="string")return G;let $=M(_,F.pluralSeparator),B=S($,J,U),X={count:J,n:J,...K};return m(B,X)}function _G(G,J){return p(G,J)}function $G(G,J){return T(G,J||H)}function u(G={}){return new D(G)}function BG(G={}){return u(G)}function i(G){if(F={...F,...G},G.locale)H=G.locale;if(G.fallbackLocale)R=G.fallbackLocale;if(G.messages)O(G.messages)}function P(G,J){let K={...G};for(let Z of Object.keys(J)){let U=J[Z],_=K[Z];if(typeof U==="object"&&U!==null&&typeof _==="object"&&_!==null)K[Z]=P(_,U);else if(U!==void 0)K[Z]=U}return K}function XG(G){let J={"&":"&","<":"<",">":">",'"':""","'":"'"};return G.replace(/[&<>"']/g,(K)=>J[K]||K)}function EG(G,J="medium",K){let Z=K||E(),U=C(G),_=typeof J==="string"?{dateStyle:J}:J;return new Intl.DateTimeFormat(Z,_).format(U)}function QG(G,J="short",K){let Z=K||E(),U=C(G),_=typeof J==="string"?{timeStyle:J}:J;return new Intl.DateTimeFormat(Z,_).format(U)}function WG(G,J="medium",K="short",Z){let U=Z||E(),_=C(G);return new Intl.DateTimeFormat(U,{dateStyle:J,timeStyle:K}).format(_)}function YG(G,J=new Date,K="long",Z){let U=Z||E(),_=C(G),$=C(J),B=_.getTime()-$.getTime(),X=Math.round(B/1000),Q=Math.round(X/60),W=Math.round(Q/60),A=Math.round(W/24),Y=Math.round(A/7),I=Math.round(A/30),z=Math.round(A/365),w=new Intl.RelativeTimeFormat(U,{style:K});if(Math.abs(X)<60)return w.format(X,"second");if(Math.abs(Q)<60)return w.format(Q,"minute");if(Math.abs(W)<24)return w.format(W,"hour");if(Math.abs(A)<7)return w.format(A,"day");if(Math.abs(Y)<4)return w.format(Y,"week");if(Math.abs(I)<12)return w.format(I,"month");return w.format(z,"year")}function AG(G,J={},K){let Z=K||E(),U={...J};if(J.compact)U.notation="compact",U.compactDisplay="short";if(J.precision!==void 0)U.minimumFractionDigits=J.precision,U.maximumFractionDigits=J.precision;return new Intl.NumberFormat(Z,U).format(G)}function IG(G,J="USD",K={},Z){let U=Z||E();return new Intl.NumberFormat(U,{style:"currency",currency:J,...K}).format(G)}function wG(G,J={},K){let Z=K||E();return new Intl.NumberFormat(Z,{style:"percent",...J}).format(G)}function mG(G,J,K="short",Z){let U=Z||E();return new Intl.NumberFormat(U,{style:"unit",unit:J,unitDisplay:K}).format(G)}function dG(G,J=2,K){let Z=K||E();if(G===0)return"0 B";let U=1024,_=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],$=Math.floor(Math.log(G)/Math.log(U)),B=G/Math.pow(U,$);return`${new Intl.NumberFormat(Z,{minimumFractionDigits:0,maximumFractionDigits:J}).format(B)} ${_[$]}`}function HG(G,J="conjunction",K="long",Z){let U=Z||E();return new Intl.ListFormat(U,{type:J,style:K}).format(G)}function n(G,J){let K=J||E();return new Intl.PluralRules(K).select(G)}function uG(G,J,K){let Z=n(G,K);return J[Z]??J.other}function b(G,J="language",K="long",Z){let U=Z||E();try{return new Intl.DisplayNames(U,{type:J,style:K}).of(G)}catch{return}}function iG(G,J){return b(G,"language","long",J)}function nG(G,J){return b(G,"region","long",J)}function cG(G,J){return b(G,"currency","long",J)}function rG(G,J,K={},Z){let U=Z||E();return new Intl.Collator(U,K).compare(G,J)}function sG(G,J={},K){let Z=K||E(),U=new Intl.Collator(Z,J);return[...G].sort((_,$)=>U.compare(_,$))}function C(G){if(G instanceof Date)return G;if(typeof G==="number")return new Date(G);return new Date(G)}function NG(G){let J=G||E(),K=(J.split("-")[0]??J).toLowerCase();return["ar","he","fa","ur","yi","ps","sd","ug","ku","ckb"].includes(K)?"rtl":"ltr"}function tG(G){return NG(G)==="rtl"}import{existsSync as RG,readdirSync as c}from"fs";import{readFile as TG}from"fs/promises";import{basename as r,extname as v,join as h}from"path";import{log as zG}from"@stacksjs/logging";async function L(G){let{directory:J,extensions:K=[".json",".yaml",".yml",".ts",".js"],recursive:Z=!1,namespaceSeparator:U="."}=G,_={};if(!RG(J))return zG.warn(`[i18n] Translation directory not found: ${J}`),_;return await s(J,_,K,Z,U,""),O(_),_}async function s(G,J,K,Z,U,_){let $=c(G,{withFileTypes:!0});for(let B of $){let X=h(G,B.name);if(B.isDirectory()){let Q=B.name;if(jG(Q))await FG(X,Q,J,K);else if(Z){let W=_?`${_}${U}${B.name}`:B.name;await s(X,J,K,Z,U,W)}}else if(B.isFile()){let Q=v(B.name);if(K.includes(Q)){let W=r(B.name,Q);if(!J[W])J[W]={};let A=await k(X);if(_)VG(J[W],_,A,U);else J[W]=f(J[W],A)}}}}async function FG(G,J,K,Z){if(!K[J])K[J]={};let U=c(G,{withFileTypes:!0});for(let _ of U){if(!_.isFile())continue;let $=v(_.name);if(!Z.includes($))continue;let B=h(G,_.name),X=r(_.name,$),Q=await k(B);if(X===J)K[J]=f(K[J],Q);else K[J][X]=Q}}async function k(G){let J=v(G).toLowerCase(),K=await TG(G,"utf8");switch(J){case".json":try{return JSON.parse(K)}catch{throw Error(`Invalid JSON in translation file: ${G}`)}case".yaml":case".yml":return CG(K);case".ts":case".js":{let Z=await import(G);return Z.default||Z}default:throw Error(`Unsupported file type: ${J}`)}}async function OG(G,J){let K=await k(J);return q(G,K),K}function CG(G){try{let J=Bun.YAML.parse(G);if(!J||typeof J!=="object"||Array.isArray(J))throw Error("YAML content must be an object at the root level");return J}catch(J){let K=J instanceof Error?J.message:"Unknown YAML parse error";throw Error(`Invalid YAML translation file: ${K}`)}}function jG(G){return/^[a-z]{2}(?:-[A-Z]{2})?(?:-[A-Za-z]+)?$/i.test(G)}function VG(G,J,K,Z){let U=J.split(Z),_=G;for(let B=0;B<U.length-1;B++){let X=U[B];if(!X)continue;if(!_[X]||typeof _[X]==="string")_[X]={};_=_[X]}let $=U[U.length-1];if($)_[$]=K}function f(G,J){let K={...G};for(let Z of Object.keys(J)){let U=J[Z];if(U===void 0)continue;let _=K[Z];if(typeof U==="object"&&U!==null&&typeof _==="object"&&_!==null)K[Z]=f(_,U);else K[Z]=U}return K}function KJ(G,J={}){return{load:()=>L({directory:G,...J}),loadLocale:(K,Z)=>OG(K,h(G,Z))}}async function UJ(G){let{loadTranslations:J}=await import("@stacksjs/ts-i18n"),K=await J(G);return O(K),K}var _J={en:{code:"en",name:"English",nativeName:"English",direction:"ltr"},"en-US":{code:"en-US",name:"English (US)",nativeName:"English (US)",direction:"ltr",region:"US"},"en-GB":{code:"en-GB",name:"English (UK)",nativeName:"English (UK)",direction:"ltr",region:"GB"},es:{code:"es",name:"Spanish",nativeName:"Espa\xF1ol",direction:"ltr"},fr:{code:"fr",name:"French",nativeName:"Fran\xE7ais",direction:"ltr"},de:{code:"de",name:"German",nativeName:"Deutsch",direction:"ltr"},it:{code:"it",name:"Italian",nativeName:"Italiano",direction:"ltr"},pt:{code:"pt",name:"Portuguese",nativeName:"Portugu\xEAs",direction:"ltr"},"pt-BR":{code:"pt-BR",name:"Portuguese (Brazil)",nativeName:"Portugu\xEAs (Brasil)",direction:"ltr",region:"BR"},zh:{code:"zh",name:"Chinese",nativeName:"\u4E2D\u6587",direction:"ltr"},"zh-CN":{code:"zh-CN",name:"Chinese (Simplified)",nativeName:"\u7B80\u4F53\u4E2D\u6587",direction:"ltr",region:"CN"},"zh-TW":{code:"zh-TW",name:"Chinese (Traditional)",nativeName:"\u7E41\u9AD4\u4E2D\u6587",direction:"ltr",region:"TW"},ja:{code:"ja",name:"Japanese",nativeName:"\u65E5\u672C\u8A9E",direction:"ltr"},ko:{code:"ko",name:"Korean",nativeName:"\uD55C\uAD6D\uC5B4",direction:"ltr"},ar:{code:"ar",name:"Arabic",nativeName:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",direction:"rtl"},he:{code:"he",name:"Hebrew",nativeName:"\u05E2\u05D1\u05E8\u05D9\u05EA",direction:"rtl"},ru:{code:"ru",name:"Russian",nativeName:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439",direction:"ltr"},nl:{code:"nl",name:"Dutch",nativeName:"Nederlands",direction:"ltr"},pl:{code:"pl",name:"Polish",nativeName:"Polski",direction:"ltr"},tr:{code:"tr",name:"Turkish",nativeName:"T\xFCrk\xE7e",direction:"ltr"},vi:{code:"vi",name:"Vietnamese",nativeName:"Ti\u1EBFng Vi\u1EC7t",direction:"ltr"},th:{code:"th",name:"Thai",nativeName:"\u0E44\u0E17\u0E22",direction:"ltr"},hi:{code:"hi",name:"Hindi",nativeName:"\u0939\u093F\u0928\u094D\u0926\u0940",direction:"ltr"}};import{loadTranslations as FJ,generateTypes as OJ,generateTypesFromModule as CJ,generateSampleConfig as jJ,writeOutputs as VJ,createTranslator as qJ}from"@stacksjs/ts-i18n";import{existsSync as qG}from"fs";import{config as y}from"@stacksjs/config";import{projectPath as MG}from"@stacksjs/path";var t=!1;async function o(){if(t)return;let G=MG("locales");if(qG(G))await L({directory:G,extensions:[".yaml",".yml",".json"]});let J=y.app,K=J?.locale??"en",Z=J?.fallbackLocale??K,U=V();i({locale:K,fallbackLocale:Z,availableLocales:U.length>0?U:[K],warnMissing:(J?.env??process.env.APP_ENV)!=="production"}),t=!0}function l(G){let K=y.app?.locale??"en",Z=new Set(V());if(!Z.size)Z.add(K);let U=(Y)=>{let I=Y.trim().toLowerCase();if(Z.has(I))return I;let z=I.split("-")[0];if(z&&Z.has(z))return z;return K};if(!G)return K;let _=new URL(G.url),$=_.pathname,B=G.headers.get("x-stx-locale");if(B)return U(B);for(let Y of Z){if(Y===K)continue;if($===`/${Y}`||$===`/${Y}/`)return U(Y);if($.startsWith(`/${Y}/`))return U(Y)}let X=_.searchParams.get("locale");if(X)return U(X);let W=(G.headers.get("cookie")??"").match(/(?:^|;\s*)locale=([a-z]{2}(?:-[a-z]{2})?)(?:;|$)/i);if(W?.[1])return U(W[1]);let A=G.headers.get("accept-language")??"";for(let Y of A.split(",")){let I=Y.split(";")[0]?.trim();if(I)return U(I)}return K}async function SG(G){await o();let J=l(G);return x(J),J}function DG(G,J){let K=G.trim().toLowerCase();if(J.locales.includes(K))return K;let Z=K.split("-")[0];if(Z&&J.locales.includes(Z))return Z;return null}function a(G,J){for(let K of J){if(G===`/${K}`||G===`/${K}/`)return{locale:K,path:"/"};if(G.startsWith(`/${K}/`))return{locale:K,path:G.slice(K.length+1)}}return{locale:null,path:G}}function e(G,J,K){if(J===K)return G;if(G==="/")return`/${J}/`;if(G==="/404.html")return`/${J}/404.html`;return`/${J}${G}`}function xG(G,J,K){let Z=DG(J,K);if(!Z)return Response.redirect(new URL("/",G.url).href,302);let U=G.headers.get("referer"),_="/";if(U)try{let Q=new URL(U);if(!Q.pathname.startsWith("/locale/"))_=a(Q.pathname,K.locales).path||"/"}catch{_="/"}let $=e(_,Z,K.defaultLocale),B=new URL($,G.url),X=Response.redirect(B.href,302);return X.headers.append("Set-Cookie",`locale=${Z}; Path=/; Max-Age=31536000; SameSite=Lax`),X}export{VJ as writeI18nOutputs,BG as useI18n,UG as trans,$G as tm,_G as te,ZG as tc,d as t,a as stripLocalePrefix,sG as sortStrings,x as setLocale,yG as setFallbackLocale,S as selectPluralForm,uG as selectPlural,l as resolveRequestLocale,M as parsePluralForms,e as localizePath,FJ as loadTranslationsFromDisk,O as loadTranslations,OG as loadLocale,UJ as loadFromTsI18n,L as loadFromDirectory,k as loadFile,tG as isRTL,p as hasTranslation,vG as hasPluralRule,NG as getTextDirection,bG as getSupportedPluralLocales,nG as getRegionName,KG as getPluralRule,JG as getPluralCategory,E as getLocale,iG as getLanguageName,b as getDisplayName,cG as getCurrencyName,V as getAvailableLocales,CJ as generateI18nTypesFromModule,OJ as generateI18nTypes,jJ as generateI18nSampleConfig,mG as formatUnit,QG as formatTime,YG as formatRelativeTime,n as formatPlural,wG as formatPercent,AG as formatNumber,HG as formatList,WG as formatDateTime,EG as formatDate,IG as formatCurrency,dG as formatBytes,o as ensureLocalesLoaded,qJ as createSimpleTranslator,xG as createLocaleSwitchResponse,KJ as createLoader,u as createI18n,i as configure,rG as compareStrings,SG as applyRequestLocale,q as addTranslations,hG as addPluralRule,_J as LOCALE_INFO,D as I18n};
|
|
2
|
+
var x=import.meta.require;function M(q,B){return D(B)(q)}function D(q){let B=q.split("-")[0]?.toLowerCase()??q.toLowerCase(),G=E[B];if(G)return G;return()=>"other"}function c(q,B="|"){let G=q.split(B).map((K)=>K.trim()),J=new Map;if(G.length===1)J.set("other",G[0]??"");else if(G.length===2)J.set("one",G[0]??""),J.set("other",G[1]??"");else if(G.length===3)J.set("zero",G[0]??""),J.set("one",G[1]??""),J.set("other",G[2]??"");else if(G.length>=4){let K=["zero","one","two","few","many","other"];for(let Q=0;Q<G.length&&Q<K.length;Q++){let X=K[Q],U=G[Q];if(X!==void 0&&U!==void 0)J.set(X,U)}}return J}function r(q,B,G){let J=M(B,G);if(q.has(J))return q.get(J);if(q.has("other"))return q.get("other");let K=q.values().next();return K.done?"":K.value}var E={en:(q)=>q===1?"one":"other",de:(q)=>q===1?"one":"other",nl:(q)=>q===1?"one":"other",es:(q)=>q===1?"one":"other",it:(q)=>q===1?"one":"other",pt:(q)=>q===1?"one":"other",sv:(q)=>q===1?"one":"other",da:(q)=>q===1?"one":"other",no:(q)=>q===1?"one":"other",fi:(q)=>q===1?"one":"other",el:(q)=>q===1?"one":"other",he:(q)=>q===1?"one":"other",hu:(q)=>q===1?"one":"other",tr:(q)=>q===1?"one":"other",zh:()=>"other",ja:()=>"other",ko:()=>"other",vi:()=>"other",th:()=>"other",id:()=>"other",ms:()=>"other",fr:(q)=>q===0||q===1?"one":"other",ru:(q)=>{let B=q%10,G=q%100;if(B===1&&G!==11)return"one";if(B>=2&&B<=4&&(G<12||G>14))return"few";if(B===0||B>=5&&B<=9||G>=11&&G<=14)return"many";return"other"},uk:(q)=>{let B=q%10,G=q%100;if(B===1&&G!==11)return"one";if(B>=2&&B<=4&&(G<12||G>14))return"few";if(B===0||B>=5&&B<=9||G>=11&&G<=14)return"many";return"other"},pl:(q)=>{let B=q%10,G=q%100;if(q===1)return"one";if(B>=2&&B<=4&&(G<12||G>14))return"few";if(B===0||B===1||B>=5&&B<=9||G>=12&&G<=14)return"many";return"other"},cs:(q)=>{if(q===1)return"one";if(q>=2&&q<=4)return"few";return"other"},sk:(q)=>{if(q===1)return"one";if(q>=2&&q<=4)return"few";return"other"},ar:(q)=>{if(q===0)return"zero";if(q===1)return"one";if(q===2)return"two";let B=q%100;if(B>=3&&B<=10)return"few";if(B>=11&&B<=99)return"many";return"other"},cy:(q)=>{if(q===0)return"zero";if(q===1)return"one";if(q===2)return"two";if(q===3)return"few";if(q===6)return"many";return"other"},sl:(q)=>{let B=q%100;if(B===1)return"one";if(B===2)return"two";if(B===3||B===4)return"few";return"other"},ga:(q)=>{if(q===1)return"one";if(q===2)return"two";if(q>=3&&q<=6)return"few";if(q>=7&&q<=10)return"many";return"other"},lt:(q)=>{let B=q%10,G=q%100;if(B===1&&(G<11||G>19))return"one";if(B>=2&&B<=9&&(G<11||G>19))return"few";return"other"},lv:(q)=>{let B=q%10,G=q%100;if(q===0)return"zero";if(B===1&&G!==11)return"one";return"other"},ro:(q)=>{if(q===1)return"one";let B=q%100;if(q===0||B>=1&&B<=19)return"few";return"other"},hi:(q)=>q===0||q===1?"one":"other"};function n(){return Object.keys(E)}function s(q){return(q.split("-")[0]?.toLowerCase()??q.toLowerCase())in E}function t(q,B){let G=q.split("-")[0]?.toLowerCase()??q.toLowerCase();E[G]=B}var b={locale:"en",fallbackLocale:"en",availableLocales:["en"],messages:{},warnMissing:!0,escapeValues:!1,keySeparator:".",pluralSeparator:"|"},C="en",O="en",W={},F={...b};function $(){return C}function l(q){O=q}function z(q,B){if(!W[q])W[q]={};W[q]=j(W[q],B)}function Y(q){for(let[B,G]of Object.entries(q))z(B,G)}function a(q){if(F={...F,...q},q.locale)C=q.locale;if(q.fallbackLocale)O=q.fallbackLocale;if(q.messages)Y(q.messages)}function j(q,B){let G={...q};for(let J of Object.keys(B)){let K=B[J],Q=G[J];if(typeof K==="object"&&K!==null&&typeof Q==="object"&&Q!==null)G[J]=j(Q,K);else if(K!==void 0)G[J]=K}return G}function Bq(q,B,G="short",J){let K=J||$();return new Intl.NumberFormat(K,{style:"unit",unit:B,unitDisplay:G}).format(q)}function Gq(q,B=2,G){let J=G||$();if(q===0)return"0 B";let K=1024,Q=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],X=Math.floor(Math.log(q)/Math.log(K)),U=q/Math.pow(K,X);return`${new Intl.NumberFormat(J,{minimumFractionDigits:0,maximumFractionDigits:B}).format(U)} ${Q[X]}`}function h(q,B){let G=B||$();return new Intl.PluralRules(G).select(q)}function Jq(q,B,G){let J=h(q,G);return B[J]??B.other}function I(q,B="language",G="long",J){let K=J||$();try{return new Intl.DisplayNames(K,{type:B,style:G}).of(q)}catch{return}}function Kq(q,B){return I(q,"language","long",B)}function Qq(q,B){return I(q,"region","long",B)}function Uq(q,B){return I(q,"currency","long",B)}function Xq(q,B,G={},J){let K=J||$();return new Intl.Collator(K,G).compare(q,B)}function Zq(q,B={},G){let J=G||$(),K=new Intl.Collator(J,B);return[...q].sort((Q,X)=>K.compare(Q,X))}function v(q){let B=q||$(),G=(B.split("-")[0]??B).toLowerCase();return["ar","he","fa","ur","yi","ps","sd","ug","ku","ckb"].includes(G)?"rtl":"ltr"}function _q(q){return v(q)==="rtl"}import{existsSync as L,readdirSync as S}from"fs";import{readFile as k}from"fs/promises";import{basename as V,extname as w,join as H}from"path";import{log as f}from"@stacksjs/logging";async function y(q){let{directory:B,extensions:G=[".json",".yaml",".yml",".ts",".js"],recursive:J=!1,namespaceSeparator:K="."}=q,Q={};if(!L(B))return f.warn(`[i18n] Translation directory not found: ${B}`),Q;return await P(B,Q,G,J,K,""),Y(Q),Q}async function P(q,B,G,J,K,Q){let X=S(q,{withFileTypes:!0});for(let U of X){let Z=H(q,U.name);if(U.isDirectory()){let _=U.name;if(m(_))await p(Z,_,B,G);else if(J){let A=Q?`${Q}${K}${U.name}`:U.name;await P(Z,B,G,J,K,A)}}else if(U.isFile()){let _=w(U.name);if(G.includes(_)){let A=V(U.name,_);if(!B[A])B[A]={};let T=await N(Z);if(Q)u(B[A],Q,T,K);else B[A]=R(B[A],T)}}}}async function p(q,B,G,J){if(!G[B])G[B]={};let K=S(q,{withFileTypes:!0});for(let Q of K){if(!Q.isFile())continue;let X=w(Q.name);if(!J.includes(X))continue;let U=H(q,Q.name),Z=V(Q.name,X),_=await N(U);if(Z===B)G[B]=R(G[B],_);else G[B][Z]=_}}async function N(q){let B=w(q).toLowerCase(),G=await k(q,"utf8");switch(B){case".json":try{return JSON.parse(G)}catch{throw Error(`Invalid JSON in translation file: ${q}`)}case".yaml":case".yml":return d(G);case".ts":case".js":{let J=await import(q);return J.default||J}default:throw Error(`Unsupported file type: ${B}`)}}async function g(q,B){let G=await N(B);return z(q,G),G}function d(q){try{let B=Bun.YAML.parse(q);if(!B||typeof B!=="object"||Array.isArray(B))throw Error("YAML content must be an object at the root level");return B}catch(B){let G=B instanceof Error?B.message:"Unknown YAML parse error";throw Error(`Invalid YAML translation file: ${G}`)}}function m(q){return/^[a-z]{2}(?:-[A-Z]{2})?(?:-[A-Za-z]+)?$/i.test(q)}function u(q,B,G,J){let K=B.split(J),Q=q;for(let U=0;U<K.length-1;U++){let Z=K[U];if(!Z)continue;if(!Q[Z]||typeof Q[Z]==="string")Q[Z]={};Q=Q[Z]}let X=K[K.length-1];if(X)Q[X]=G}function R(q,B){let G={...q};for(let J of Object.keys(B)){let K=B[J];if(K===void 0)continue;let Q=G[J];if(typeof K==="object"&&K!==null&&typeof Q==="object"&&Q!==null)G[J]=R(Q,K);else G[J]=K}return G}function Iq(q,B={}){return{load:()=>y({directory:q,...B}),loadLocale:(G,J)=>g(G,H(q,J))}}async function wq(q){let{loadTranslations:B}=await import("@stacksjs/ts-i18n"),G=await B(q);return Y(G),G}var Nq={en:{code:"en",name:"English",nativeName:"English",direction:"ltr"},"en-US":{code:"en-US",name:"English (US)",nativeName:"English (US)",direction:"ltr",region:"US"},"en-GB":{code:"en-GB",name:"English (UK)",nativeName:"English (UK)",direction:"ltr",region:"GB"},es:{code:"es",name:"Spanish",nativeName:"Espa\xF1ol",direction:"ltr"},fr:{code:"fr",name:"French",nativeName:"Fran\xE7ais",direction:"ltr"},de:{code:"de",name:"German",nativeName:"Deutsch",direction:"ltr"},it:{code:"it",name:"Italian",nativeName:"Italiano",direction:"ltr"},pt:{code:"pt",name:"Portuguese",nativeName:"Portugu\xEAs",direction:"ltr"},"pt-BR":{code:"pt-BR",name:"Portuguese (Brazil)",nativeName:"Portugu\xEAs (Brasil)",direction:"ltr",region:"BR"},zh:{code:"zh",name:"Chinese",nativeName:"\u4E2D\u6587",direction:"ltr"},"zh-CN":{code:"zh-CN",name:"Chinese (Simplified)",nativeName:"\u7B80\u4F53\u4E2D\u6587",direction:"ltr",region:"CN"},"zh-TW":{code:"zh-TW",name:"Chinese (Traditional)",nativeName:"\u7E41\u9AD4\u4E2D\u6587",direction:"ltr",region:"TW"},ja:{code:"ja",name:"Japanese",nativeName:"\u65E5\u672C\u8A9E",direction:"ltr"},ko:{code:"ko",name:"Korean",nativeName:"\uD55C\uAD6D\uC5B4",direction:"ltr"},ar:{code:"ar",name:"Arabic",nativeName:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",direction:"rtl"},he:{code:"he",name:"Hebrew",nativeName:"\u05E2\u05D1\u05E8\u05D9\u05EA",direction:"rtl"},ru:{code:"ru",name:"Russian",nativeName:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439",direction:"ltr"},nl:{code:"nl",name:"Dutch",nativeName:"Nederlands",direction:"ltr"},pl:{code:"pl",name:"Polish",nativeName:"Polski",direction:"ltr"},tr:{code:"tr",name:"Turkish",nativeName:"T\xFCrk\xE7e",direction:"ltr"},vi:{code:"vi",name:"Vietnamese",nativeName:"Ti\u1EBFng Vi\u1EC7t",direction:"ltr"},th:{code:"th",name:"Thai",nativeName:"\u0E44\u0E17\u0E22",direction:"ltr"},hi:{code:"hi",name:"Hindi",nativeName:"\u0939\u093F\u0928\u094D\u0926\u0940",direction:"ltr"}};export{bq as writeI18nOutputs,sq as useI18n,kq as trans,pq as tm,yq as te,fq as tc,Lq as t,GB as stripLocalePrefix,Zq as sortStrings,gq as setLocale,l as setFallbackLocale,r as selectPluralForm,Jq as selectPlural,lq as resolveRequestLocale,c as parsePluralForms,BB as localizePath,Pq as loadTranslationsFromDisk,uq as loadTranslations,g as loadLocale,wq as loadFromTsI18n,y as loadFromDirectory,N as loadFile,_q as isRTL,cq as hasTranslation,s as hasPluralRule,v as getTextDirection,n as getSupportedPluralLocales,Qq as getRegionName,D as getPluralRule,M as getPluralCategory,dq as getLocale,Kq as getLanguageName,I as getDisplayName,Uq as getCurrencyName,iq as getAvailableLocales,Mq as generateI18nTypesFromModule,xq as generateI18nTypes,Dq as generateI18nSampleConfig,Bq as formatUnit,QB as formatTime,$B as formatRelativeTime,EB as formatPlural,_B as formatPercent,XB as formatNumber,AB as formatList,UB as formatDateTime,KB as formatDate,ZB as formatCurrency,Gq as formatBytes,oq as ensureLocalesLoaded,hq as createSimpleTranslator,qB as createLocaleSwitchResponse,Iq as createLoader,nq as createI18n,a as configure,Xq as compareStrings,aq as applyRequestLocale,mq as addTranslations,t as addPluralRule,Nq as LOCALE_INFO,rq as I18n};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/i18n",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.85",
|
|
4
4
|
"description": "Internationalization system for Stacks.js applications",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/i18n#readme",
|
|
8
9
|
"repository": {
|
|
@@ -40,6 +41,6 @@
|
|
|
40
41
|
"@stacksjs/ts-i18n": "^0.1.9"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@stacksjs/development": "0.70.
|
|
44
|
+
"@stacksjs/development": "0.70.85"
|
|
44
45
|
}
|
|
45
46
|
}
|