imba-localization 0.0.8 β 0.0.9
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 +3 -3
- package/package/index.js +1 -0
- package/package.json +12 -3
- /package/{index.imba β package/index.imba} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
# Localization
|
|
2
|
+
# JSON Localization for Imba
|
|
3
3
|
|
|
4
4
|
A lightweight Imba module for loading and handling JSON-based localization files in web applications. This utility fetches a localization file, selects the appropriate language based on the user's browser settings (or falls back to a default), and allows you to easily access localized strings throughout your application.
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@ A lightweight Imba module for loading and handling JSON-based localization files
|
|
|
15
15
|
|
|
16
16
|
Just include the module in your project or copy the class directly into your codebase.
|
|
17
17
|
```bash
|
|
18
|
-
npm install imba-localization
|
|
18
|
+
npm install imba-localization
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## π Usage
|
|
@@ -40,7 +40,7 @@ Hereβs an example of how to use it in an Imba app:
|
|
|
40
40
|
```imba
|
|
41
41
|
# app.imba
|
|
42
42
|
|
|
43
|
-
import Localization from 'imba-localization
|
|
43
|
+
import Localization from 'imba-localization'
|
|
44
44
|
|
|
45
45
|
# To create an instance pass the address to the JSON and (optionally) default language
|
|
46
46
|
const loc = new Localization("ADDRESS_TO_JSON", "en")
|
package/package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var S=Symbol.for("#__init__"),H=Symbol.for("#__initor__"),X=Symbol.for("#__inited__"),G=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 F={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512},T=new Map,A=globalThis[Z]||={counter:0,classes:T};function B(h,n={}){return T.has(h)||T.set(h,{symbol:Symbol(h.name),parent:Object.getPrototypeOf(h.prototype)?.constructor,for:h,uses:null,inits:null,id:A.counter++,...n}),T.get(h)}function E(h,n){return typeof n==="string"?typeof h===n:n?.[Symbol.hasInstance]?.(h)}function D(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 I(h,n,f,u={}){let z=h.constructor;if(!f&&n){if(f=Object.getOwnPropertyDescriptors(n),delete f.constructor,f[S])console.warn(`Cannot define plain fields when extending class ${z.name}`),delete f[S]}let r=B(z);if(r&&r.augments){let L=new Map;for(let o of Object.keys(f)){let v=Object.getOwnPropertyDescriptor(h,o);for(let w of r.augments){let R=L.get(w);R||L.set(w,R={});let q=Object.getOwnPropertyDescriptor(w.prototype,o);if(q&&!D(v,q))console.warn("wont extend",o,q,v);else R[o]=f[o]}}for(let[o,v]of L)if(Object.keys(v).length)I(o.prototype,null,v)}return Object.defineProperties(h,f),h}function J(h,n){let f=B(h),u=B(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 r=u.ref=Symbol(n.name),L=Object[Symbol.hasInstance];n.prototype[r]=!0,Object.defineProperty(n,Symbol.hasInstance,{value:function(o){return this===n?o&&!!o[r]:L.call(this,o)}})}if(h.prototype[u.ref])return h;if(u.uses)for(let r of u.uses)J(h,r);u.augments.add(h),f.uses||=[],f.uses.push(n);let z=Object.getOwnPropertyDescriptors(n.prototype);if(delete z.constructor,z[S])f.inits||=[],f.inits.push(n.prototype[S]),delete z[S];if(Object.defineProperties(h.prototype,z),n?.mixed instanceof Function)n.mixed(h);return h}var P={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(h,n,...f)=>{return P.target[n].apply(P.self,f)},get:(h,n)=>{return Reflect.get(P.target,n,P.self)},set:(h,n,f,u)=>{return Reflect.set(P.target,n,f,P.self)}})};function N(h,n,f,u,z=null){let r=Object.getPrototypeOf(h.prototype),L=u&F.HasMixins,o;if(L)T.set(h,T.get(r.constructor)),r=Object.getPrototypeOf(r);if(z){let w=u&F.IsObjectExtension?z:z.prototype,R=B(h);if(R.uses){if(z===w)console.warn("Cannot extend object with mixins");for(let q of R.uses)J(z,q)}if(u&F.HasSuperCalls)P.cache[n]=Object.create(Object.getPrototypeOf(w),Object.getOwnPropertyDescriptors(w));return I(w,h.prototype),z}let v=r?.constructor;if(o=B(h,{symbol:n}),Object.defineProperty(h,Y,{value:o,enumerable:!1,configurable:!0}),f&&h.name!==f)Object.defineProperty(h,"name",{value:f,configurable:!0});if(o.flags=u,u&F.HasConstructor)h.prototype[H]=n;if(o.uses)for(let w of o.uses)w.mixes?.(h);if(v?.inherited instanceof Function)v.inherited(h);return h}function Q(h,n){if(h[H]===n)h[X]?.(),h[G]&&h[G].inited(h)}var U=Symbol.for("#active"),V=Symbol();class W{[S](h=null,n=!0,f=!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[U]=h?h[U]:void 0,this.default=h?h.default:void 0}constructor(h,n="en"){var f=this;return this[S](),this.default=n,window.fetch(h).then(function(u){return u.json()}).then(function(u){return f._finalize(u,void 0)}).catch(function(u){return f._finalize(void 0,u)}),new Proxy(this,{get:function(u,z,r){if(f[z])return Reflect.get(u,z,r);if(u.languages[f.active]&&u.languages[f.active][z])return u.languages[f.active][z];return""}});Q(this,V)}_finalize(h,n){if(n){if(E(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(E(this.onerror,Function))this.onerror("no_default_localization");else console.log("There is no Localization for the default language",this.default);return}if(this[U]=this.languages[this.preferred]?this.preferred:this.default,E(this.onready,Function))return this.onready()}get active(){return this.languages[this[U]]?this[U]:this.default}set active(h){if(this.languages[h]){if(this[U]=h,E(this.onchange,Function))this.onchange(h)}else console.log("Localization for the language not found",h)}static{N(this,V,"Localization",16)}}export{W as default};
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imba-localization",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/HeapVoid/imba-localization.git"
|
|
7
7
|
},
|
|
8
|
-
"main": "./index.
|
|
8
|
+
"main": "./index.js",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"imba": "latest"
|
|
11
11
|
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"bundle": "bunx bimba ./package/index.imba --outdir ./package --minify"
|
|
14
|
+
},
|
|
12
15
|
"description": "A class to make using language localizations in Imba easier.",
|
|
13
16
|
"keywords": ["imba", "theme", "localization"],
|
|
14
17
|
"license": "MIT",
|
|
15
|
-
"type": "module"
|
|
18
|
+
"type": "module",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"bimba-cli": "^0.3.2"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"package"
|
|
24
|
+
]
|
|
16
25
|
}
|
|
File without changes
|