Skip to content

Commit 2c8f58d

Browse files
mledlivanhofer
andauthored
feat: plural rule improvement (#708)
* adds test cases for PL to underline issue * adds other as plural fallback values for few and many * use ?? * update sizes * add changelog --------- Co-authored-by: Ivan Hofer <ivan.hofer@outlook.com>
1 parent c207fc5 commit 2c8f58d

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

.size-limit.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,61 @@ module.exports = [
22
{
33
name: 'i18n-string',
44
path: 'dist/i18n.string.min.js',
5-
limit: '945 b',
5+
limit: '948 b',
66
},
77
{
88
name: 'typed-i18n-string',
99
path: 'dist/i18n.typed.string.min.js',
10-
limit: '949 b',
10+
limit: '953 b',
1111
},
1212
{
1313
name: 'i18n-object',
1414
path: 'dist/i18n.object.min.js',
15-
limit: '1086 b',
15+
limit: '1089 b',
1616
},
1717
{
1818
name: 'typed-i18n-object',
1919
path: 'dist/i18n.typed.object.min.js',
20-
limit: '1090 b',
20+
limit: '1095 b',
2121
},
2222
{
2323
name: 'i18n-instance',
2424
path: 'dist/i18n.instance.min.js',
25-
limit: '1117 b',
25+
limit: '1119 b',
2626
},
2727
{
2828
name: 'all together',
2929
path: 'dist/i18n.all.min.js',
30-
limit: '1192 b',
30+
limit: '1194 b',
3131
},
3232
{
3333
name: 'adapter-angular',
3434
path: 'angular/index.min.mjs',
35-
limit: '1225 b',
35+
limit: '1230 b',
3636
ignore: ['angular'],
3737
},
3838
{
3939
name: 'adapter-react',
4040
path: 'react/index.min.mjs',
41-
limit: '1560 b',
41+
limit: '1562 b',
4242
ignore: ['react'],
4343
},
4444
{
4545
name: 'adapter-solid',
4646
path: 'solid/index.min.mjs',
47-
limit: '1402 b',
47+
limit: '1403 b',
4848
ignore: ['solid-js'],
4949
},
5050
{
5151
name: 'adapter-svelte',
5252
path: 'svelte/index.min.mjs',
53-
limit: '1339 b',
53+
limit: '1342 b',
5454
ignore: ['svelte'],
5555
},
5656
{
5757
name: 'adapter-vue',
5858
path: 'vue/index.min.mjs',
59-
limit: '1253 b',
59+
limit: '1256 b',
6060
ignore: ['vue'],
6161
},
6262
]

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
# Version 5
44

5+
## 5.26.0 (2023-08-01)
6+
7+
Feat:
8+
- improved plural rules support for polnish [#672](https://github.com/ivanhofer/typesafe-i18n/issues/672)
9+
510
## 5.25.1 (2023-07-20)
611

712
Fix:

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,18 @@ The footprint of the `typesafe-i18n` package is smaller compared to other existi
233233

234234
These parts are bundled into the [core functions](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#usage). The sizes of the core functionalities are:
235235

236-
- [i18nString](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18nString): 945 bytes gzipped
237-
- [i18nObject](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18nObject): 1086 bytes gzipped
238-
- [i18n](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18n): 1117 bytes gzipped
236+
- [i18nString](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18nString): 948 bytes gzipped
237+
- [i18nObject](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18nObject): 1089 bytes gzipped
238+
- [i18n](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/runtime#i18n): 1119 bytes gzipped
239239

240240
Apart from that there can be a small overhead depending on which utilities and wrappers you use.
241241

242242
There also exists a useful wrapper for some frameworks:
243-
- [`typesafe-i18n` angular-service](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-angular): 1225 bytes gzipped
244-
- [`typesafe-i18n` react-context](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-react): 1560 bytes gzipped
245-
- [`typesafe-i18n` solid-context](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-solid): 1402 bytes gzipped
246-
- [`typesafe-i18n` svelte-store](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-svelte): 1339 bytes gzipped
247-
- [`typesafe-i18n` vue-plugin](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-vue): 1253 bytes gzipped
243+
- [`typesafe-i18n` angular-service](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-angular): 1230 bytes gzipped
244+
- [`typesafe-i18n` react-context](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-react): 1562 bytes gzipped
245+
- [`typesafe-i18n` solid-context](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-solid): 1403 bytes gzipped
246+
- [`typesafe-i18n` svelte-store](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-svelte): 1342 bytes gzipped
247+
- [`typesafe-i18n` vue-plugin](https://github.com/ivanhofer/typesafe-i18n/tree/main/packages/adapter-vue): 1256 bytes gzipped
248248

249249

250250
<!-- ------------------------------------------------------------------------------------------ -->

packages/runtime/src/core.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ const getPlural = (pluralRules: Intl.PluralRules, { z, o, t, f, m, r }: BasicPlu
157157
case 'two':
158158
return t
159159
case 'few':
160-
return f
160+
return f ?? r
161161
case 'many':
162-
return m
162+
return m ?? r
163163
default:
164164
return r
165165
}

packages/runtime/src/util.object.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,16 @@ test('switch-case with comma 2', () =>
267267

268268
// --------------------------------------------------------------------------------------------------------------------
269269

270+
const LL10 = i18nObject('pl', {
271+
MULTIPLE_PARAMS_PLURAL: '{0} banana{{s}} and {1} apple{{s}}',
272+
SINGULAR_PLURAL: '{{ one item | ?? items }}',
273+
})
274+
275+
test('multiple params plural for language without PluralRule other', () =>
276+
assert.is(LL10.MULTIPLE_PARAMS_PLURAL(1, 2), '1 banana and 2 apples'))
277+
test('plural zero: one for language without PluralRule other', () => assert.is(LL10.SINGULAR_PLURAL(1), 'one item'))
278+
test('plural zero: ?? for language without PluralRule other', () => assert.is(LL10.SINGULAR_PLURAL(5), '5 items'))
279+
280+
// --------------------------------------------------------------------------------------------------------------------
281+
270282
test.run()

packages/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// this file gets auto-generated
2-
export const version = '5.25.0'
2+
export const version = '5.25.1'

0 commit comments

Comments
 (0)