Skip to content

Commit a2fa744

Browse files
author
Sebi Nemeth
committed
change filtering method
1 parent cfb3ce9 commit a2fa744

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

dist/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,17 @@ class LiveTranslatorManager {
147147
const original = originalFormatter.interpolate(message, values, path);
148148
let meta = '';
149149
try {
150-
const hasNestedValues = !!values && Object.values(values).some(v => typeof v === 'object');
150+
// filter nested objects, replace inner objects with string 'object'
151+
// this is needed when values from <i18n> tags are circular dependent objects
152+
const filteredValues = Object.fromEntries(Object.entries(values || {})
153+
.map(([key, value]) => [key, typeof value !== 'object' ? value : 'object']));
151154
meta = ZeroWidthEncoder.encode(JSON.stringify({
152155
message,
153-
values: !hasNestedValues ? values : null,
156+
values: filteredValues,
154157
path,
155158
locale: self._options.i18n.locale,
156159
}));
160+
console.log(values);
157161
}
158162
catch (exception) {
159163
console.warn(message, values, path, self._options.i18n.locale, exception);

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,25 @@ class LiveTranslatorManager {
168168
const originalFormatter = this._options.i18n.formatter
169169
const self = this
170170
this._options.i18n.formatter = {
171-
interpolate (message, values, path) {
171+
interpolate (message: string, values: object | null, path: string) {
172172
const original = originalFormatter.interpolate(message, values, path) as unknown[] | null
173173
let meta = ''
174174
try {
175-
const hasNestedValues =
176-
!!values && Object.values(values).some(v => typeof v === 'object')
175+
// filter nested objects, replace inner objects with string 'object'
176+
// this is needed when values from <i18n> tags are circular dependent objects
177+
const filteredValues = Object.fromEntries(
178+
Object.entries(values || {})
179+
.map(([key, value]) => [key, typeof value !== 'object' ? value : 'object'])
180+
)
177181
meta = ZeroWidthEncoder.encode(
178182
JSON.stringify({
179183
message,
180-
values: !hasNestedValues ? values : null,
184+
values: filteredValues,
181185
path,
182186
locale: self._options.i18n.locale,
183187
} as TranslationMeta),
184188
)
189+
console.log(values)
185190
} catch (exception) {
186191
console.warn(message, values, path, self._options.i18n.locale, exception)
187192
}

0 commit comments

Comments
 (0)