Skip to content

Commit a4d7df1

Browse files
committed
feat: Add "/" as possible trans delimiter
1 parent 3b836c9 commit a4d7df1

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ export class I18n {
337337
* Get the translation for the given key and watch for any changes.
338338
*/
339339
wTrans(key: string, replacements: ReplacementsInterface = {}): ComputedRef<string> {
340+
key = key.replace(/\//g, '.')
341+
340342
if (!this.activeMessages[key]) {
341343
const hasChildItems = this.activeMessages[`${key}.0`] !== undefined
342344

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
return [
4+
'is_electric' => 'É elétrico?',
5+
'foo' => [
6+
'level1' => [
7+
'level2' => 'barpt',
8+
]
9+
]
10+
];

test/translate.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,10 @@ it('translates a possible nested item, and if not exists check on the root level
191191
await global.mountPlugin(undefined, 'pt');
192192
expect(trans('foo.bar')).toBe('baz');
193193
});
194+
195+
it('translates a nested file item while using "/" and "." at the same time as a delimiter', async () => {
196+
await global.mountPlugin()
197+
198+
expect(trans('nested/cars/car.is_electric')).toBe('É elétrico?');
199+
expect(trans('nested/cars/car.foo.level1.level2')).toBe('barpt');
200+
})

0 commit comments

Comments
 (0)