imba-localization 0.3.7 → 0.3.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.
Files changed (2) hide show
  1. package/localization.imba +13 -2
  2. package/package.json +1 -1
package/localization.imba CHANGED
@@ -5,6 +5,8 @@ export class Localization
5
5
  languages = {}
6
6
  preferred = (window..navigator..language || 'en-US').slice(0, 2)
7
7
  default
8
+ ready = false
9
+ errors = {}
8
10
 
9
11
  def constructor url, dft = 'en'
10
12
  default = dft
@@ -15,10 +17,16 @@ export class Localization
15
17
 
16
18
  return new Proxy self, {
17
19
  get: do(target, p, receiver)
18
- return Reflect.get(target, p, receiver) if self[p]
20
+ return Reflect.get(target, p, receiver) if self[p] !== undefined
21
+ if !ready
22
+ console.log("Request before localization is ready:", p)
23
+ return
24
+ return if errors[p]
19
25
  return target.languages[p] if target.languages[p]
20
26
  return target.languages[active][p] if target.languages[active] and target.languages[active][p]
21
- onerror('no_localization_key', p) if onerror isa Function
27
+ if !errors[p]
28
+ onerror('no_localization_key', p) if onerror isa Function
29
+ errors[p] = true
22
30
  return ''
23
31
  }
24
32
 
@@ -36,6 +44,8 @@ export class Localization
36
44
  else
37
45
  console.log('There is no Localization for the default language', default)
38
46
  return
47
+ ready = true
48
+ errors = {}
39
49
  onready! if onready isa Function
40
50
  onchange(active) if onchange isa Function
41
51
 
@@ -50,6 +60,7 @@ export class Localization
50
60
  if window.localStorage.getItem('imba-localization') != name
51
61
  window.localStorage.setItem('imba-localization', name)
52
62
  onchange(name) if onchange isa Function
63
+ errors = {}
53
64
 
54
65
  export const path-arrow-down = <path d="M213.66,165.66a8,8,0,0,1-11.32,0L128,91.31,53.66,165.66a8,8,0,0,1-11.32-11.32l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,213.66,165.66Z">
55
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imba-localization",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/imba-localization.git"