imba-localization 0.1.8 → 0.2.0
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/README.md +1 -1
- package/index.imba +0 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A lightweight Imba module for loading and handling JSON-based localization files
|
|
|
6
6
|
## ✨ Features
|
|
7
7
|
|
|
8
8
|
- 🔍 **Automatic language detection** - Uses the user's browser language settings
|
|
9
|
-
|
|
9
|
+
- 💾 **Persistence**: Stores user choice in local storage across sessions
|
|
10
10
|
- 🔄 **Smart fallback system** - Falls back to a default language when needed
|
|
11
11
|
- 🧠 **Intuitive access** - Proxy-based access to translation strings
|
|
12
12
|
- 📡 **Event handling** - Support for `onready`, `onchange`, and `onerror` events
|
package/index.imba
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S=Symbol.for("#__init__"),E=Symbol.for("#__initor__"),Q=Symbol.for("#__inited__"),B=Symbol.for("#__hooks__"),A=Symbol.for("#__patch__"),D=Symbol.for("#has"),V=Symbol.for("#meta"),W=Symbol.for("imba"),O=Symbol.for("#__mixin__"),K=Symbol.for("#matcher"),M=Symbol.for("#L"),
|
|
1
|
+
var S=Symbol.for("#__init__"),E=Symbol.for("#__initor__"),Q=Symbol.for("#__inited__"),B=Symbol.for("#__hooks__"),A=Symbol.for("#__patch__"),D=Symbol.for("#has"),V=Symbol.for("#meta"),W=Symbol.for("imba"),O=Symbol.for("#__mixin__"),K=Symbol.for("#matcher"),M=Symbol.for("#L"),C=Symbol.for("#appendChild"),i=Symbol.for("#afterVisit"),j=Symbol.for("#beforeReconcile"),g=Symbol.for("#afterReconcile"),d=Symbol.for("##up");var q={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512},R=new Map,X=globalThis[W]||={counter:0,classes:R};function c(h,n={}){return R.has(h)||R.set(h,{symbol:Symbol(h.name),parent:Object.getPrototypeOf(h.prototype)?.constructor,for:h,uses:null,inits:null,id:X.counter++,...n}),R.get(h)}function T(h,n){return typeof n==="string"?typeof h===n:n?.[Symbol.hasInstance]?.(h)}function Y(h,n){if(!h||!n)return!1;if(h.get)return n.get===h.get;if(h.set)return n.set===h.set;if(h.value)return h.value===n.value}function G(h,n,o,u={}){let r=h.constructor;if(!o&&n){if(o=Object.getOwnPropertyDescriptors(n),delete o.constructor,o[S])console.warn(`Cannot define plain fields when extending class ${r.name}`),delete o[S]}let z=c(r);if(z&&z.augments){let I=new Map;for(let f of Object.keys(o)){let v=Object.getOwnPropertyDescriptor(h,f);for(let w of z.augments){let P=I.get(w);P||I.set(w,P={});let U=Object.getOwnPropertyDescriptor(w.prototype,f);if(U&&!Y(v,U))console.warn("wont extend",f,U,v);else P[f]=o[f]}}for(let[f,v]of I)if(Object.keys(v).length)G(f.prototype,null,v)}return Object.defineProperties(h,o),h}function H(h,n){let o=c(h),u=c(n);if(u.parent){if(!(h.prototype instanceof u.parent))throw new Error(`Mixin ${n.name} has superclass not present in target class`)}if(!u.augments){u.augments=new Set;let z=u.ref=Symbol(n.name),I=Object[Symbol.hasInstance];n.prototype[z]=!0,Object.defineProperty(n,Symbol.hasInstance,{value:function(f){return this===n?f&&!!f[z]:I.call(this,f)}})}if(h.prototype[u.ref])return h;if(u.uses)for(let z of u.uses)H(h,z);u.augments.add(h),o.uses||=[],o.uses.push(n);let r=Object.getOwnPropertyDescriptors(n.prototype);if(delete r.constructor,r[S])o.inits||=[],o.inits.push(n.prototype[S]),delete r[S];if(Object.defineProperties(h.prototype,r),n?.mixed instanceof Function)n.mixed(h);return h}var F={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(h,n,...o)=>{return F.target[n].apply(F.self,o)},get:(h,n)=>{return Reflect.get(F.target,n,F.self)},set:(h,n,o,u)=>{return Reflect.set(F.target,n,o,F.self)}})};function J(h,n,o,u,r=null){let z=Object.getPrototypeOf(h.prototype),I=u&q.HasMixins,f;if(I)R.set(h,R.get(z.constructor)),z=Object.getPrototypeOf(z);if(r){let w=u&q.IsObjectExtension?r:r.prototype,P=c(h);if(P.uses){if(r===w)console.warn("Cannot extend object with mixins");for(let U of P.uses)H(r,U)}if(u&q.HasSuperCalls)F.cache[n]=Object.create(Object.getPrototypeOf(w),Object.getOwnPropertyDescriptors(w));return G(w,h.prototype),r}let v=z?.constructor;if(f=c(h,{symbol:n}),Object.defineProperty(h,V,{value:f,enumerable:!1,configurable:!0}),o&&h.name!==o)Object.defineProperty(h,"name",{value:o,configurable:!0});if(f.flags=u,u&q.HasConstructor)h.prototype[E]=n;if(f.uses)for(let w of f.uses)w.mixes?.(h);if(v?.inherited instanceof Function)v.inherited(h);return h}function L(h,n){if(h[E]===n)h[Q]?.(),h[B]&&h[B].inited(h)}var N=Symbol();class Z{[S](h=null,n=!0,o=!0){var u;this.onready=h?h.onready:void 0,this.onerror=h?h.onerror:void 0,this.onchange=h?h.onchange:void 0,this.languages=h&&(u=h.languages)!==void 0?u:{},this.preferred=h&&(u=h.preferred)!==void 0?u:(window?.navigator?.language||"en-US").slice(0,2),this.default=h?h.default:void 0}constructor(h,n="en"){var o=this;return this[S](),this.default=n,window.fetch(h).then(function(u){return u.json()}).then(function(u){return o._finalize(u,void 0)}).catch(function(u){return o._finalize(void 0,u)}),new Proxy(this,{get:function(u,r,z){if(o[r])return Reflect.get(u,r,z);if(u.languages[r])return u.languages[r];if(u.languages[o.active]&&u.languages[o.active][r])return u.languages[o.active][r];if(T(o.onerror,Function))o.onerror("no_localization_key",r);return""}});L(this,N)}_finalize(h,n){if(n){if(T(this.onerror,Function))this.onerror("no_localization_file",n);else console.log("Localization file was not loaded",n);return}if(h)this.languages=h;if(!this.languages[this.default]){if(T(this.onerror,Function))this.onerror("no_default_localization",this.default);else console.log("There is no Localization for the default language",this.default);return}if(T(this.onready,Function))return this.onready()}get active(){let h=window.localStorage.getItem("imba-localization");if(h&&this.languages[h])return h;if(this.languages[this.preferred])return this.preferred;return this.default}set active(h){if(h=h&&this.languages[h]?h:this.active,window.localStorage.getItem("imba-localization")!=h){if(window.localStorage.setItem("imba-localization",h),T(this.onchange,Function))this.onchange(h)}}static{J(this,N,"Localization",16)}}export{Z as Localization};
|