cibernox / cibernox/precompile-intl-runtime
Wrong arguments if too much values
- Dominant language
- TypeScript
- Stars
- 11
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
If I pass more values to `$t` then there are arguments in the message, the arguments may get the wrong values.
**Example**
I have these strings in the language file:
```json
{
"message": {
"one": "{name} sent you 1 file",
"other": "{name} sent you {count} files"
}
}
```
Both messages are called with the same options:
```js
// This is a function that returns the correct string based on the `count` value, because we cannot use ICU expressions
function pluralization(id, options) {
if (options.values.count === 1) {
return $t(`${id}.one`, options);
} else {
return $t(`${id}.other`, options);
}
}
console.log(pluralization('message', {values: {count: 1, name: 'John'}));
console.log(pluralization('message', {values: {count: 2, name: 'John'}));
```
This results in these result:
```
1 sent you 1 file
John sent you 2 files
```
**Expected behavior**
The arguments should be set correctly, even if there are too much values.
```
John sent you 1 file
John sent you 2 files
```
**Workaround**
Currently, we have to set the static `1` as a variable too.
```json
{
"one": "{name} sent you {count} file",
"other": "{name} sent you {count} files"
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.