Skip to content

Commit 0c5ac4f

Browse files
authored
i18next@25 (#95)
1 parent 9e072de commit 0c5ac4f

File tree

6 files changed

+97
-36
lines changed

6 files changed

+97
-36
lines changed

.changeset/honest-panthers-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@withease/i18next': major
3+
---
4+
5+
Support i18next@25

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"effector-vue": "23.0.0",
2525
"estree-walker": "^3.0.3",
2626
"glob": "^8.0.3",
27-
"i18next": "24.0.0",
27+
"i18next": "25.0.0",
2828
"markdown": "^0.5.0",
2929
"playwright": "^1.32.2",
3030
"prettier": "^2.6.2",

packages/i18next/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"peerDependencies": {
66
"effector": "^22.5.0 || ^23.0.0",
7-
"i18next": "^23.0.0 || ^24.0.0"
7+
"i18next": "^23.0.0 || ^24.0.0 || ^25.0.0"
88
},
99
"scripts": {
1010
"test:run": "vitest run --typecheck",
@@ -35,7 +35,7 @@
3535
"size-limit": [
3636
{
3737
"path": "./dist/i18next.js",
38-
"limit": "1.26 kB"
38+
"limit": "1.33 kB"
3939
}
4040
]
4141
}

packages/i18next/src/integration.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ export function createI18nextIntegration({
176176
): Store<string> {
177177
return combine(
178178
{ t: $t, variables: combine(variables ?? {}) },
179-
({ t, variables }) => t(key, variables) ?? key
179+
({ t, variables }) =>
180+
t(
181+
key,
182+
// since i18next@25 t-function mutates variables object,
183+
// so we spread it to avoid mutating original object
184+
{ ...variables }
185+
) ?? key
180186
);
181187
}
182188

packages/i18next/src/translated.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ describe('integration.translated', () => {
2727

2828
expect(scope.getState($result)).toBe('valueOne');
2929
});
30+
31+
test('supports simple key and language change', async () => {
32+
const instance = createInstance({
33+
resources: {
34+
th: { common: { key: 'valueOne' } },
35+
en: { common: { key: 'valueTwo' } },
36+
},
37+
lng: 'th',
38+
});
39+
40+
const setup = createEvent();
41+
42+
const { translated, changeLanguageFx } = createI18nextIntegration({
43+
instance,
44+
setup,
45+
});
46+
47+
const $result = translated('common:key');
48+
49+
const scope = fork();
50+
51+
await allSettled(setup, { scope });
52+
53+
expect(scope.getState($result)).toBe('valueOne');
54+
55+
await allSettled(changeLanguageFx, { scope, params: 'en' });
56+
57+
expect(scope.getState($result)).toBe('valueTwo');
58+
});
3059
});
3160

3261
describe('overload: template literal', () => {
@@ -87,5 +116,40 @@ describe('integration.translated', () => {
87116

88117
expect(scope.getState($result)).toBe('valueOne kek');
89118
});
119+
120+
test('changes after language changed', async () => {
121+
const instance = createInstance({
122+
resources: {
123+
th: { common: { key: 'valueOne {{name}}' } },
124+
en: { common: { key: 'valueTwo {{name}}' } },
125+
},
126+
lng: 'th',
127+
});
128+
129+
const setup = createEvent();
130+
131+
const { translated, changeLanguageFx } = createI18nextIntegration({
132+
instance,
133+
setup,
134+
});
135+
136+
const $name = createStore('wow');
137+
138+
const $result = translated('common:key', { name: $name });
139+
140+
const scope = fork();
141+
142+
await allSettled(setup, { scope });
143+
144+
expect(scope.getState($result)).toBe('valueOne wow');
145+
146+
await allSettled(changeLanguageFx, { scope, params: 'en' });
147+
148+
expect(scope.getState($result)).toBe('valueTwo wow');
149+
150+
await allSettled($name, { scope, params: 'kek' });
151+
152+
expect(scope.getState($result)).toBe('valueTwo kek');
153+
});
90154
});
91155
});

pnpm-lock.yaml

Lines changed: 18 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)