imba-localization 0.1.5 → 0.1.7
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 +16 -5
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A lightweight Imba module for loading and handling JSON-based localization files
|
|
|
10
10
|
- 🧠 **Intuitive access** - Proxy-based access to translation strings
|
|
11
11
|
- 📡 **Event handling** - Support for `onready`, `onchange`, and `onerror` events
|
|
12
12
|
- 🚀 **Simple integration** - Easy to use in any Imba-based web application
|
|
13
|
-
- 🧩
|
|
13
|
+
- 🧩 **<LanguageSelector>** - Plug and play component for switching languages
|
|
14
14
|
|
|
15
15
|
## 📘 Notes
|
|
16
16
|
|
|
@@ -70,15 +70,26 @@ loc.onready = do
|
|
|
70
70
|
loc.onerror = do(error, details)
|
|
71
71
|
# The Localization object can return following types of errors:
|
|
72
72
|
# 'no_localization_file' - if there were a problem when downloading JSON file
|
|
73
|
-
# 'no_default_localization' - if there is
|
|
73
|
+
# 'no_default_localization' - if there is no localization in the file for the default language
|
|
74
74
|
# 'no_localization_key' - if there is no requiered (from the interface) key in the file
|
|
75
75
|
console.error "Localization error:", error, details
|
|
76
76
|
|
|
77
77
|
loc.onchange = do(lang_key)
|
|
78
78
|
console.log "Language changed to:", lang_key
|
|
79
79
|
|
|
80
|
-
#
|
|
80
|
+
# Get the current localization code
|
|
81
|
+
console.log loc.active
|
|
82
|
+
|
|
83
|
+
# Switch the active language
|
|
81
84
|
loc.active = "fr" # Changes to French if available
|
|
85
|
+
|
|
86
|
+
# Loop through all the localizations
|
|
87
|
+
for key, data of loc.languages
|
|
88
|
+
console.log key, data
|
|
89
|
+
|
|
90
|
+
# Get all the keys for the active language
|
|
91
|
+
console.log loc.languages[loc.active]
|
|
92
|
+
|
|
82
93
|
```
|
|
83
94
|
|
|
84
95
|
## 📄 JSON Structure
|
|
@@ -119,7 +130,7 @@ new Localization(url, default = 'en')
|
|
|
119
130
|
|
|
120
131
|
### Properties
|
|
121
132
|
|
|
122
|
-
- `active`: Get or set the active language
|
|
133
|
+
- `active`: Get or set the code of the active language
|
|
123
134
|
- `languages`: Object containing all loaded language data
|
|
124
135
|
- `preferred`: Detected browser language (first 2 characters of `navigator.language`)
|
|
125
136
|
|
|
@@ -247,7 +258,7 @@ tag SomeIcon
|
|
|
247
258
|
|
|
248
259
|
### ArrowIcon
|
|
249
260
|
|
|
250
|
-
|
|
261
|
+
The default arrow icon used in the LanguageSelector component is available as a separate icon (in case for some reason you don't want to use [imba-phosphor-icons](https://www.npmjs.com/package/imba-phosphor-icons) package by Sindre).
|
|
251
262
|
|
|
252
263
|
```imba
|
|
253
264
|
import {ArrowIcon} from 'imba-localization/components'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imba-localization",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/HeapVoid/imba-localization.git"
|
|
@@ -25,5 +25,12 @@
|
|
|
25
25
|
"index.js",
|
|
26
26
|
"components.imba",
|
|
27
27
|
"components.d.ts"
|
|
28
|
-
]
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./index.js",
|
|
31
|
+
"./components": {
|
|
32
|
+
"import": "./components.imba",
|
|
33
|
+
"types": "./components.d.ts"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
29
36
|
}
|