@zohodesk/i18n 1.0.0-beta.15.1 → 1.0.0-beta.18
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 +73 -41
- package/es/components/DateTimeDiffFormat.js +46 -12
- package/es/components/HOCI18N.js +33 -30
- package/es/components/I18NProvider.js +7 -16
- package/es/components/UserTimeDiffFormat.js +11 -9
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
- package/es/components/__tests__/FormatText.spec.js +0 -1
- package/es/components/__tests__/HOCI18N.spec.js +0 -1
- package/es/components/__tests__/I18N.spec.js +0 -2
- package/es/components/__tests__/I18NProvider.spec.js +0 -1
- package/es/components/__tests__/PluralFormat.spec.js +0 -1
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +2 -3
- package/es/utils.js +119 -171
- package/lib/components/DateTimeDiffFormat.js +49 -15
- package/lib/components/FormatText.js +4 -4
- package/lib/components/HOCI18N.js +4 -4
- package/lib/components/I18N.js +4 -4
- package/lib/components/I18NProvider.js +12 -21
- package/lib/components/PluralFormat.js +4 -4
- package/lib/components/UserTimeDiffFormat.js +12 -14
- package/lib/components/__tests__/I18NProvider.spec.js +1 -1
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +54 -56
- package/lib/utils.js +130 -212
- package/package.json +28 -28
- package/src/I18NContext.js +2 -2
- package/src/components/DateTimeDiffFormat.js +254 -211
- package/src/components/FormatText.js +14 -14
- package/src/components/HOCI18N.js +37 -37
- package/src/components/I18N.js +72 -72
- package/src/components/I18NProvider.js +106 -116
- package/src/components/PluralFormat.js +37 -37
- package/src/components/UserTimeDiffFormat.js +94 -103
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
- package/src/components/__tests__/FormatText.spec.js +26 -26
- package/src/components/__tests__/HOCI18N.spec.js +33 -33
- package/src/components/__tests__/I18N.spec.js +29 -29
- package/src/components/__tests__/I18NProvider.spec.js +65 -65
- package/src/components/__tests__/PluralFormat.spec.js +27 -27
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/src/index.js +33 -33
- package/src/utils.js +527 -587
- package/es/components/NewDateFormat.js +0 -53
- package/lib/components/NewDateFormat.js +0 -60
- package/src/components/NewDateFormat.js +0 -60
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import FormatText from '../FormatText';
|
|
2
|
-
import I18NProvider from '../I18NProvider';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import renderer from 'react-test-renderer';
|
|
5
|
-
|
|
6
|
-
describe('FormatText component', () => {
|
|
7
|
-
it('Should display i18n value as html', () => {
|
|
8
|
-
let ele=renderer.create(
|
|
9
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
10
|
-
<FormatText i18NKey='key1' isHtml />
|
|
11
|
-
</I18NProvider>
|
|
12
|
-
);
|
|
13
|
-
let tree=ele.toJSON();
|
|
14
|
-
expect(tree).toMatchSnapshot();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('Should display i18n value', () => {
|
|
18
|
-
let ele=renderer.create(
|
|
19
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
20
|
-
<FormatText i18NKey='key1' />
|
|
21
|
-
</I18NProvider>
|
|
22
|
-
);
|
|
23
|
-
let tree=ele.toJSON();
|
|
24
|
-
expect(tree).toMatchSnapshot();
|
|
25
|
-
});
|
|
26
|
-
|
|
1
|
+
import FormatText from '../FormatText';
|
|
2
|
+
import I18NProvider from '../I18NProvider';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import renderer from 'react-test-renderer';
|
|
5
|
+
|
|
6
|
+
describe('FormatText component', () => {
|
|
7
|
+
it('Should display i18n value as html', () => {
|
|
8
|
+
let ele=renderer.create(
|
|
9
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
10
|
+
<FormatText i18NKey='key1' isHtml />
|
|
11
|
+
</I18NProvider>
|
|
12
|
+
);
|
|
13
|
+
let tree=ele.toJSON();
|
|
14
|
+
expect(tree).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Should display i18n value', () => {
|
|
18
|
+
let ele=renderer.create(
|
|
19
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
20
|
+
<FormatText i18NKey='key1' />
|
|
21
|
+
</I18NProvider>
|
|
22
|
+
);
|
|
23
|
+
let tree=ele.toJSON();
|
|
24
|
+
expect(tree).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
27
|
});
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import HOCI18N from '..//HOCI18N';
|
|
2
|
-
import I18NProvider from '../I18NProvider';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import renderer from 'react-test-renderer';
|
|
6
|
-
|
|
7
|
-
let Test = props => <div>test{props.placeHolder}</div>;
|
|
8
|
-
Test.propTypes = {
|
|
9
|
-
placeHolder: PropTypes.string
|
|
10
|
-
};
|
|
11
|
-
const defaultProps = {
|
|
12
|
-
i18NKey: 'key1<b>vimal</b>'
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('I18N component', () => {
|
|
16
|
-
it('Should display i18n value', () => {
|
|
17
|
-
Test = HOCI18N(['placeHolder'])(Test);
|
|
18
|
-
let ele = renderer.create(
|
|
19
|
-
<I18NProvider i18n={{ key1: 'vimal1' }}>
|
|
20
|
-
<Test placeHolder='key1' />
|
|
21
|
-
</I18NProvider>
|
|
22
|
-
);
|
|
23
|
-
let tree = ele.toJSON();
|
|
24
|
-
expect(tree).toMatchSnapshot();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('Should display i18n key', () => {
|
|
28
|
-
Test = HOCI18N(['placeHolder'])(Test);
|
|
29
|
-
let ele = renderer.create(<Test placeHolder='key1' />);
|
|
30
|
-
let tree = ele.toJSON();
|
|
31
|
-
expect(tree).toMatchSnapshot();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
1
|
+
import HOCI18N from '..//HOCI18N';
|
|
2
|
+
import I18NProvider from '../I18NProvider';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import renderer from 'react-test-renderer';
|
|
6
|
+
|
|
7
|
+
let Test = props => <div>test{props.placeHolder}</div>;
|
|
8
|
+
Test.propTypes = {
|
|
9
|
+
placeHolder: PropTypes.string
|
|
10
|
+
};
|
|
11
|
+
const defaultProps = {
|
|
12
|
+
i18NKey: 'key1<b>vimal</b>'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('I18N component', () => {
|
|
16
|
+
it('Should display i18n value', () => {
|
|
17
|
+
Test = HOCI18N(['placeHolder'])(Test);
|
|
18
|
+
let ele = renderer.create(
|
|
19
|
+
<I18NProvider i18n={{ key1: 'vimal1' }}>
|
|
20
|
+
<Test placeHolder='key1' />
|
|
21
|
+
</I18NProvider>
|
|
22
|
+
);
|
|
23
|
+
let tree = ele.toJSON();
|
|
24
|
+
expect(tree).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should display i18n key', () => {
|
|
28
|
+
Test = HOCI18N(['placeHolder'])(Test);
|
|
29
|
+
let ele = renderer.create(<Test placeHolder='key1' />);
|
|
30
|
+
let tree = ele.toJSON();
|
|
31
|
+
expect(tree).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import I18N from '../I18N';
|
|
2
|
-
import I18NProvider from '../I18NProvider';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import renderer from 'react-test-renderer';
|
|
5
|
-
|
|
6
|
-
const defaultProps ={
|
|
7
|
-
i18NKey: 'key1'
|
|
8
|
-
};
|
|
9
|
-
describe('I18N component', () => {
|
|
10
|
-
it('Should display i18n value as html', () => {
|
|
11
|
-
let ele=renderer.create(
|
|
12
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
13
|
-
<I18N {...defaultProps} isHtml />
|
|
14
|
-
</I18NProvider>
|
|
15
|
-
);
|
|
16
|
-
let tree=ele.toJSON();
|
|
17
|
-
expect(tree).toMatchSnapshot();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Should display i18n value', () => {
|
|
21
|
-
let ele=renderer.create(
|
|
22
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
23
|
-
<I18N {...defaultProps} />
|
|
24
|
-
</I18NProvider>
|
|
25
|
-
);
|
|
26
|
-
let tree=ele.toJSON();
|
|
27
|
-
expect(tree).toMatchSnapshot();
|
|
28
|
-
});
|
|
29
|
-
|
|
1
|
+
import I18N from '../I18N';
|
|
2
|
+
import I18NProvider from '../I18NProvider';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import renderer from 'react-test-renderer';
|
|
5
|
+
|
|
6
|
+
const defaultProps ={
|
|
7
|
+
i18NKey: 'key1'
|
|
8
|
+
};
|
|
9
|
+
describe('I18N component', () => {
|
|
10
|
+
it('Should display i18n value as html', () => {
|
|
11
|
+
let ele=renderer.create(
|
|
12
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
13
|
+
<I18N {...defaultProps} isHtml />
|
|
14
|
+
</I18NProvider>
|
|
15
|
+
);
|
|
16
|
+
let tree=ele.toJSON();
|
|
17
|
+
expect(tree).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('Should display i18n value', () => {
|
|
21
|
+
let ele=renderer.create(
|
|
22
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
23
|
+
<I18N {...defaultProps} />
|
|
24
|
+
</I18NProvider>
|
|
25
|
+
);
|
|
26
|
+
let tree=ele.toJSON();
|
|
27
|
+
expect(tree).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
30
|
});
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import I18NProvider, { i18NProviderUtils } from '../I18NProvider';
|
|
2
|
-
import I18N from '../I18N';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import renderer from 'react-test-renderer';
|
|
5
|
-
import { Provider } from 'react-redux';
|
|
6
|
-
import configureStore from 'redux-mock-store';
|
|
7
|
-
import thunk from 'redux-thunk';
|
|
8
|
-
|
|
9
|
-
describe('I18NProvider component', () => {
|
|
10
|
-
it('Should display i18n value using i18n utils function without I18NProvider', () => {
|
|
11
|
-
expect(i18NProviderUtils.getI18NValue('key1')).toBe('key1');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('Should display i18n value', () => {
|
|
15
|
-
let ele = renderer.create(
|
|
16
|
-
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
17
|
-
<I18N i18NKey='key1' />
|
|
18
|
-
</I18NProvider>
|
|
19
|
-
);
|
|
20
|
-
let tree = ele.toJSON();
|
|
21
|
-
expect(tree).toMatchSnapshot();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('Should display key not available case', () => {
|
|
25
|
-
let ele = renderer.create(
|
|
26
|
-
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
27
|
-
<I18N i18NKey='key2' />
|
|
28
|
-
</I18NProvider>
|
|
29
|
-
);
|
|
30
|
-
let tree = ele.toJSON();
|
|
31
|
-
expect(tree).toMatchSnapshot();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('Should display i18n value using i18n utils function', () => {
|
|
35
|
-
let ele = renderer.create(
|
|
36
|
-
<I18NProvider i18n={{ key1: 'vimal' }}>
|
|
37
|
-
<div>test</div>
|
|
38
|
-
</I18NProvider>
|
|
39
|
-
);
|
|
40
|
-
expect(i18NProviderUtils.getI18NValue('key1')).toBe('vimal');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('Should display user date format using i18n utils function', () => {
|
|
44
|
-
let ele = renderer.create(
|
|
45
|
-
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
46
|
-
<div>test</div>
|
|
47
|
-
</I18NProvider>
|
|
48
|
-
);
|
|
49
|
-
expect(
|
|
50
|
-
i18NProviderUtils.userDateFormat(
|
|
51
|
-
'2016-12-27T08:36:03.837Z',
|
|
52
|
-
{
|
|
53
|
-
today: 'DD-MM-YYYY[today]',
|
|
54
|
-
tomorrow: 'DD-MM-YYYY[tomorrow]',
|
|
55
|
-
yesterday: 'DD-MM-YYYY-[yesterday]',
|
|
56
|
-
|
|
57
|
-
others: () => 'DD-MM-YYYY-[others]'
|
|
58
|
-
},
|
|
59
|
-
'',
|
|
60
|
-
'',
|
|
61
|
-
true
|
|
62
|
-
)
|
|
63
|
-
).toBe('27-12-2016tomorrow');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
1
|
+
import I18NProvider, { i18NProviderUtils } from '../I18NProvider';
|
|
2
|
+
import I18N from '../I18N';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import renderer from 'react-test-renderer';
|
|
5
|
+
import { Provider } from 'react-redux';
|
|
6
|
+
import configureStore from 'redux-mock-store';
|
|
7
|
+
import thunk from 'redux-thunk';
|
|
8
|
+
|
|
9
|
+
describe('I18NProvider component', () => {
|
|
10
|
+
it('Should display i18n value using i18n utils function without I18NProvider', () => {
|
|
11
|
+
expect(i18NProviderUtils.getI18NValue('key1')).toBe('key1');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('Should display i18n value', () => {
|
|
15
|
+
let ele = renderer.create(
|
|
16
|
+
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
17
|
+
<I18N i18NKey='key1' />
|
|
18
|
+
</I18NProvider>
|
|
19
|
+
);
|
|
20
|
+
let tree = ele.toJSON();
|
|
21
|
+
expect(tree).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('Should display key not available case', () => {
|
|
25
|
+
let ele = renderer.create(
|
|
26
|
+
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
27
|
+
<I18N i18NKey='key2' />
|
|
28
|
+
</I18NProvider>
|
|
29
|
+
);
|
|
30
|
+
let tree = ele.toJSON();
|
|
31
|
+
expect(tree).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Should display i18n value using i18n utils function', () => {
|
|
35
|
+
let ele = renderer.create(
|
|
36
|
+
<I18NProvider i18n={{ key1: 'vimal' }}>
|
|
37
|
+
<div>test</div>
|
|
38
|
+
</I18NProvider>
|
|
39
|
+
);
|
|
40
|
+
expect(i18NProviderUtils.getI18NValue('key1')).toBe('vimal');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('Should display user date format using i18n utils function', () => {
|
|
44
|
+
let ele = renderer.create(
|
|
45
|
+
<I18NProvider i18n={{ key1: 'vimal' }} timeZone='Asia/Calcutta'>
|
|
46
|
+
<div>test</div>
|
|
47
|
+
</I18NProvider>
|
|
48
|
+
);
|
|
49
|
+
expect(
|
|
50
|
+
i18NProviderUtils.userDateFormat(
|
|
51
|
+
'2016-12-27T08:36:03.837Z',
|
|
52
|
+
{
|
|
53
|
+
today: 'DD-MM-YYYY[today]',
|
|
54
|
+
tomorrow: 'DD-MM-YYYY[tomorrow]',
|
|
55
|
+
yesterday: 'DD-MM-YYYY-[yesterday]',
|
|
56
|
+
|
|
57
|
+
others: () => 'DD-MM-YYYY-[others]'
|
|
58
|
+
},
|
|
59
|
+
'',
|
|
60
|
+
'',
|
|
61
|
+
true
|
|
62
|
+
)
|
|
63
|
+
).toBe('27-12-2016tomorrow');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import PluralFormat from '../PluralFormat';
|
|
2
|
-
import I18NProvider from '../I18NProvider';
|
|
3
|
-
import FormatText from '../FormatText';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import renderer from 'react-test-renderer';
|
|
6
|
-
|
|
7
|
-
describe('PluralFormat component', () => {
|
|
8
|
-
it('Should display i18n value as html', () => {
|
|
9
|
-
let ele=renderer.create(
|
|
10
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
11
|
-
<FormatText i18NKey='key1' isHtml />
|
|
12
|
-
</I18NProvider>
|
|
13
|
-
);
|
|
14
|
-
let tree=ele.toJSON();
|
|
15
|
-
expect(tree).toMatchSnapshot();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('Should display i18n value', () => {
|
|
19
|
-
let ele=renderer.create(
|
|
20
|
-
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
21
|
-
<FormatText i18NKey='key1' />
|
|
22
|
-
</I18NProvider>
|
|
23
|
-
);
|
|
24
|
-
let tree=ele.toJSON();
|
|
25
|
-
expect(tree).toMatchSnapshot();
|
|
26
|
-
});
|
|
27
|
-
|
|
1
|
+
import PluralFormat from '../PluralFormat';
|
|
2
|
+
import I18NProvider from '../I18NProvider';
|
|
3
|
+
import FormatText from '../FormatText';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import renderer from 'react-test-renderer';
|
|
6
|
+
|
|
7
|
+
describe('PluralFormat component', () => {
|
|
8
|
+
it('Should display i18n value as html', () => {
|
|
9
|
+
let ele=renderer.create(
|
|
10
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
11
|
+
<FormatText i18NKey='key1' isHtml />
|
|
12
|
+
</I18NProvider>
|
|
13
|
+
);
|
|
14
|
+
let tree=ele.toJSON();
|
|
15
|
+
expect(tree).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Should display i18n value', () => {
|
|
19
|
+
let ele=renderer.create(
|
|
20
|
+
<I18NProvider i18n={{ key1: 'vimal1<b>vimal</b>' }}>
|
|
21
|
+
<FormatText i18NKey='key1' />
|
|
22
|
+
</I18NProvider>
|
|
23
|
+
);
|
|
24
|
+
let tree=ele.toJSON();
|
|
25
|
+
expect(tree).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
28
|
});
|