imba-localization 0.1.2 → 0.1.4
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 +4 -0
- package/index.imba +6 -5
- package/index.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -48,6 +48,10 @@ const loc = new Localization("ADDRESS_TO_JSON", "en")
|
|
|
48
48
|
loc.onready = do
|
|
49
49
|
console.log loc['hello'] # Output: "Hello" (or translated value)
|
|
50
50
|
console.log loc['goodbye'] # Output: "Goodbye" (or translated value)
|
|
51
|
+
# or
|
|
52
|
+
console.log loc.hello
|
|
53
|
+
# or
|
|
54
|
+
console.log loc..hello
|
|
51
55
|
|
|
52
56
|
loc.onerror = do(msg, err)
|
|
53
57
|
console.error "Localization load error:", msg, err
|
package/index.imba
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export class Localization
|
|
2
2
|
onready
|
|
3
3
|
onerror
|
|
4
4
|
onchange
|
|
@@ -17,6 +17,7 @@ export default class Localization
|
|
|
17
17
|
return new Proxy self, {
|
|
18
18
|
get: do(target, p, receiver)
|
|
19
19
|
return Reflect.get(target, p, receiver) if self[p]
|
|
20
|
+
return target.languages[p] if target.languages[p]
|
|
20
21
|
return target.languages[active][p] if target.languages[active] and target.languages[active][p]
|
|
21
22
|
return ''
|
|
22
23
|
}
|
|
@@ -35,15 +36,15 @@ export default class Localization
|
|
|
35
36
|
else
|
|
36
37
|
console.log('There is no Localization for the default language', default)
|
|
37
38
|
return
|
|
38
|
-
|
|
39
|
+
active = preferred
|
|
39
40
|
onready! if onready isa Function
|
|
40
41
|
|
|
41
42
|
get active
|
|
42
43
|
return languages[#active] ? #active : default
|
|
43
44
|
|
|
44
45
|
set active name
|
|
45
|
-
if languages[name]
|
|
46
|
+
if name and languages[name]
|
|
46
47
|
#active = name
|
|
47
|
-
onchange(name) if onchange isa Function
|
|
48
48
|
else
|
|
49
|
-
|
|
49
|
+
#active = languages[preferred] ? preferred : default
|
|
50
|
+
onchange(#active) if onchange isa Function
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P=Symbol.for("#__init__"),J=Symbol.for("#__initor__"),X=Symbol.for("#__inited__"),I=Symbol.for("#__hooks__"),o=Symbol.for("#__patch__"),K=Symbol.for("#has"),Y=Symbol.for("#meta"),Z=Symbol.for("imba"),M=Symbol.for("#__mixin__"),C=Symbol.for("#matcher"),c=Symbol.for("#L"),j=Symbol.for("#appendChild"),d=Symbol.for("#afterVisit"),g=Symbol.for("#beforeReconcile"),i=Symbol.for("#afterReconcile"),y=Symbol.for("##up");var H={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512},B=new Map,A=globalThis[Z]||={counter:0,classes:B};function F(h,u={}){return B.has(h)||B.set(h,{symbol:Symbol(h.name),parent:Object.getPrototypeOf(h.prototype)?.constructor,for:h,uses:null,inits:null,id:A.counter++,...u}),B.get(h)}function G(h,u){return typeof u==="string"?typeof h===u:u?.[Symbol.hasInstance]?.(h)}function D(h,u){if(!h||!u)return!1;if(h.get)return u.get===h.get;if(h.set)return u.set===h.set;if(h.value)return h.value===u.value}function L(h,u,f,n={}){let z=h.constructor;if(!f&&u){if(f=Object.getOwnPropertyDescriptors(u),delete f.constructor,f[P])console.warn(`Cannot define plain fields when extending class ${z.name}`),delete f[P]}let v=F(z);if(v&&v.augments){let R=new Map;for(let r of Object.keys(f)){let S=Object.getOwnPropertyDescriptor(h,r);for(let w of v.augments){let q=R.get(w);q||R.set(w,q={});let E=Object.getOwnPropertyDescriptor(w.prototype,r);if(E&&!D(S,E))console.warn("wont extend",r,E,S);else q[r]=f[r]}}for(let[r,S]of R)if(Object.keys(S).length)L(r.prototype,null,S)}return Object.defineProperties(h,f),h}function N(h,u){let f=F(h),n=F(u);if(n.parent){if(!(h.prototype instanceof n.parent))throw new Error(`Mixin ${u.name} has superclass not present in target class`)}if(!n.augments){n.augments=new Set;let v=n.ref=Symbol(u.name),R=Object[Symbol.hasInstance];u.prototype[v]=!0,Object.defineProperty(u,Symbol.hasInstance,{value:function(r){return this===u?r&&!!r[v]:R.call(this,r)}})}if(h.prototype[n.ref])return h;if(n.uses)for(let v of n.uses)N(h,v);n.augments.add(h),f.uses||=[],f.uses.push(u);let z=Object.getOwnPropertyDescriptors(u.prototype);if(delete z.constructor,z[P])f.inits||=[],f.inits.push(u.prototype[P]),delete z[P];if(Object.defineProperties(h.prototype,z),u?.mixed instanceof Function)u.mixed(h);return h}var T={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(h,u,...f)=>{return T.target[u].apply(T.self,f)},get:(h,u)=>{return Reflect.get(T.target,u,T.self)},set:(h,u,f,n)=>{return Reflect.set(T.target,u,f,T.self)}})};function Q(h,u,f,n,z=null){let v=Object.getPrototypeOf(h.prototype),R=n&H.HasMixins,r;if(R)B.set(h,B.get(v.constructor)),v=Object.getPrototypeOf(v);if(z){let w=n&H.IsObjectExtension?z:z.prototype,q=F(h);if(q.uses){if(z===w)console.warn("Cannot extend object with mixins");for(let E of q.uses)N(z,E)}if(n&H.HasSuperCalls)T.cache[u]=Object.create(Object.getPrototypeOf(w),Object.getOwnPropertyDescriptors(w));return L(w,h.prototype),z}let S=v?.constructor;if(r=F(h,{symbol:u}),Object.defineProperty(h,Y,{value:r,enumerable:!1,configurable:!0}),f&&h.name!==f)Object.defineProperty(h,"name",{value:f,configurable:!0});if(r.flags=n,n&H.HasConstructor)h.prototype[J]=u;if(r.uses)for(let w of r.uses)w.mixes?.(h);if(S?.inherited instanceof Function)S.inherited(h);return h}function V(h,u){if(h[J]===u)h[X]?.(),h[I]&&h[I].inited(h)}var U=Symbol.for("#active"),W=Symbol();class O{[P](h=null,u=!0,f=!0){var n;this.onready=h?h.onready:void 0,this.onerror=h?h.onerror:void 0,this.onchange=h?h.onchange:void 0,this.languages=h&&(n=h.languages)!==void 0?n:{},this.preferred=h&&(n=h.preferred)!==void 0?n:(window?.navigator?.language||"en-US").slice(0,2),this[U]=h?h[U]:void 0,this.default=h?h.default:void 0}constructor(h,u="en"){var f=this;return this[P](),this.default=u,window.fetch(h).then(function(n){return n.json()}).then(function(n){return f._finalize(n,void 0)}).catch(function(n){return f._finalize(void 0,n)}),new Proxy(this,{get:function(n,z,v){if(f[z])return Reflect.get(n,z,v);if(n.languages[z])return n.languages[z];if(n.languages[f.active]&&n.languages[f.active][z])return n.languages[f.active][z];return""}});V(this,W)}_finalize(h,u){if(u){if(G(this.onerror,Function))this.onerror("no_localization_file",u);else console.log("Localization file was not loaded",u);return}if(h)this.languages=h;if(!this.languages[this.default]){if(G(this.onerror,Function))this.onerror("no_default_localization");else console.log("There is no Localization for the default language",this.default);return}if(this.active=this.preferred,G(this.onready,Function))return this.onready()}get active(){return this.languages[this[U]]?this[U]:this.default}set active(h){if(h&&this.languages[h])this[U]=h;else this[U]=this.languages[this.preferred]?this.preferred:this.default;if(G(this.onchange,Function))this.onchange(this[U])}static{Q(this,W,"Localization",16)}}export{O as Localization};
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imba-localization",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/HeapVoid/imba-localization.git"
|
|
7
7
|
},
|
|
8
|
-
"main": "
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"module": "index.js",
|
|
10
|
+
"browser": "index.js",
|
|
9
11
|
"devDependencies": {
|
|
10
|
-
"imba": "latest"
|
|
12
|
+
"imba": "latest",
|
|
13
|
+
"bimba-cli": "latest"
|
|
11
14
|
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"bundle": "bunx bimba index.imba --outdir . --minify",
|
|
@@ -17,9 +20,6 @@
|
|
|
17
20
|
"keywords": ["imba", "theme", "localization"],
|
|
18
21
|
"license": "MIT",
|
|
19
22
|
"type": "module",
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"bimba-cli": "^0.3.2"
|
|
22
|
-
},
|
|
23
23
|
"files": [
|
|
24
24
|
"index.imba",
|
|
25
25
|
"index.js"
|