lang-tag
Version:
A professional solution for managing translations in modern JavaScript/TypeScript projects, especially those using component-based architectures. `lang-tag` simplifies internationalization by allowing you to define translation keys directly within the com
2 lines (1 loc) • 1.24 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function k(e,o,t,n,a){const l={};for(const[s,r]of Object.entries(t)){const u=`${n}${s}`,c=a?`${a}.${s}`:s;if(typeof r=="object"&&r!==null)l[s]=k(e,o,r,`${u}.`,c);else if(typeof r=="string"){const f=(p,i,y,b)=>h=>o.transform({config:e,parentPath:n,path:p,unprefixedPath:i,key:y,value:b,params:h});if(o.processKey){const p={config:e,parentPath:n,path:u,unprefixedPath:c,key:s,value:r};o.processKey(p,(i,y)=>{const b=n+i,h=a?`${a}.${i}`:i;l[i]=f(b,h,i,y)}),l.hasOwnProperty(s)||(l[s]=f(u,c,s,r))}else l[s]=f(u,c,s,r)}}return l}function F(e,o,t){let n=o?.path||"";return n&&!n.endsWith(".")&&(n+="."),k(o,t,e,n,"")}function m(e){const o={};for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const n=e[t];if(n==null)continue;typeof n=="object"&&!Array.isArray(n)&&!(n instanceof Function)?o[t]=m(n):typeof n=="string"?o[t]=(a=>n):typeof n=="function"&&(o[t]=n)}return o}function T(e,o){let t=e;for(const n of o)if(t&&typeof t=="object"&&n in t)t=t[n];else return null;return typeof t=="function"?t:null}function $(e,o){const t=o.split(".");return T(e,t)}exports.createCallableTranslations=F;exports.lookupTranslation=$;exports.normalizeTranslations=m;