Skip to content

Commit 47a1ad7

Browse files
fix(core): remove runtime whitespace trimming aligned with v5 (#2169)
1 parent f7b2392 commit 47a1ad7

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

packages/core/src/i18n.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe("I18n", () => {
215215
id: "My name is {name}",
216216
message: "Je m'appelle {name}",
217217
})
218-
).toEqual("Je m'appelle")
218+
).toEqual("Je m'appelle ")
219219

220220
// Untranslated message
221221
expect(i18n._("Missing message")).toEqual("Missing message")
@@ -263,6 +263,23 @@ describe("I18n", () => {
263263
).toEqual("Mi 'nombre' es {name}")
264264
})
265265

266+
it("._ should not trim whitespaces in translated messages", () => {
267+
const messages = {}
268+
269+
const i18n = setupI18n({
270+
locale: "es",
271+
messages: { es: messages },
272+
})
273+
274+
expect(
275+
i18n._({
276+
id: "msg",
277+
/* note the space at the end */
278+
message: " Hello ",
279+
})
280+
).toEqual(" Hello ")
281+
})
282+
266283
it("._ shouldn't compile uncompiled messages in production", () => {
267284
const messages = {
268285
Hello: "Salut",

packages/core/src/interpolate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("interpolate", () => {
4444
expect(plural({ value: 1 })).toEqual("1 Book")
4545
expect(plural({ value: 2 })).toEqual("2 Books")
4646
expect(plural({ value: 4 })).toEqual("Four books")
47-
expect(plural({ value: 99 })).toEqual("Books with problems")
47+
expect(plural({ value: 99 })).toEqual(" Books with problems ")
4848

4949
const offset = prepare(
5050
"{value, plural, offset:1 =0 {No Books} one {# Book} other {# Books}}"

packages/core/src/interpolate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ export function interpolate(
152152
// convert raw unicode sequences back to normal strings
153153
// note JSON.parse hack is not working as you might expect https://stackoverflow.com/a/57560631/2210610
154154
// that's why special library for that purpose is used
155-
return unraw(result.trim())
155+
return unraw(result)
156156
}
157-
if (isString(result)) return result.trim()
157+
if (isString(result)) return result
158158
return result ? String(result) : ""
159159
}
160160
}

0 commit comments

Comments
 (0)