@prezly/theme-kit-intl 8.2.0 → 9.0.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/build/dictionary.cjs +33 -0
- package/build/dictionary.d.ts +3 -0
- package/build/dictionary.mjs +26 -0
- package/build/formatting/datetime/lib.cjs +4 -16
- package/build/formatting/datetime/lib.d.ts +2 -0
- package/build/formatting/datetime/lib.mjs +3 -16
- package/build/formatting/datetime/lib.test.cjs +14 -0
- package/build/formatting/datetime/lib.test.d.ts +1 -0
- package/build/formatting/datetime/lib.test.mjs +12 -0
- package/build/formatting/datetime/shared.test.cjs +15 -0
- package/build/formatting/datetime/shared.test.d.ts +1 -0
- package/build/formatting/datetime/shared.test.mjs +13 -0
- package/build/formatting/messages/lib.cjs +91 -63
- package/build/formatting/messages/lib.d.ts +7 -2
- package/build/formatting/messages/lib.mjs +89 -65
- package/build/formatting/messages/lib.test.cjs +141 -6
- package/build/formatting/messages/lib.test.mjs +142 -7
- package/build/formatting/messages/types.cjs +18 -1
- package/build/formatting/messages/types.d.ts +46 -3
- package/build/formatting/messages/types.mjs +12 -1
- package/build/i18n/af.json +87 -1
- package/build/i18n/ar.json +139 -2
- package/build/i18n/az.json +86 -0
- package/build/i18n/be.json +130 -0
- package/build/i18n/bg.json +130 -0
- package/build/i18n/ca.json +130 -0
- package/build/i18n/cs.json +134 -4
- package/build/i18n/da.json +130 -0
- package/build/i18n/de.json +86 -0
- package/build/i18n/el.json +86 -0
- package/build/i18n/en.json +130 -0
- package/build/i18n/es.json +131 -1
- package/build/i18n/et.json +86 -0
- package/build/i18n/fi.json +86 -0
- package/build/i18n/fil.json +87 -1
- package/build/i18n/fr.json +86 -0
- package/build/i18n/ga.json +130 -0
- package/build/i18n/he.json +108 -0
- package/build/i18n/hi.json +86 -0
- package/build/i18n/hr.json +108 -0
- package/build/i18n/hu.json +86 -0
- package/build/i18n/id.json +65 -1
- package/build/i18n/it.json +108 -0
- package/build/i18n/ja.json +64 -0
- package/build/i18n/kk.json +130 -0
- package/build/i18n/ko.json +64 -0
- package/build/i18n/lt.json +131 -1
- package/build/i18n/lv.json +87 -1
- package/build/i18n/mt.json +124 -0
- package/build/i18n/nl.json +131 -1
- package/build/i18n/no.json +86 -0
- package/build/i18n/pl.json +131 -1
- package/build/i18n/pt-BR.json +132 -2
- package/build/i18n/pt.json +133 -3
- package/build/i18n/ro.json +109 -1
- package/build/i18n/ru.json +130 -0
- package/build/i18n/sk.json +108 -0
- package/build/i18n/sl.json +131 -1
- package/build/i18n/sr.json +130 -0
- package/build/i18n/sv.json +130 -0
- package/build/i18n/sw.json +86 -0
- package/build/i18n/th.json +130 -0
- package/build/i18n/tr.json +130 -0
- package/build/i18n/uk.json +130 -0
- package/build/i18n/ur.json +86 -0
- package/build/i18n/uz.json +86 -0
- package/build/i18n/vi.json +64 -0
- package/build/i18n/zh-CN.json +130 -0
- package/build/i18n/zh-TW.json +64 -0
- package/build/index.cjs +12 -0
- package/build/index.d.ts +1 -0
- package/build/index.mjs +1 -0
- package/build/messages/content.cjs +12 -0
- package/build/messages/content.d.ts +12 -0
- package/build/messages/content.mjs +12 -0
- package/build/utils/index.cjs +12 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.mjs +1 -0
- package/build/utils/withCache.cjs +20 -0
- package/build/utils/withCache.d.ts +1 -0
- package/build/utils/withCache.mjs +14 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _index = require("../../locales/index.cjs");
|
|
3
4
|
var _lib = require("./lib.cjs");
|
|
4
5
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
5
6
|
|
|
@@ -13,11 +14,45 @@ var I18N = {
|
|
|
13
14
|
}, {
|
|
14
15
|
type: 0,
|
|
15
16
|
value: '!'
|
|
17
|
+
}],
|
|
18
|
+
["images.count"]: [{
|
|
19
|
+
type: 0,
|
|
20
|
+
value: 'Images: '
|
|
21
|
+
}, {
|
|
22
|
+
offset: 0,
|
|
23
|
+
options: {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
|
+
'=0': {
|
|
26
|
+
value: [{
|
|
27
|
+
type: 0,
|
|
28
|
+
value: 'no images'
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
one: {
|
|
32
|
+
value: [{
|
|
33
|
+
type: 7
|
|
34
|
+
}, {
|
|
35
|
+
type: 0,
|
|
36
|
+
value: ' image'
|
|
37
|
+
}]
|
|
38
|
+
},
|
|
39
|
+
other: {
|
|
40
|
+
value: [{
|
|
41
|
+
type: 7
|
|
42
|
+
}, {
|
|
43
|
+
type: 0,
|
|
44
|
+
value: ' images'
|
|
45
|
+
}]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
pluralType: 'cardinal',
|
|
49
|
+
type: 6,
|
|
50
|
+
value: 'imagesCount'
|
|
16
51
|
}]
|
|
17
52
|
};
|
|
18
53
|
describe('formatMessageString', () => {
|
|
19
54
|
it('should format intl-generated message intl object using the given values', () => {
|
|
20
|
-
var formatted = (0, _lib.formatMessageString)({
|
|
55
|
+
var formatted = (0, _lib.formatMessageString)('en', {
|
|
21
56
|
id: 'hello.world',
|
|
22
57
|
defaultMessage: 'Hello, {name}!'
|
|
23
58
|
}, I18N, {
|
|
@@ -26,14 +61,14 @@ describe('formatMessageString', () => {
|
|
|
26
61
|
expect(formatted).toBe('¡Hola, Julio!');
|
|
27
62
|
});
|
|
28
63
|
it('should leave placeholders if the given values object does not have enough data', () => {
|
|
29
|
-
var formatted = (0, _lib.formatMessageString)({
|
|
64
|
+
var formatted = (0, _lib.formatMessageString)('en', {
|
|
30
65
|
id: 'hello.world',
|
|
31
66
|
defaultMessage: 'Hello, {name}!'
|
|
32
67
|
}, I18N, {});
|
|
33
68
|
expect(formatted).toBe('¡Hola, {name}!');
|
|
34
69
|
});
|
|
35
70
|
it('should fallback to the default message if the dictionary does not have it', () => {
|
|
36
|
-
var formatted = (0, _lib.formatMessageString)({
|
|
71
|
+
var formatted = (0, _lib.formatMessageString)('en', {
|
|
37
72
|
id: 'hello.world',
|
|
38
73
|
defaultMessage: 'Hello, {name}!'
|
|
39
74
|
}, {}, {
|
|
@@ -41,10 +76,36 @@ describe('formatMessageString', () => {
|
|
|
41
76
|
});
|
|
42
77
|
expect(formatted).toBe('Hello, Julio!');
|
|
43
78
|
});
|
|
79
|
+
it('should format pluralization placeholders', () => {
|
|
80
|
+
function format(imagesCount) {
|
|
81
|
+
return (0, _lib.formatMessageString)('en', {
|
|
82
|
+
id: 'images.count',
|
|
83
|
+
defaultMessage: 'default'
|
|
84
|
+
}, I18N, {
|
|
85
|
+
imagesCount
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
expect(format(0)).toBe('Images: no images');
|
|
89
|
+
expect(format(1)).toBe('Images: 1 image');
|
|
90
|
+
expect(format(1024)).toBe('Images: 1024 images');
|
|
91
|
+
});
|
|
92
|
+
it('should do the most minimal support for pluralization placeholders in default messages', () => {
|
|
93
|
+
function format(imagesCount) {
|
|
94
|
+
return (0, _lib.formatMessageString)('en', {
|
|
95
|
+
id: 'images.count',
|
|
96
|
+
defaultMessage: 'Images: {imagesCount, plural, other {IDK}}'
|
|
97
|
+
}, {}, {
|
|
98
|
+
imagesCount
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
expect(format(0)).toEqual('Images: 0');
|
|
102
|
+
expect(format(1)).toEqual('Images: 1');
|
|
103
|
+
expect(format(1024)).toEqual('Images: 1024');
|
|
104
|
+
});
|
|
44
105
|
});
|
|
45
106
|
describe('formatMessageFragment', () => {
|
|
46
107
|
it('should format intl-generated message intl object using the given values', () => {
|
|
47
|
-
var formatted = (0, _lib.formatMessageFragment)({
|
|
108
|
+
var formatted = (0, _lib.formatMessageFragment)('en', {
|
|
48
109
|
id: 'hello.world',
|
|
49
110
|
defaultMessage: 'Hello, {name}!'
|
|
50
111
|
}, I18N, {
|
|
@@ -56,14 +117,14 @@ describe('formatMessageFragment', () => {
|
|
|
56
117
|
}, '!']);
|
|
57
118
|
});
|
|
58
119
|
it('should leave placeholders if the given values object does not have enough data', () => {
|
|
59
|
-
var formatted = (0, _lib.formatMessageFragment)({
|
|
120
|
+
var formatted = (0, _lib.formatMessageFragment)('en', {
|
|
60
121
|
id: 'hello.world',
|
|
61
122
|
defaultMessage: 'Hello, {name}!'
|
|
62
123
|
}, I18N, {});
|
|
63
124
|
expect(formatted).toEqual(['¡Hola, ', '{name}', '!']);
|
|
64
125
|
});
|
|
65
126
|
it('should fallback to the default message if the dictionary does not have it', () => {
|
|
66
|
-
var formatted = (0, _lib.formatMessageFragment)({
|
|
127
|
+
var formatted = (0, _lib.formatMessageFragment)('en', {
|
|
67
128
|
id: 'hello.world',
|
|
68
129
|
defaultMessage: 'Hello, {name}!'
|
|
69
130
|
}, {}, {
|
|
@@ -74,6 +135,80 @@ describe('formatMessageFragment', () => {
|
|
|
74
135
|
children: ['Julio']
|
|
75
136
|
}, '!']);
|
|
76
137
|
});
|
|
138
|
+
it('should format pluralization placeholders', () => {
|
|
139
|
+
function format(imagesCount) {
|
|
140
|
+
return (0, _lib.formatMessageFragment)('en', {
|
|
141
|
+
id: 'images.count',
|
|
142
|
+
defaultMessage: 'default'
|
|
143
|
+
}, I18N, {
|
|
144
|
+
imagesCount
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
expect(format(0)).toEqual(['Images: ', 'no images']);
|
|
148
|
+
expect(format(1)).toEqual(['Images: ', '1', ' image']);
|
|
149
|
+
expect(format(1024)).toEqual(['Images: ', '1024', ' images']);
|
|
150
|
+
});
|
|
151
|
+
it('should do the most minimal support for pluralization placeholders in default messages', () => {
|
|
152
|
+
function format(imagesCount) {
|
|
153
|
+
return (0, _lib.formatMessageFragment)('en', {
|
|
154
|
+
id: 'images.count',
|
|
155
|
+
defaultMessage: 'Images: {imagesCount, plural, other {IDK}}'
|
|
156
|
+
}, {}, {
|
|
157
|
+
imagesCount
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
expect(format(0)).toEqual(['Images: ', 0]);
|
|
161
|
+
expect(format(1)).toEqual(['Images: ', 1]);
|
|
162
|
+
expect(format(1024)).toEqual(['Images: ', 1024]);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('parseMessage', () => {
|
|
166
|
+
it('should parse literal string', () => {
|
|
167
|
+
var parsed = (0, _lib.parseMessage)('Hello world!');
|
|
168
|
+
expect(parsed).toEqual([{
|
|
169
|
+
type: 0,
|
|
170
|
+
value: 'Hello world!'
|
|
171
|
+
}]);
|
|
172
|
+
});
|
|
173
|
+
it('should parse argument placeholders', () => {
|
|
174
|
+
var parsed = (0, _lib.parseMessage)('Hello {name}!');
|
|
175
|
+
expect(parsed).toEqual([{
|
|
176
|
+
type: 0,
|
|
177
|
+
value: 'Hello '
|
|
178
|
+
}, {
|
|
179
|
+
type: 1,
|
|
180
|
+
value: 'name'
|
|
181
|
+
}, {
|
|
182
|
+
type: 0,
|
|
183
|
+
value: '!'
|
|
184
|
+
}]);
|
|
185
|
+
});
|
|
186
|
+
it('should partially parse plural placeholders as a last resort fallback', () => {
|
|
187
|
+
var parsed = (0, _lib.parseMessage)('{apples, plural, zero {There are no apples}, one {There is one apple}, other {There are # apples}}');
|
|
188
|
+
expect(parsed).toEqual([{
|
|
189
|
+
type: 1,
|
|
190
|
+
value: 'apples'
|
|
191
|
+
}]);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
describe('tokenizeMessage', () => {
|
|
195
|
+
it('should return a single item array for literal strings', () => {
|
|
196
|
+
var tokens = (0, _lib.tokenizeMessage)('Hello world');
|
|
197
|
+
expect(tokens).toEqual(['Hello world']);
|
|
198
|
+
});
|
|
199
|
+
it('it should tokenize simple placeholders', () => {
|
|
200
|
+
var tokens = (0, _lib.tokenizeMessage)('Hello {type} world of {creatures}!');
|
|
201
|
+
expect(tokens).toEqual(['Hello ', '{type}', ' world of ', '{creatures}', '!']);
|
|
202
|
+
});
|
|
203
|
+
it('it should tokenize pluralization placeholders', () => {
|
|
204
|
+
var tokens = (0, _lib.tokenizeMessage)('Hello {type} world of {count, plural, other {#}} {creatures}!');
|
|
205
|
+
expect(tokens).toEqual(['Hello ', '{type}', ' world of ', '{count, plural, other {#}}', ' ', '{creatures}', '!']);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('getPluralRules', () => {
|
|
209
|
+
test.each(_index.supportedLocales)('should be safe to use with any of the supported locales: %s', locale => {
|
|
210
|
+
expect((0, _lib.getPluralRules)(_index.Locale.from(locale).code)).toBeInstanceOf(Intl.PluralRules);
|
|
211
|
+
});
|
|
77
212
|
});
|
|
78
213
|
|
|
79
214
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
-
import {
|
|
2
|
+
import { Locale, supportedLocales } from "../../locales/index.mjs";
|
|
3
|
+
import { formatMessageFragment, formatMessageString, getPluralRules, parseMessage, tokenizeMessage } from "./lib.mjs";
|
|
3
4
|
var I18N = {
|
|
4
5
|
["hello.world"]: [{
|
|
5
6
|
type: 0,
|
|
@@ -10,11 +11,45 @@ var I18N = {
|
|
|
10
11
|
}, {
|
|
11
12
|
type: 0,
|
|
12
13
|
value: '!'
|
|
14
|
+
}],
|
|
15
|
+
["images.count"]: [{
|
|
16
|
+
type: 0,
|
|
17
|
+
value: 'Images: '
|
|
18
|
+
}, {
|
|
19
|
+
offset: 0,
|
|
20
|
+
options: {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
+
'=0': {
|
|
23
|
+
value: [{
|
|
24
|
+
type: 0,
|
|
25
|
+
value: 'no images'
|
|
26
|
+
}]
|
|
27
|
+
},
|
|
28
|
+
one: {
|
|
29
|
+
value: [{
|
|
30
|
+
type: 7
|
|
31
|
+
}, {
|
|
32
|
+
type: 0,
|
|
33
|
+
value: ' image'
|
|
34
|
+
}]
|
|
35
|
+
},
|
|
36
|
+
other: {
|
|
37
|
+
value: [{
|
|
38
|
+
type: 7
|
|
39
|
+
}, {
|
|
40
|
+
type: 0,
|
|
41
|
+
value: ' images'
|
|
42
|
+
}]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
pluralType: 'cardinal',
|
|
46
|
+
type: 6,
|
|
47
|
+
value: 'imagesCount'
|
|
13
48
|
}]
|
|
14
49
|
};
|
|
15
50
|
describe('formatMessageString', () => {
|
|
16
51
|
it('should format intl-generated message intl object using the given values', () => {
|
|
17
|
-
var formatted = formatMessageString({
|
|
52
|
+
var formatted = formatMessageString('en', {
|
|
18
53
|
id: 'hello.world',
|
|
19
54
|
defaultMessage: 'Hello, {name}!'
|
|
20
55
|
}, I18N, {
|
|
@@ -23,14 +58,14 @@ describe('formatMessageString', () => {
|
|
|
23
58
|
expect(formatted).toBe('¡Hola, Julio!');
|
|
24
59
|
});
|
|
25
60
|
it('should leave placeholders if the given values object does not have enough data', () => {
|
|
26
|
-
var formatted = formatMessageString({
|
|
61
|
+
var formatted = formatMessageString('en', {
|
|
27
62
|
id: 'hello.world',
|
|
28
63
|
defaultMessage: 'Hello, {name}!'
|
|
29
64
|
}, I18N, {});
|
|
30
65
|
expect(formatted).toBe('¡Hola, {name}!');
|
|
31
66
|
});
|
|
32
67
|
it('should fallback to the default message if the dictionary does not have it', () => {
|
|
33
|
-
var formatted = formatMessageString({
|
|
68
|
+
var formatted = formatMessageString('en', {
|
|
34
69
|
id: 'hello.world',
|
|
35
70
|
defaultMessage: 'Hello, {name}!'
|
|
36
71
|
}, {}, {
|
|
@@ -38,10 +73,36 @@ describe('formatMessageString', () => {
|
|
|
38
73
|
});
|
|
39
74
|
expect(formatted).toBe('Hello, Julio!');
|
|
40
75
|
});
|
|
76
|
+
it('should format pluralization placeholders', () => {
|
|
77
|
+
function format(imagesCount) {
|
|
78
|
+
return formatMessageString('en', {
|
|
79
|
+
id: 'images.count',
|
|
80
|
+
defaultMessage: 'default'
|
|
81
|
+
}, I18N, {
|
|
82
|
+
imagesCount
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
expect(format(0)).toBe('Images: no images');
|
|
86
|
+
expect(format(1)).toBe('Images: 1 image');
|
|
87
|
+
expect(format(1024)).toBe('Images: 1024 images');
|
|
88
|
+
});
|
|
89
|
+
it('should do the most minimal support for pluralization placeholders in default messages', () => {
|
|
90
|
+
function format(imagesCount) {
|
|
91
|
+
return formatMessageString('en', {
|
|
92
|
+
id: 'images.count',
|
|
93
|
+
defaultMessage: 'Images: {imagesCount, plural, other {IDK}}'
|
|
94
|
+
}, {}, {
|
|
95
|
+
imagesCount
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
expect(format(0)).toEqual('Images: 0');
|
|
99
|
+
expect(format(1)).toEqual('Images: 1');
|
|
100
|
+
expect(format(1024)).toEqual('Images: 1024');
|
|
101
|
+
});
|
|
41
102
|
});
|
|
42
103
|
describe('formatMessageFragment', () => {
|
|
43
104
|
it('should format intl-generated message intl object using the given values', () => {
|
|
44
|
-
var formatted = formatMessageFragment({
|
|
105
|
+
var formatted = formatMessageFragment('en', {
|
|
45
106
|
id: 'hello.world',
|
|
46
107
|
defaultMessage: 'Hello, {name}!'
|
|
47
108
|
}, I18N, {
|
|
@@ -53,14 +114,14 @@ describe('formatMessageFragment', () => {
|
|
|
53
114
|
}, '!']);
|
|
54
115
|
});
|
|
55
116
|
it('should leave placeholders if the given values object does not have enough data', () => {
|
|
56
|
-
var formatted = formatMessageFragment({
|
|
117
|
+
var formatted = formatMessageFragment('en', {
|
|
57
118
|
id: 'hello.world',
|
|
58
119
|
defaultMessage: 'Hello, {name}!'
|
|
59
120
|
}, I18N, {});
|
|
60
121
|
expect(formatted).toEqual(['¡Hola, ', '{name}', '!']);
|
|
61
122
|
});
|
|
62
123
|
it('should fallback to the default message if the dictionary does not have it', () => {
|
|
63
|
-
var formatted = formatMessageFragment({
|
|
124
|
+
var formatted = formatMessageFragment('en', {
|
|
64
125
|
id: 'hello.world',
|
|
65
126
|
defaultMessage: 'Hello, {name}!'
|
|
66
127
|
}, {}, {
|
|
@@ -71,6 +132,80 @@ describe('formatMessageFragment', () => {
|
|
|
71
132
|
children: ['Julio']
|
|
72
133
|
}, '!']);
|
|
73
134
|
});
|
|
135
|
+
it('should format pluralization placeholders', () => {
|
|
136
|
+
function format(imagesCount) {
|
|
137
|
+
return formatMessageFragment('en', {
|
|
138
|
+
id: 'images.count',
|
|
139
|
+
defaultMessage: 'default'
|
|
140
|
+
}, I18N, {
|
|
141
|
+
imagesCount
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
expect(format(0)).toEqual(['Images: ', 'no images']);
|
|
145
|
+
expect(format(1)).toEqual(['Images: ', '1', ' image']);
|
|
146
|
+
expect(format(1024)).toEqual(['Images: ', '1024', ' images']);
|
|
147
|
+
});
|
|
148
|
+
it('should do the most minimal support for pluralization placeholders in default messages', () => {
|
|
149
|
+
function format(imagesCount) {
|
|
150
|
+
return formatMessageFragment('en', {
|
|
151
|
+
id: 'images.count',
|
|
152
|
+
defaultMessage: 'Images: {imagesCount, plural, other {IDK}}'
|
|
153
|
+
}, {}, {
|
|
154
|
+
imagesCount
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
expect(format(0)).toEqual(['Images: ', 0]);
|
|
158
|
+
expect(format(1)).toEqual(['Images: ', 1]);
|
|
159
|
+
expect(format(1024)).toEqual(['Images: ', 1024]);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe('parseMessage', () => {
|
|
163
|
+
it('should parse literal string', () => {
|
|
164
|
+
var parsed = parseMessage('Hello world!');
|
|
165
|
+
expect(parsed).toEqual([{
|
|
166
|
+
type: 0,
|
|
167
|
+
value: 'Hello world!'
|
|
168
|
+
}]);
|
|
169
|
+
});
|
|
170
|
+
it('should parse argument placeholders', () => {
|
|
171
|
+
var parsed = parseMessage('Hello {name}!');
|
|
172
|
+
expect(parsed).toEqual([{
|
|
173
|
+
type: 0,
|
|
174
|
+
value: 'Hello '
|
|
175
|
+
}, {
|
|
176
|
+
type: 1,
|
|
177
|
+
value: 'name'
|
|
178
|
+
}, {
|
|
179
|
+
type: 0,
|
|
180
|
+
value: '!'
|
|
181
|
+
}]);
|
|
182
|
+
});
|
|
183
|
+
it('should partially parse plural placeholders as a last resort fallback', () => {
|
|
184
|
+
var parsed = parseMessage('{apples, plural, zero {There are no apples}, one {There is one apple}, other {There are # apples}}');
|
|
185
|
+
expect(parsed).toEqual([{
|
|
186
|
+
type: 1,
|
|
187
|
+
value: 'apples'
|
|
188
|
+
}]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe('tokenizeMessage', () => {
|
|
192
|
+
it('should return a single item array for literal strings', () => {
|
|
193
|
+
var tokens = tokenizeMessage('Hello world');
|
|
194
|
+
expect(tokens).toEqual(['Hello world']);
|
|
195
|
+
});
|
|
196
|
+
it('it should tokenize simple placeholders', () => {
|
|
197
|
+
var tokens = tokenizeMessage('Hello {type} world of {creatures}!');
|
|
198
|
+
expect(tokens).toEqual(['Hello ', '{type}', ' world of ', '{creatures}', '!']);
|
|
199
|
+
});
|
|
200
|
+
it('it should tokenize pluralization placeholders', () => {
|
|
201
|
+
var tokens = tokenizeMessage('Hello {type} world of {count, plural, other {#}} {creatures}!');
|
|
202
|
+
expect(tokens).toEqual(['Hello ', '{type}', ' world of ', '{count, plural, other {#}}', ' ', '{creatures}', '!']);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('getPluralRules', () => {
|
|
206
|
+
test.each(supportedLocales)('should be safe to use with any of the supported locales: %s', locale => {
|
|
207
|
+
expect(getPluralRules(Locale.from(locale).code)).toBeInstanceOf(Intl.PluralRules);
|
|
208
|
+
});
|
|
74
209
|
});
|
|
75
210
|
|
|
76
211
|
/**
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.IntlMessageFormat = void 0;
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
8
|
+
var IntlMessageFormat;
|
|
9
|
+
(function (_IntlMessageFormat) {
|
|
10
|
+
var Type = /*#__PURE__*/function (Type) {
|
|
11
|
+
Type[Type["LITERAL"] = 0] = "LITERAL";
|
|
12
|
+
Type[Type["ARGUMENT"] = 1] = "ARGUMENT";
|
|
13
|
+
Type[Type["PLURAL"] = 6] = "PLURAL";
|
|
14
|
+
Type[Type["POUND"] = 7] = "POUND";
|
|
15
|
+
return Type;
|
|
16
|
+
}({}); // TAG = 8, // Not implemented
|
|
17
|
+
_IntlMessageFormat.Type = Type;
|
|
18
|
+
})(IntlMessageFormat || (exports.IntlMessageFormat = IntlMessageFormat = {}));
|
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
export type IntlDictionary = Partial<Record<string, IntlMessageFormat>>;
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type VarName = string;
|
|
3
|
+
export type IntlMessageFormat = ({
|
|
4
|
+
type: IntlMessageFormat.Type.LITERAL;
|
|
4
5
|
value: string;
|
|
5
|
-
}
|
|
6
|
+
} | {
|
|
7
|
+
type: IntlMessageFormat.Type.ARGUMENT;
|
|
8
|
+
value: VarName;
|
|
9
|
+
} | {
|
|
10
|
+
type: IntlMessageFormat.Type.PLURAL;
|
|
11
|
+
value: VarName;
|
|
12
|
+
pluralType: 'cardinal' | 'ordinal';
|
|
13
|
+
offset: number;
|
|
14
|
+
options: Partial<Record<'zero' | 'one' | 'two' | 'few' | 'many' | `=${number}`, {
|
|
15
|
+
value: IntlMessageFormat;
|
|
16
|
+
}>> & {
|
|
17
|
+
other: {
|
|
18
|
+
value: IntlMessageFormat;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
type: IntlMessageFormat.Type.POUND;
|
|
23
|
+
})[];
|
|
24
|
+
export declare namespace IntlMessageFormat {
|
|
25
|
+
/**
|
|
26
|
+
* @see https://github.com/formatjs/formatjs/blob/df4f21270320237eb5a91fbf74f3f8f51b4ff184/rust/icu-messageformat-parser/src/ast.rs#L212-L262
|
|
27
|
+
*/
|
|
28
|
+
enum Type {
|
|
29
|
+
/**
|
|
30
|
+
* Raw text
|
|
31
|
+
*/
|
|
32
|
+
LITERAL = 0,
|
|
33
|
+
/**
|
|
34
|
+
* Variable without any format, e.g. `var` in `this is a {var}`
|
|
35
|
+
*/
|
|
36
|
+
ARGUMENT = 1,
|
|
37
|
+
/**
|
|
38
|
+
* Variable with plural format
|
|
39
|
+
*/
|
|
40
|
+
PLURAL = 6,
|
|
41
|
+
/**
|
|
42
|
+
* Only possible within plural argument.
|
|
43
|
+
* This is the `#` symbol that will be substituted with the count.
|
|
44
|
+
*/
|
|
45
|
+
POUND = 7
|
|
46
|
+
}
|
|
47
|
+
}
|
|
6
48
|
export interface IntlMessageDescriptor {
|
|
7
49
|
id: string;
|
|
8
50
|
defaultMessage?: string;
|
|
9
51
|
}
|
|
10
52
|
export type IntlMessageValues<T> = Record<string, T>;
|
|
53
|
+
export {};
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
2
|
+
export var IntlMessageFormat;
|
|
3
|
+
(function (_IntlMessageFormat) {
|
|
4
|
+
var Type = /*#__PURE__*/function (Type) {
|
|
5
|
+
Type[Type["LITERAL"] = 0] = "LITERAL";
|
|
6
|
+
Type[Type["ARGUMENT"] = 1] = "ARGUMENT";
|
|
7
|
+
Type[Type["PLURAL"] = 6] = "PLURAL";
|
|
8
|
+
Type[Type["POUND"] = 7] = "POUND";
|
|
9
|
+
return Type;
|
|
10
|
+
}({}); // TAG = 8, // Not implemented
|
|
11
|
+
_IntlMessageFormat.Type = Type;
|
|
12
|
+
})(IntlMessageFormat || (IntlMessageFormat = {}));
|
package/build/i18n/af.json
CHANGED
|
@@ -159,12 +159,98 @@
|
|
|
159
159
|
"value": "Lets het verkeerd geloop. Probeer die vorm weer indien"
|
|
160
160
|
}
|
|
161
161
|
],
|
|
162
|
+
"mediaGallery.imagesCount": [
|
|
163
|
+
{
|
|
164
|
+
"offset": 0,
|
|
165
|
+
"options": {
|
|
166
|
+
"=0": {
|
|
167
|
+
"value": [
|
|
168
|
+
{
|
|
169
|
+
"type": 0,
|
|
170
|
+
"value": "Geen beelde nie"
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
"one": {
|
|
175
|
+
"value": [
|
|
176
|
+
{
|
|
177
|
+
"type": 7
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"type": 0,
|
|
181
|
+
"value": " beeld"
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
"other": {
|
|
186
|
+
"value": [
|
|
187
|
+
{
|
|
188
|
+
"type": 7
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"type": 0,
|
|
192
|
+
"value": " beelde"
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"pluralType": "cardinal",
|
|
198
|
+
"type": 6,
|
|
199
|
+
"value": "imagesCount"
|
|
200
|
+
}
|
|
201
|
+
],
|
|
162
202
|
"mediaGallery.title": [
|
|
163
203
|
{
|
|
164
204
|
"type": 0,
|
|
165
205
|
"value": "Media galerye"
|
|
166
206
|
}
|
|
167
207
|
],
|
|
208
|
+
"mediaGallery.titleSingular": [
|
|
209
|
+
{
|
|
210
|
+
"type": 0,
|
|
211
|
+
"value": "Mediagalery"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"mediaGallery.videosCount": [
|
|
215
|
+
{
|
|
216
|
+
"offset": 0,
|
|
217
|
+
"options": {
|
|
218
|
+
"=0": {
|
|
219
|
+
"value": [
|
|
220
|
+
{
|
|
221
|
+
"type": 0,
|
|
222
|
+
"value": "Geen video's nie"
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
"one": {
|
|
227
|
+
"value": [
|
|
228
|
+
{
|
|
229
|
+
"type": 7
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"type": 0,
|
|
233
|
+
"value": " video"
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
"other": {
|
|
238
|
+
"value": [
|
|
239
|
+
{
|
|
240
|
+
"type": 7
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"type": 0,
|
|
244
|
+
"value": " video's"
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
"pluralType": "cardinal",
|
|
250
|
+
"type": 6,
|
|
251
|
+
"value": "videosCount"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
168
254
|
"misc.embargoMessage": [
|
|
169
255
|
{
|
|
170
256
|
"type": 0,
|
|
@@ -258,7 +344,7 @@
|
|
|
258
344
|
"search.filters": [
|
|
259
345
|
{
|
|
260
346
|
"type": 0,
|
|
261
|
-
"value": "
|
|
347
|
+
"value": "Filtreer"
|
|
262
348
|
}
|
|
263
349
|
],
|
|
264
350
|
"search.fullResultsSubTitle": [
|