jb-core 0.16.1 → 0.17.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 +4 -0
- package/i18n/README.md +30 -0
- package/i18n/dist/dictionary.d.ts +3 -0
- package/i18n/dist/dictionary.d.ts.map +1 -0
- package/i18n/dist/i18n.d.ts +11 -0
- package/i18n/dist/i18n.d.ts.map +1 -0
- package/i18n/dist/index.cjs.js +2 -0
- package/i18n/dist/index.cjs.js.br +0 -0
- package/i18n/dist/index.cjs.js.gz +0 -0
- package/i18n/dist/index.cjs.js.map +1 -0
- package/i18n/dist/index.d.ts +3 -0
- package/i18n/dist/index.d.ts.map +1 -0
- package/i18n/dist/index.js +2 -0
- package/i18n/dist/index.js.br +0 -0
- package/i18n/dist/index.js.gz +0 -0
- package/i18n/dist/index.js.map +1 -0
- package/i18n/dist/index.umd.js +2 -0
- package/i18n/dist/index.umd.js.br +0 -0
- package/i18n/dist/index.umd.js.gz +0 -0
- package/i18n/dist/index.umd.js.map +1 -0
- package/i18n/lib/dictionary.ts +11 -0
- package/i18n/lib/i18n.ts +31 -0
- package/i18n/lib/index.ts +2 -0
- package/i18n/package.json +6 -0
- package/i18n/tsconfig.json +17 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -7,6 +7,10 @@ core modules of jb-design system mostly contain functions that help you manage y
|
|
|
7
7
|
|
|
8
8
|
to see react modules please see [`jb-core/react`](https://github.com/javadbat/jb-core/tree/main/react)
|
|
9
9
|
|
|
10
|
+
## I18N modules
|
|
11
|
+
|
|
12
|
+
to see i18n modules please see [`jb-core/i18n`](https://github.com/javadbat/jb-core/tree/main/i18n)
|
|
13
|
+
|
|
10
14
|
## listenAndSilentEvent
|
|
11
15
|
|
|
12
16
|
this function listen to event in the capture phase and stop it's propagation and call your handler so you will be the only one who capture this event used for event forwarding (transformation) in web-components.
|
package/i18n/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# JB I18N Module
|
|
2
|
+
|
|
3
|
+
## config file
|
|
4
|
+
JB Design System use html tag `lang` attribute to set the default language of it's components.
|
|
5
|
+
```html
|
|
6
|
+
<html lang="fa">
|
|
7
|
+
<!-- or -->
|
|
8
|
+
<html lang="en">
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
if you want to set your locale manually in javascript you just have to import `i18n` and set your default locale:
|
|
12
|
+
```ts
|
|
13
|
+
import {i18n} from 'jb-core/i18n';
|
|
14
|
+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale for more setting detail
|
|
15
|
+
i18n.setLocale(new Intl.Locale("fa"))
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## internal methods
|
|
19
|
+
|
|
20
|
+
this methods are internal methods and intended to be used inside jb design system modules but you can also use them if you are creating modules
|
|
21
|
+
|
|
22
|
+
### getRequiredMessage
|
|
23
|
+
used to get error message of required filed base on their label
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
getRequiredMessage(context:JBI18N,label?:string)
|
|
27
|
+
//example
|
|
28
|
+
import {i18n,getRequiredMessage} from 'jb-core/i18n';
|
|
29
|
+
getRequiredMessage(i18n,"your label");
|
|
30
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../lib/dictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,wBAAgB,kBAAkB,CAAC,OAAO,EAAC,MAAM,EAAC,KAAK,CAAC,EAAC,MAAM,UAQ9D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
this is the core module of i18n in jb design system its is just a main store for keeping data and change config.
|
|
3
|
+
every helper method will implement as an independent functions and class, so modules only use instance of an this class as a input to each used function
|
|
4
|
+
*/
|
|
5
|
+
export declare class JBI18N {
|
|
6
|
+
locale: Intl.Locale;
|
|
7
|
+
constructor();
|
|
8
|
+
setLocale(locale: Intl.Locale): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const i18n: JBI18N;
|
|
11
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../lib/i18n.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,qBAAa,MAAM;IACjB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;;IAoBnB,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM;CAG9B;AAED,eAAO,MAAM,IAAI,QAAe,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{constructor(){if("fa"===(document?.documentElement?.lang||"en"))this.locale=new Intl.Locale("fa",{calendar:"persian",region:"US"});else this.locale=new Intl.Locale("en",{calendar:"gregory",region:"US"})}setLocale(e){this.locale=e}};const l=new e;exports.JBI18N=e,exports.getRequiredMessage=function(e,l){return"fa"===e.locale.language?l?`لطفاً ${l} خود را وارد نمایید`:"لطفاً این قسمت را پر کنید":l?`Please enter your ${l}`:"Please complete this field"},exports.i18n=l;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","names":[],"sources":["../lib/i18n.ts","../lib/dictionary.ts"],"sourcesContent":[],"mappings":"AAIA,IAAa,EAAb,MAEE,WAAA,GAEE,GACO,QAFM,UAAU,iBAAiB,MAAQ,MAG5C,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,YAKV,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,MAKf,CACD,SAAA,CAAU,GACR,KAAK,OAAS,CACf,GAGH,MAAa,EAAO,IAAI,8CC5BxB,SAAmC,EAAe,GAChD,MACO,OADA,EAAQ,OAAO,SAEX,EAAA,SAAe,uBAA2B,4BAG1C,EAAA,qBAA2B,IAAQ,4BAE/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{constructor(){if("fa"===(document?.documentElement?.lang||"en"))this.locale=new Intl.Locale("fa",{calendar:"persian",region:"US"});else this.locale=new Intl.Locale("en",{calendar:"gregory",region:"US"})}setLocale(e){this.locale=e}};const l=new e;function n(e,l){return"fa"===e.locale.language?l?`لطفاً ${l} خود را وارد نمایید`:"لطفاً این قسمت را پر کنید":l?`Please enter your ${l}`:"Please complete this field"}export{e as JBI18N,n as getRequiredMessage,l as i18n};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../lib/i18n.ts","../lib/dictionary.ts"],"sourcesContent":[],"mappings":"AAIA,IAAa,EAAb,MAEE,WAAA,GAEE,GACO,QAFM,UAAU,iBAAiB,MAAQ,MAG5C,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,YAKV,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,MAKf,CACD,SAAA,CAAU,GACR,KAAK,OAAS,CACf,GAGH,MAAa,EAAO,IAAI,EC5BxB,SAAgB,EAAmB,EAAe,GAChD,MACO,OADA,EAAQ,OAAO,SAEX,EAAA,SAAe,uBAA2B,4BAG1C,EAAA,qBAA2B,IAAQ,4BAE/C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).JBCoreI18N={})}(this,(function(e){var n=class{constructor(){if("fa"===(document?.documentElement?.lang||"en"))this.locale=new Intl.Locale("fa",{calendar:"persian",region:"US"});else this.locale=new Intl.Locale("en",{calendar:"gregory",region:"US"})}setLocale(e){this.locale=e}};const o=new n;e.JBI18N=n,e.getRequiredMessage=function(e,n){return"fa"===e.locale.language?n?`لطفاً ${n} خود را وارد نمایید`:"لطفاً این قسمت را پر کنید":n?`Please enter your ${n}`:"Please complete this field"},e.i18n=o}));
|
|
2
|
+
//# sourceMappingURL=index.umd.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","names":[],"sources":["../lib/i18n.ts","../lib/dictionary.ts"],"sourcesContent":[],"mappings":"qOAIA,IAAa,EAAb,MAEE,WAAA,GAEE,GACO,QAFM,UAAU,iBAAiB,MAAQ,MAG5C,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,YAKV,KAAK,OAAS,IAAI,KAAK,OAAO,KAAM,CAClC,SAAU,UACV,OAAQ,MAKf,CACD,SAAA,CAAU,GACR,KAAK,OAAS,CACf,GAGH,MAAa,EAAO,IAAI,kCC5BxB,SAAmC,EAAe,GAChD,MACO,OADA,EAAQ,OAAO,SAEX,EAAA,SAAe,uBAA2B,4BAG1C,EAAA,qBAA2B,IAAQ,4BAE/C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { JBI18N } from "./i18n";
|
|
2
|
+
|
|
3
|
+
export function getRequiredMessage(context:JBI18N,label?:string){
|
|
4
|
+
switch(context.locale.language){
|
|
5
|
+
case 'fa':
|
|
6
|
+
return label?`لطفاً ${label} خود را وارد نمایید`:'لطفاً این قسمت را پر کنید';
|
|
7
|
+
case 'en':
|
|
8
|
+
default:
|
|
9
|
+
return label?`Please enter your ${label}`:'Please complete this field';
|
|
10
|
+
}
|
|
11
|
+
}
|
package/i18n/lib/i18n.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
this is the core module of i18n in jb design system its is just a main store for keeping data and change config.
|
|
3
|
+
every helper method will implement as an independent functions and class, so modules only use instance of an this class as a input to each used function
|
|
4
|
+
*/
|
|
5
|
+
export class JBI18N {
|
|
6
|
+
locale: Intl.Locale
|
|
7
|
+
constructor() {
|
|
8
|
+
const lang = document?.documentElement?.lang || "en"
|
|
9
|
+
switch (lang) {
|
|
10
|
+
case "fa":
|
|
11
|
+
this.locale = new Intl.Locale("fa", {
|
|
12
|
+
calendar: "persian",
|
|
13
|
+
region: "US",
|
|
14
|
+
})
|
|
15
|
+
break;
|
|
16
|
+
case "en":
|
|
17
|
+
default:
|
|
18
|
+
this.locale = new Intl.Locale("en", {
|
|
19
|
+
calendar: "gregory",
|
|
20
|
+
region: "US",
|
|
21
|
+
});
|
|
22
|
+
break;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
setLocale(locale: Intl.Locale) {
|
|
27
|
+
this.locale = locale;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const i18n = new JBI18N();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"rootDir": "./lib",
|
|
5
|
+
"declarationDir": "./dist",
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"lib/**/*.ts",
|
|
9
|
+
],
|
|
10
|
+
"exclude": [
|
|
11
|
+
"stories",
|
|
12
|
+
"node_modules",
|
|
13
|
+
"**/*.spec.ts",
|
|
14
|
+
"dist",
|
|
15
|
+
],
|
|
16
|
+
"extends":"../configs/tsconfig-web-component.json"
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"theme",
|
|
16
16
|
"event"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.17.0",
|
|
19
19
|
"bugs": "https://github.com/javadbat/jb-core/issues",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"files": [
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"styles/",
|
|
27
27
|
"configs/",
|
|
28
28
|
"theme/",
|
|
29
|
+
"i18n/",
|
|
29
30
|
"react/",
|
|
30
31
|
"react/dist/"
|
|
31
32
|
],
|