lang-tag
Version:
`lang-tag` is a robust solution for managing translations in JavaScript/TypeScript projects, especially those using component-based architectures. It simplifies i18n by allowing you to define translation keys directly within the components where they are
2 lines (1 loc) • 844 B
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(o,t,e,n){const r={};for(const[s,a]of Object.entries(e)){const l=`${n+s}`;if(typeof a=="object"&&a!==null)r[s]=u(o,t,a,`${l}.`);else{const c={config:o,keyPrefix:n,path:l,key:s,value:a};t.onKeyAppend?.(c,i=>r[i]=T=>t.transform({...c,key:i,params:T})),r[s]=i=>t.transform({...c,params:i})}}return r}function m(o,t,e){let n=t?.path||"";return n&&!n.endsWith(".")&&(n+="."),u(t,e,o,n)}const y=({value:o,params:t})=>o.replace(/{{(.*?)}}/g,(e,n)=>t?.[n.trim()]??"");function f(o){const t={};for(const e in o){const n=o[e];n!=null&&(typeof n=="object"&&!Array.isArray(n)&&!(n instanceof Function)?t[e]=f(n):typeof n=="string"?t[e]=r=>n:t[e]=n)}return t}exports.mapTranslationObjectToFunctions=m;exports.mockTranslateTransform=y;exports.normalizeTranslations=f;