ziko-providers 0.2.0 → 0.3.0

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
@@ -4,9 +4,9 @@
4
4
 
5
5
  ## List of providers
6
6
 
7
- |Provider|Description|
8
- |`DirectionProvider`||
9
- |`ThemeProvider`||
7
+ - Direction : `DirectionProvider`
8
+ - I18N : `createI18NProvider`, `useTranslation`
9
+
10
10
 
11
11
  <!-- ## Install
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko-providers",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1 @@
1
+ export * from './use-translate.js'
@@ -0,0 +1,23 @@
1
+ import { useState } from 'ziko/hooks';
2
+
3
+ export function useTranslation(
4
+ initialLang = __Ziko__?.__PROVIDERS__?.i18n?.lang,
5
+ locals = __Ziko__.__PROVIDERS__?.i18n?.locals
6
+ ) {
7
+ const [getLang, setLang] = useState(initialLang);
8
+
9
+ setLang(initialLang)
10
+
11
+ function t(key) {
12
+ return () => ({
13
+ value : locals[getLang().value][key],
14
+ isStateGetter: () => true,
15
+ _subscribe: (fn) => {
16
+ getLang()._subscribe(() => fn(locals[getLang().value][key]));
17
+ }
18
+ });
19
+ }
20
+
21
+ return [t, setLang];
22
+ }
23
+
package/src/i18n/index.js CHANGED
@@ -1,14 +1,2 @@
1
- import { Provider } from '../provider.js';
2
- class __I18NProvider__ extends Provider{
3
- constructor(component, {lang, locals}){
4
- super(component)
5
- document.documentElement.lang = lang;
6
- if(!globalThis.__Ziko__.__PROVIDERS__) globalThis.__Ziko__.__PROVIDERS__ = {}
7
- globalThis.__Ziko__.__PROVIDERS__.i18n = {
8
- lang,
9
- locals
10
- }
11
- }
12
- }
13
-
14
- export const I18NProvider = (component, {lang, locals}) => new __I18NProvider__(component, {lang, locals});
1
+ export * from './provider.js'
2
+ export * from './hooks/index.js'
@@ -0,0 +1,7 @@
1
+ export function createI18NProvider(lang, locals){
2
+ if(!globalThis.__Ziko__.__PROVIDERS__) globalThis.__Ziko__.__PROVIDERS__ = {}
3
+ globalThis.__Ziko__.__PROVIDERS__.i18n = {
4
+ lang,
5
+ locals,
6
+ }
7
+ }
package/src/provider.js CHANGED
@@ -1,4 +1,4 @@
1
- import { UIElement } from "ziko/src/ui/index.js";
1
+ import { UIElement } from "ziko/src/ui/constructors/UIElement.js"
2
2
 
3
3
  export class Provider extends UIElement{
4
4
  constructor(component){