imba-localization 0.2.4 → 0.2.6
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 +15 -15
- package/localization.imba +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ A lightweight Imba module for loading and handling JSON-based localization files
|
|
|
11
11
|
- 🧠 **Intuitive access** - Proxy-based access to translation strings
|
|
12
12
|
- 📡 **Event handling** - Support for `onready`, `onchange`, and `onerror` events
|
|
13
13
|
- 🚀 **Simple integration** - Easy to use in any Imba-based web application
|
|
14
|
-
- 🧩 **`<
|
|
14
|
+
- 🧩 **`<LocalizationSelector>`** - Plug and play component for switching languages
|
|
15
15
|
|
|
16
16
|
## 📘 Notes
|
|
17
17
|
|
|
@@ -54,10 +54,10 @@ Add this to your HTML head to load the localization file simultaneously with you
|
|
|
54
54
|
|
|
55
55
|
```imba
|
|
56
56
|
# app.imba
|
|
57
|
-
import {
|
|
57
|
+
import { LocalizationState } from 'imba-localization'
|
|
58
58
|
|
|
59
59
|
# Create an instance with the JSON URL and optional default language
|
|
60
|
-
const loc = new
|
|
60
|
+
const loc = new LocalizationState("path/to/lang.json", "en")
|
|
61
61
|
|
|
62
62
|
# Set up event handlers
|
|
63
63
|
loc.onready = do
|
|
@@ -69,7 +69,7 @@ loc.onready = do
|
|
|
69
69
|
console.log loc['user']['profile'] # Accessing nested properties
|
|
70
70
|
|
|
71
71
|
loc.onerror = do(error, details)
|
|
72
|
-
# The
|
|
72
|
+
# The LocalizationState object can return following types of errors:
|
|
73
73
|
# 'no_localization_file' - if there were a problem when downloading JSON file
|
|
74
74
|
# 'no_default_localization' - if there is no localization in the file for the default language
|
|
75
75
|
# 'no_localization_key' - if there is no requiered (from the interface) key in the file
|
|
@@ -123,7 +123,7 @@ Your localization file should follow this format:
|
|
|
123
123
|
### Constructor
|
|
124
124
|
|
|
125
125
|
```imba
|
|
126
|
-
new
|
|
126
|
+
new LocalizationState(url, default = 'en')
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
- `url`: Path to your JSON localization file
|
|
@@ -143,18 +143,18 @@ new Localization(url, default = 'en')
|
|
|
143
143
|
|
|
144
144
|
## 🧩 Components
|
|
145
145
|
|
|
146
|
-
###
|
|
146
|
+
### LocalizationSelector
|
|
147
147
|
|
|
148
148
|
A customizable dropdown component that allows users to select from available in the JSON localization file languages.
|
|
149
149
|
|
|
150
150
|
```imba
|
|
151
|
-
import {
|
|
152
|
-
const loc = new
|
|
151
|
+
import { LocalizationState, LocalizationSelector } from 'imba-localization'
|
|
152
|
+
const loc = new LocalizationState("path/to/lang.json", "en")
|
|
153
153
|
|
|
154
154
|
# In your UI component
|
|
155
155
|
tag AppHeader
|
|
156
156
|
<self>
|
|
157
|
-
<
|
|
157
|
+
<LocalizationSelector state=loc> # state attribute is mandatory
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
To make this component work as intended, your JSON file will need some adjustments. For each supported language you will need to define the display name for the language and also the country code for the flag to show (for example `en` language is used in `gb` and `us` countries):
|
|
@@ -209,11 +209,11 @@ css
|
|
|
209
209
|
LanguageSelector can be easily customized through CSS and Imba tag (class) inheritance. Here how the above classes can be adjusted via the inheritance:
|
|
210
210
|
|
|
211
211
|
```imba
|
|
212
|
-
import {
|
|
213
|
-
const loc = new
|
|
212
|
+
import { LocalizationState, LocalizationSelector } from 'imba-localization'
|
|
213
|
+
const loc = new LocalizationState("path/to/lang.json", "en")
|
|
214
214
|
|
|
215
215
|
# Create an inheritent class
|
|
216
|
-
tag Languages <
|
|
216
|
+
tag Languages < LocalizationSelector
|
|
217
217
|
css
|
|
218
218
|
$ease: 1s
|
|
219
219
|
.menu-item rd:2px
|
|
@@ -230,7 +230,7 @@ tag MyApp
|
|
|
230
230
|
You can redefine the collection of flag icons through the `icons` attribute:
|
|
231
231
|
|
|
232
232
|
```imba
|
|
233
|
-
<
|
|
233
|
+
<LocalizationSelector icons='https://flagicons.lipis.dev/flags/4x3/##.svg'>
|
|
234
234
|
```
|
|
235
235
|
There are many flag collections out there:
|
|
236
236
|
- https://kapowaz.github.io/square-flags/flags/##.svg (default one)
|
|
@@ -253,12 +253,12 @@ tag SomeIcon
|
|
|
253
253
|
<path d="...">
|
|
254
254
|
|
|
255
255
|
|
|
256
|
-
<
|
|
256
|
+
<LocalizationSelector arrow=SomeIcon>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
### ArrowIcon
|
|
260
260
|
|
|
261
|
-
The default arrow icon used in the
|
|
261
|
+
The default arrow icon used in the LocalizationSelector 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).
|
|
262
262
|
|
|
263
263
|
```imba
|
|
264
264
|
import {ArrowIcon} from 'imba-localization'
|
package/localization.imba
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class LocalizationState
|
|
2
2
|
onready
|
|
3
3
|
onerror
|
|
4
4
|
onchange
|
|
@@ -56,7 +56,7 @@ export tag ArrowIcon
|
|
|
56
56
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
|
|
57
57
|
<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">
|
|
58
58
|
|
|
59
|
-
export tag
|
|
59
|
+
export tag LocalizationSelector
|
|
60
60
|
state
|
|
61
61
|
icons = "https://kapowaz.github.io/square-flags/flags/##.svg"
|
|
62
62
|
#dropdown = false
|