imba-localization 0.2.9 → 0.3.2

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 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
- - 🧩 **`<LocalizationSelector>`** - Plug and play component for switching languages
14
+ - 🧩 **`<language-selector>`** - Plug and play tag 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 { LocalizationState } from 'imba-localization'
57
+ import { Localization } from 'imba-localization'
58
58
 
59
59
  # Create an instance with the JSON URL and optional default language
60
- const loc = new LocalizationState("path/to/lang.json", "en")
60
+ const loc = new Localization("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 LocalizationState object can return following types of errors:
72
+ # The Localization 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 LocalizationState(url, default = 'en')
126
+ new Localization(url, default = 'en')
127
127
  ```
128
128
 
129
129
  - `url`: Path to your JSON localization file
@@ -148,13 +148,15 @@ new LocalizationState(url, default = 'en')
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 { LocalizationState, LocalizationSelector } from 'imba-localization'
152
- const loc = new LocalizationState("path/to/lang.json", "en")
151
+ import { Localization } from 'imba-localization'
152
+ const loc = new Localization("path/to/lang.json", "en")
153
153
 
154
- # In your UI component
154
+ # after importing Localization object
155
+ # <language-selector> tag will be available
156
+ # in any of you project your UI component
155
157
  tag AppHeader
156
158
  <self>
157
- <LocalizationSelector state=loc> # state attribute is mandatory
159
+ <language-selector state=loc> # state attribute is mandatory
158
160
  ```
159
161
 
160
162
  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):
@@ -189,8 +191,10 @@ css
189
191
  .main-arrow
190
192
  w:16px h:16px ml:auto
191
193
  fill:light-dark(#000000,#FFFFFF)
192
- scale-y:-1
193
- ead:$ease
194
+ transition: transform $ease ease
195
+ scale-y:-1
196
+ .main-arrow-active
197
+ scale-y:1
194
198
  .menu
195
199
  t:100% l:50% x:-50% mt:2px rd:8px rd:8px py:5px zi:999
196
200
  fw:500 fs:13px
@@ -206,14 +210,19 @@ css
206
210
  .menu-item-text
207
211
  fs:13px
208
212
  ```
209
- LanguageSelector can be easily customized through CSS and Imba tag (class) inheritance. Here how the above classes can be adjusted via the inheritance:
213
+ `<language-selector>` can be easily customized through CSS and Imba tag (class) inheritance. Here how the above classes can be adjusted via the inheritance, or through CSS selectors:
210
214
 
211
215
  ```imba
212
- import { LocalizationState, LocalizationSelector } from 'imba-localization'
213
- const loc = new LocalizationState("path/to/lang.json", "en")
216
+
217
+ import { Localization } from 'imba-localization'
218
+ const loc = new Localization("path/to/lang.json", "en")
219
+
220
+ # --------------------
221
+ # Inheritance
222
+ # --------------------
214
223
 
215
224
  # Create an inheritent class
216
- tag Languages < LocalizationSelector
225
+ tag custom-languages < language-selector
217
226
  css
218
227
  $ease: 1s
219
228
  .menu-item rd:2px
@@ -222,7 +231,34 @@ tag Languages < LocalizationSelector
222
231
  # Using the adjusted component
223
232
  tag MyApp
224
233
  <self>
225
- <Languages state=loc>
234
+ <custom-languages state=loc>
235
+
236
+
237
+ # --------------------
238
+ # CSS selectors
239
+ # --------------------
240
+
241
+ global css
242
+ language-selector
243
+ @not(#_) # is needed for higher precedence
244
+ .main
245
+ bgc: #992033
246
+ bd: 1px solid #992033
247
+ .main-active
248
+ bgc: blue2
249
+ bd: 1px solid #992033
250
+ .menu
251
+ bgc: #992033
252
+ bd: 1px solid #992033
253
+ .menu-item
254
+ bgc@hover: orange4
255
+ c@hover: black
256
+
257
+ # Using component that will be restyled
258
+ tag MyApp
259
+ <self>
260
+ <language-selector state=loc>
261
+
226
262
  ```
227
263
 
228
264
  #### Flag collections
@@ -230,7 +266,7 @@ tag MyApp
230
266
  You can redefine the collection of flag icons through the `icons` attribute:
231
267
 
232
268
  ```imba
233
- <LocalizationSelector icons='https://flagicons.lipis.dev/flags/4x3/##.svg'>
269
+ <language-selector icons='https://flagicons.lipis.dev/flags/4x3/##.svg'>
234
270
  ```
235
271
  There are many flag collections out there:
236
272
  - https://kapowaz.github.io/square-flags/flags/##.svg (default one)
@@ -247,13 +283,12 @@ You can use any other collection you prefer, just change the actual country code
247
283
  You can use any arrow icon you prefer (or remove it though CSS) by passing a tag of the image to the LanguageSelector `arrow` attribute:
248
284
 
249
285
  ```imba
250
- tag SomeIcon
251
- <self>
252
- <svg viewBox="..." xmlns="http://www.w3.org/2000/svg">
253
- <path d="...">
286
+ const arrow =
287
+ <svg viewBox="..." xmlns="http://www.w3.org/2000/svg">
288
+ <path d="...">
254
289
 
255
290
 
256
- <LocalizationSelector arrow=SomeIcon>
291
+ <language-selector arrow=arrow>
257
292
  ```
258
293
 
259
294
  ### ArrowIcon
@@ -261,10 +296,10 @@ tag SomeIcon
261
296
  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
297
 
263
298
  ```imba
264
- import {ArrowIcon} from 'imba-localization'
299
+ import {svg-arrow-down} from 'imba-localization'
265
300
 
266
301
  tag App
267
302
  <self>
268
- <ArrowIcon>
303
+ <{svg-arrow-down}>
269
304
  css w:20px h:20px stroke:red
270
305
  ```
package/localization.imba CHANGED
@@ -51,19 +51,15 @@ export class Localization
51
51
  window.localStorage.setItem('imba-localization', name)
52
52
  onchange(name) if onchange isa Function
53
53
 
54
- const arrow-down =
54
+ export const svg-arrow-down =
55
55
  <svg viewBox="0 0 256 256">
56
56
  <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">
57
57
 
58
- tag icon-arrow-down
59
- <self>
60
- <{arrow-down}>
61
-
62
58
  tag language-selector
63
59
  state
64
60
  icons = "https://kapowaz.github.io/square-flags/flags/##.svg"
65
61
  #dropdown = false
66
- icon-arrow = arrow-down
62
+ arrow = svg-arrow-down
67
63
 
68
64
  def onselect key
69
65
  #dropdown = false
@@ -75,8 +71,9 @@ tag language-selector
75
71
  .main-active bgc:light-dark(#000000/20, #FFFFFF/30)
76
72
  .main-flag mr:10px rd:50% w:20px h:20px
77
73
  .main-name mr:10px
78
- .main-arrow w:16px h:16px fill:light-dark(#000000,#FFFFFF) ml:auto scale-y:-1 ead:$ease
79
- .menu t:100% l:50% x:-50% zi:999 backdrop-filter:blur(20px) mt:2px rd:8px rd:8px py:5px bgc:light-dark(#000000/5, #FFFFFF/10) fw:500 fs:13px ead:$ease
74
+ .main-arrow w:16px h:16px fill:light-dark(#000000,#FFFFFF) ml:auto scale-y:-1
75
+ .main-arrow-active scale-y:1
76
+ .menu t:100% l:50% x:-50% zi:999 backdrop-filter:blur(20px) mt:2px rd:8px rd:8px py:5px bgc:light-dark(#000000/5, #FFFFFF/10) fw:500 fs:13px ead:$ease
80
77
  .menu-item d:hflex ai:center px:10px py:5px rd:8px cursor:pointer bg@hover:light-dark(#000000/10, #FFFFFF/20) m:5px
81
78
  .menu-item-icon h:20px w:20px mr:10px rd:50%
82
79
  .menu-item-text fs:13px
@@ -94,7 +91,7 @@ tag language-selector
94
91
  <div.main [pos:rel d:hcc] .main-active=#dropdown>
95
92
  <img.main-flag src=icon(state[state.active].$.flag)>
96
93
  <div.main-name> state.$.name
97
- <{icon-arrow}.main-arrow [scale-y:1]=#dropdown>
94
+ <{arrow}.main-arrow [ead:$ease] .main-arrow-active=#dropdown>
98
95
 
99
96
  if #dropdown
100
97
  <div$menu.menu [pos:abs w:100% > max-content o@off:0] ease>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imba-localization",
3
- "version": "0.2.9",
3
+ "version": "0.3.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/imba-localization.git"