Skip to content

Commit

Permalink
fix(core): remove runtime whitespace trimming aligned with v5
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Jan 30, 2025
1 parent 20d8478 commit 3f0caa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion packages/core/src/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe("I18n", () => {
id: "My name is {name}",
message: "Je m'appelle {name}",
})
).toEqual("Je m'appelle")
).toEqual("Je m'appelle ")

// Untranslated message
expect(i18n._("Missing message")).toEqual("Missing message")
Expand Down Expand Up @@ -263,6 +263,23 @@ describe("I18n", () => {
).toEqual("Mi 'nombre' es {name}")
})

it("._ should not trim whitespaces in translated messages", () => {
const messages = {}

const i18n = setupI18n({
locale: "es",
messages: { es: messages },
})

expect(
i18n._({
id: "msg",
/* note the space at the end */
message: " Hello ",
})
).toEqual(" Hello ")
})

it("._ shouldn't compile uncompiled messages in production", () => {
const messages = {
Hello: "Salut",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/interpolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ export function interpolate(
// convert raw unicode sequences back to normal strings
// note JSON.parse hack is not working as you might expect https://stackoverflow.com/a/57560631/2210610
// that's why special library for that purpose is used
return unraw(result.trim())
return unraw(result)
}
if (isString(result)) return result.trim()
if (isString(result)) return result
return result ? String(result) : ""
}
}

0 comments on commit 3f0caa1

Please sign in to comment.