@ckbox/i18n 1.1.1-dev.0 → 1.2.0-dev.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 +3 -3
- package/dist/context/I18nContext.d.ts +25 -0
- package/dist/context/I18nProvider.d.ts +13 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/types.d.ts +33 -0
- package/dist/index.d.ts +0 -8
- package/dist/index.js +1 -1
- package/dist/plural/Plural.d.ts +19 -0
- package/dist/plural/index.d.ts +1 -0
- package/dist/utils/getMsg.d.ts +35 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/useTranslation.d.ts +29 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Using a build served from the CDN is the simplest and fastest way of embedding C
|
|
|
13
13
|
To start using CKBox on your website, embed the following `script` element in the HTML code of the page:
|
|
14
14
|
|
|
15
15
|
```html
|
|
16
|
-
<script src="https://cdn.ckbox.io/CKBox/1.
|
|
16
|
+
<script src="https://cdn.ckbox.io/CKBox/1.2.0-dev.0/ckbox.js"></script>
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Quick implementation example:
|
|
@@ -22,7 +22,7 @@ Quick implementation example:
|
|
|
22
22
|
<html>
|
|
23
23
|
<head>
|
|
24
24
|
<meta charset="UTF-8" />
|
|
25
|
-
<script src="https://cdn.ckbox.io/CKBox/1.
|
|
25
|
+
<script src="https://cdn.ckbox.io/CKBox/1.2.0-dev.0/ckbox.js"></script>
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
|
28
28
|
<div id="ckbox"></div>
|
|
@@ -47,7 +47,7 @@ The code snippet below presents the simplest scenario for integration of CKEdito
|
|
|
47
47
|
<head>
|
|
48
48
|
<meta charset="UTF-8" />
|
|
49
49
|
<script src="https://cdn.ckeditor.com/ckeditor5/34.2.0/classic/ckeditor.js"></script>
|
|
50
|
-
<script src="https://cdn.ckbox.io/CKBox/1.
|
|
50
|
+
<script src="https://cdn.ckbox.io/CKBox/1.2.0-dev.0/ckbox.js"></script>
|
|
51
51
|
</head>
|
|
52
52
|
<body>
|
|
53
53
|
<div id="editor"></div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Plural } from '../plural';
|
|
3
|
+
import { I18nResources } from './types';
|
|
4
|
+
export interface I18nContext {
|
|
5
|
+
/**
|
|
6
|
+
* Debug mode.
|
|
7
|
+
*/
|
|
8
|
+
debug: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Currently selected language.
|
|
11
|
+
*/
|
|
12
|
+
lang: string;
|
|
13
|
+
/**
|
|
14
|
+
* Stored translations.
|
|
15
|
+
*/
|
|
16
|
+
resources: I18nResources;
|
|
17
|
+
/**
|
|
18
|
+
* Plural utils.
|
|
19
|
+
*/
|
|
20
|
+
pluralUtils: Plural;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Defines React context for i18n and sets defaults.
|
|
24
|
+
*/
|
|
25
|
+
export declare const I18nContext: React.Context<I18nContext>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { I18nProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* `I18nProvider` component sets i18n context for all child components.
|
|
5
|
+
*/
|
|
6
|
+
declare const I18nProvider: React.FC<Props>;
|
|
7
|
+
interface Props extends I18nProps {
|
|
8
|
+
/**
|
|
9
|
+
* Pass-through children.
|
|
10
|
+
*/
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export default I18nProvider;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines shape of all translation resources, e.g.:
|
|
3
|
+
* {
|
|
4
|
+
* en: {
|
|
5
|
+
* key: "translation"
|
|
6
|
+
* },
|
|
7
|
+
* pl: {
|
|
8
|
+
* key: "tłumaczenie"
|
|
9
|
+
* }
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export declare type I18nResources = Record<string, I18nTranslations>;
|
|
13
|
+
/**
|
|
14
|
+
* Defines shape of translations for a language, e.g.:
|
|
15
|
+
* {
|
|
16
|
+
* key: "translation"
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare type I18nTranslations = Record<string, string>;
|
|
20
|
+
export interface I18nProps {
|
|
21
|
+
/**
|
|
22
|
+
* Toggles debug mode.
|
|
23
|
+
*/
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Language code.
|
|
27
|
+
*/
|
|
28
|
+
lang?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Translation resources that will be set synchronously. Resources for other languages can be still loaded on demand.
|
|
31
|
+
*/
|
|
32
|
+
resources?: I18nResources;
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,10 +27,6 @@ interface I18nProps {
|
|
|
27
27
|
* Toggles debug mode.
|
|
28
28
|
*/
|
|
29
29
|
debug?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Endpoint from which translation files will be loaded.
|
|
32
|
-
*/
|
|
33
|
-
loadURL?: (lang: string) => string;
|
|
34
30
|
/**
|
|
35
31
|
* Language code.
|
|
36
32
|
*/
|
|
@@ -62,10 +58,6 @@ declare class Plural {
|
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
interface I18nContext {
|
|
65
|
-
/**
|
|
66
|
-
* Switch language.
|
|
67
|
-
*/
|
|
68
|
-
changeLang: (lang: string) => void;
|
|
69
61
|
/**
|
|
70
62
|
* Debug mode.
|
|
71
63
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
const
|
|
4
|
+
const _0xc509eb=_0x5aca;(function(_0x545fcf,_0x2cc1fb){const _0x2d696a=_0x5aca,_0x13ae17=_0x545fcf();while(!![]){try{const _0x153039=-parseInt(_0x2d696a(0x178))/0x1+-parseInt(_0x2d696a(0x16a))/0x2*(-parseInt(_0x2d696a(0x181))/0x3)+parseInt(_0x2d696a(0x16b))/0x4*(-parseInt(_0x2d696a(0x164))/0x5)+-parseInt(_0x2d696a(0x16c))/0x6+-parseInt(_0x2d696a(0x165))/0x7*(parseInt(_0x2d696a(0x16e))/0x8)+-parseInt(_0x2d696a(0x188))/0x9+parseInt(_0x2d696a(0x166))/0xa;if(_0x153039===_0x2cc1fb)break;else _0x13ae17['push'](_0x13ae17['shift']());}catch(_0x2746d5){_0x13ae17['push'](_0x13ae17['shift']());}}}(_0x48a5,0x6f117));import*as _0x312476 from'react';import{sprintf}from'sprintf-js';class Plural{constructor(_0x2c593c){const _0x203a45=_0x5aca;this[_0x203a45(0x16f)]=_0x2c593c;try{this['_rules']=new Intl[(_0x203a45(0x16d))](_0x2c593c);}catch(_0x4a94a2){console['warn']('Plural\x20rules\x20could\x20not\x20be\x20created.\x20Perhaps\x20`Intl.PluralRules`\x20is\x20not\x20supported?');}}['getKey'](_0x349a97,_0x294413){const _0x47cae7=_0x5aca;if(!this[_0x47cae7(0x173)])return _0x349a97+_0x47cae7(0x167);const _0x2f838f=this['_rules'][_0x47cae7(0x182)](_0x294413);return _0x349a97+'_'+_0x2f838f;}}function _0x5aca(_0x63a24,_0x5bcf67){const _0x48a5fe=_0x48a5();return _0x5aca=function(_0x5aca79,_0x59fa95){_0x5aca79=_0x5aca79-0x164;let _0x4da73e=_0x48a5fe[_0x5aca79];return _0x4da73e;},_0x5aca(_0x63a24,_0x5bcf67);}Plural[_0xc509eb(0x17e)]=_0x53afa6=>{const _0xb46949=_0xc509eb;try{return Intl[_0xb46949(0x16d)][_0xb46949(0x176)]([_0x53afa6])['length']>0x0;}catch(_0x44b0ad){return![];}};const I18nContext=_0x312476[_0xc509eb(0x17b)]({'debug':![],'lang':'en','resources':{},'pluralUtils':new Plural('en')}),I18nProvider=({children:_0x39487d,debug:debug=![],lang:lang='en',resources:resources={}})=>{const _0x4406f1=_0xc509eb;return _0x312476[_0x4406f1(0x184)](()=>{const _0x50b080=_0x4406f1,_0x48f1cd=Plural[_0x50b080(0x17e)](lang);!_0x48f1cd&&console[_0x50b080(0x174)](_0x50b080(0x17f)+lang+_0x50b080(0x171));},[lang]),_0x312476[_0x4406f1(0x186)](I18nContext['Provider'],{'value':{'debug':debug,'lang':lang,'pluralUtils':new Plural(lang),'resources':resources}},_0x39487d);},TAG_REGEX=/<[a-zA-Z0-9\-!/](?:"[^"]*"|'[^']*'|[^'">])*>/g,ALLOWED_TAGS=['em',_0xc509eb(0x169),'code'],getMsg=(_0x34356b,_0x21223f={},_0x4b550b)=>{const _0x229786=_0xc509eb,_0x2c49c5=_0x4b550b[_0x229786(0x172)];if(_0x21223f[_0x34356b]&&_0x2c49c5===undefined)return{'found':!![],'msg':_0x21223f[_0x34356b]};const _0x45c38f=Object['keys'](_0x21223f)[_0x229786(0x180)](_0x1bf73a=>_0x1bf73a['indexOf'](_0x34356b)===0x0);if(_0x45c38f[_0x229786(0x17d)]===0x0||_0x2c49c5===undefined)return{'found':![],'msg':_0x34356b};const _0x42c833=_0x4b550b[_0x229786(0x168)][_0x229786(0x185)](_0x34356b,_0x2c49c5);return{'found':!![],'msg':_0x21223f[_0x42c833]};},parseMsgTags=_0x8fc869=>{const _0x1eaf4c=_0xc509eb,_0xbaa1dc=[];let _0xfdfb40=0x0,_0x97cfd3;while((_0x97cfd3=TAG_REGEX[_0x1eaf4c(0x177)](_0x8fc869))!==null){const _0x3e8e04=_0x97cfd3[0x0],{index:_0x50071f}=_0x97cfd3,_0x238948=_0x3e8e04['charAt'](0x1)==='/',_0x3367cc=_0x238948?_0x3e8e04['slice'](0x2,-0x1):_0x3e8e04[_0x1eaf4c(0x170)](0x1,-0x1),_0x277efe=ALLOWED_TAGS['includes'](_0x3367cc);if(!_0x277efe)continue;const _0x4cb896=_0x8fc869[_0x1eaf4c(0x170)](_0xfdfb40,_0x50071f);if(!_0x4cb896){_0xfdfb40=_0x50071f+_0x3e8e04[_0x1eaf4c(0x17d)];continue;}_0x238948?_0xbaa1dc[_0x1eaf4c(0x17a)]({'type':'tag','name':_0x3e8e04[_0x1eaf4c(0x170)](0x2,-0x1),'content':_0x4cb896}):_0xbaa1dc[_0x1eaf4c(0x17a)]({'type':_0x1eaf4c(0x175),'content':_0x4cb896}),_0xfdfb40=_0x50071f+_0x3e8e04[_0x1eaf4c(0x17d)];}return _0xfdfb40<_0x8fc869['length']&&_0xbaa1dc[_0x1eaf4c(0x17a)]({'type':_0x1eaf4c(0x175),'content':_0x8fc869['slice'](_0xfdfb40)}),_0xbaa1dc;};function formatMsgWithTags(_0x4ba967){const _0x369a7e=_0xc509eb,_0x4e099f=parseMsgTags(_0x4ba967),_0x1a882e=_0x4e099f[_0x369a7e(0x179)](({content:_0x491155,type:_0x82f1f2,name:_0x2a7b12},_0x5445f1)=>{const _0x36b5a7=_0x369a7e,_0x5bfeca=_0x82f1f2!==_0x36b5a7(0x175)&&_0x2a7b12?_0x2a7b12:_0x312476[_0x36b5a7(0x189)];return _0x312476['createElement'](_0x5bfeca,{'key':''+_0x5445f1},_0x491155);});return _0x1a882e;}function formatMsg(_0x44a18c,_0x42027d,_0x5f4e07){const _0x1daa0d=sprintf(_0x44a18c,..._0x42027d!==null&&_0x42027d!==void 0x0?_0x42027d:[]);if(!_0x5f4e07)return _0x1daa0d;return formatMsgWithTags(_0x1daa0d);}function _0x48a5(){const _0x431657=['33IuOWkB','select','values','useEffect','getKey','createElement','useContext','5691420kBtZQG','Fragment','2079070BeDWzv','7qOpRIL','32617050YnfmcC','_one','pluralUtils','strong','38156IosTDB','4BXcqcg','5232552VSneAX','PluralRules','5801632RBhsDm','lang','slice','\x22\x20is\x20not\x20supported.','plural','_rules','warn','text','supportedLocalesOf','exec','371138gcKHDH','map','push','createContext','processTags','length','isSupported','Plural\x20form\x20for\x20language\x20\x22','filter'];_0x48a5=function(){return _0x431657;};return _0x48a5();}const useTranslation=()=>{const _0x574ba2=_0xc509eb,{lang:_0x538844,debug:_0x9ac006,pluralUtils:_0x40d26e,resources:_0x2ed7ac}=_0x312476[_0x574ba2(0x187)](I18nContext);function _0x398e93(_0x2ae1c0,_0x2a7679){const _0x2ef6bc=_0x574ba2,{found:_0x2a5233,msg:_0x2d0333}=getMsg(_0x2ae1c0,_0x2ed7ac[_0x538844],{'plural':_0x2a7679===null||_0x2a7679===void 0x0?void 0x0:_0x2a7679[_0x2ef6bc(0x172)],'pluralUtils':_0x40d26e});_0x9ac006&&!_0x2a5233&&console['log']('['+_0x538844+']:\x20Translation\x20for\x20key\x20\x27'+_0x2ae1c0+'\x27\x20is\x20missing.');if(_0x2a7679===null||_0x2a7679===void 0x0?void 0x0:_0x2a7679[_0x2ef6bc(0x17c)])return formatMsg(_0x2d0333,_0x2a7679===null||_0x2a7679===void 0x0?void 0x0:_0x2a7679[_0x2ef6bc(0x183)],!![]);return formatMsg(_0x2d0333,_0x2a7679===null||_0x2a7679===void 0x0?void 0x0:_0x2a7679[_0x2ef6bc(0x183)],![]);}return{'t':_0x398e93,'lang':_0x538844};};export{I18nContext,I18nProvider,useTranslation};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class Plural {
|
|
2
|
+
lang: string;
|
|
3
|
+
private _rules?;
|
|
4
|
+
constructor(lang: string);
|
|
5
|
+
/**
|
|
6
|
+
* Checks if plural form is supported for selected language.
|
|
7
|
+
*
|
|
8
|
+
* @returns flag indicating if plural is supported
|
|
9
|
+
*/
|
|
10
|
+
static isSupported: (lang: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Gets plural form of the translation key.
|
|
13
|
+
*
|
|
14
|
+
* @param key main part of the translation key
|
|
15
|
+
* @param plural desired plural form
|
|
16
|
+
* @returns plural form of the translation key
|
|
17
|
+
*/
|
|
18
|
+
getKey(key: string, plural: number): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Plural';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { I18nTranslations } from '../context';
|
|
3
|
+
import { Plural } from '../plural';
|
|
4
|
+
export interface MsgOpts {
|
|
5
|
+
/**
|
|
6
|
+
* Indicates which plural to use.
|
|
7
|
+
*/
|
|
8
|
+
plural?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Plural utils.
|
|
11
|
+
*/
|
|
12
|
+
pluralUtils: Plural;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns translated message based on provided info.
|
|
16
|
+
*
|
|
17
|
+
* @param lang selected language
|
|
18
|
+
* @param key translation key
|
|
19
|
+
* @param translations language translations
|
|
20
|
+
* @param opts translation options
|
|
21
|
+
* @returns translation message
|
|
22
|
+
*/
|
|
23
|
+
export declare const getMsg: (key: string, translations: I18nTranslations | undefined, opts: MsgOpts) => {
|
|
24
|
+
found: boolean;
|
|
25
|
+
msg: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns formatted string as per `sprintf`.
|
|
29
|
+
*
|
|
30
|
+
* @param msg message to format
|
|
31
|
+
* @param values values to interpolate message with
|
|
32
|
+
* @returns formatted message
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatMsg(msg: string, values?: (string | number)[], processTags?: false): string;
|
|
35
|
+
export declare function formatMsg(msg: string, values?: (string | number)[], processTags?: true): React.ReactNode[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTranslation';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface TOpts<T extends boolean> {
|
|
3
|
+
/**
|
|
4
|
+
* Values to interpolate message with.
|
|
5
|
+
*/
|
|
6
|
+
values?: (string | number)[];
|
|
7
|
+
/**
|
|
8
|
+
* Indicates which plural to use.
|
|
9
|
+
*/
|
|
10
|
+
plural?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Include html tags in message.
|
|
13
|
+
*/
|
|
14
|
+
processTags?: T;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Exposes basic translation utilities which can be used in components.
|
|
18
|
+
* Most notably, it exposes `t` function which outputs translated message for currently selected language.
|
|
19
|
+
*
|
|
20
|
+
* @returns translation utils
|
|
21
|
+
*/
|
|
22
|
+
export declare const useTranslation: () => {
|
|
23
|
+
t: {
|
|
24
|
+
(key: string, opts?: TOpts<false>): string;
|
|
25
|
+
(key: string, opts?: TOpts<true>): React.ReactNode[];
|
|
26
|
+
};
|
|
27
|
+
lang: string;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
22
22
|
"name": "@ckbox/i18n",
|
|
23
|
-
"version": "1.
|
|
23
|
+
"version": "1.2.0-dev.0",
|
|
24
24
|
"description": "I18n utils of CKBox",
|
|
25
25
|
"main": "dist/index.js",
|
|
26
26
|
"types": "dist/index.d.ts",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"sprintf-js": "^1.1.2",
|
|
32
|
-
"tslib": "^2.4.
|
|
32
|
+
"tslib": "^2.4.1"
|
|
33
33
|
}
|
|
34
34
|
}
|