File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -175,8 +175,13 @@ export function createI18nextIntegration({
175
175
variables ?: Record < string , Store < string > >
176
176
) : Store < string > {
177
177
return combine (
178
- { t : $t , variables : combine ( variables ?? { } ) } ,
179
- ( { t, variables } ) => t ( key , variables ) ?? key
178
+ {
179
+ t : $t ,
180
+ variables : variables
181
+ ? combine ( variables )
182
+ : createStore ( null , { serialize : 'ignore' } ) ,
183
+ } ,
184
+ ( { t, variables } ) => t ( key , variables ?? undefined ) ?? key
180
185
) ;
181
186
}
182
187
Original file line number Diff line number Diff line change @@ -116,5 +116,40 @@ describe('integration.translated', () => {
116
116
117
117
expect ( scope . getState ( $result ) ) . toBe ( 'valueOne kek' ) ;
118
118
} ) ;
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
+ } ) ;
119
154
} ) ;
120
155
} ) ;
You can’t perform that action at this time.
0 commit comments