Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

fix(translate): escape special character % to prevent crash#138

Open
xavierdeneux wants to merge 1 commit into
masterfrom
fix-specialchars-bug
Open

fix(translate): escape special character % to prevent crash#138
xavierdeneux wants to merge 1 commit into
masterfrom
fix-specialchars-bug

Conversation

@xavierdeneux

@xavierdeneux xavierdeneux commented Feb 18, 2025

Copy link
Copy Markdown

🤔 Why?

I saw an error with one of my preview for EPG and the root cause was the title of the box contained the "%" chars.
Because of this char, the sprintf command failed.

t('my_translation_string%') does not work
(In fact, in my original case, the "translation string" is not really a translation key but an already translated key like t('Mon super programme 100% cool')

image

💻 How?

Escape the "%" chars to prevent sprintf command to crash.

const translatedResult = sprintf(translation, { ...data, ...i18nNames, number });
// escape special characters (% for now)
const translationValues = _mapValues({ ...data, ...i18nNames, number }, value => {
if (value) {

@qtomasicchio qtomasicchio Feb 18, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the unit test, value can be a number. We should probably check that we have a string, what do you think?

Suggested change
if (value) {
if (typeof value === 'string') {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants