Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when ICU messages contains html tags #310

Open
shtumi opened this issue Dec 26, 2020 · 3 comments
Open

Problem when ICU messages contains html tags #310

shtumi opened this issue Dec 26, 2020 · 3 comments

Comments

@shtumi
Copy link

shtumi commented Dec 26, 2020

When I have translation id like this:

translation.id:
  {count, plural,
    one {<b>1</b> item}
    other {<b>{count}</b> items}
  }

it doesn't work in js with

Translator.trans('translation.id', { count: 23});

because official documentation of intl-messageformat says that tags should be quoted (because if not it assume b is variable.
https://formatjs.io/docs/intl-messageformat/

So it should be like:

translation.id:
  {count, plural,
    one {'<b>'1'</b>' item}
    other {'<b>'{count}'</b>' items}
  }

But when I try this format in twig:

{{ 'translation.id'|trans({count: 23}) }}

then I face to error:
An exception has been thrown during the rendering of a template ("Invalid message format (error #65801): msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES").

@shtumi
Copy link
Author

shtumi commented Dec 26, 2020

pull request #311 added

sustmi added a commit to sustmi/BazingaJsTranslationBundle that referenced this issue Sep 21, 2021
sustmi added a commit to sustmi/BazingaJsTranslationBundle that referenced this issue Sep 22, 2021
@sustmi
Copy link
Contributor

sustmi commented Sep 22, 2021

I created a new pull-request that fixes this issue using ignoreTag option of IntlMessageFormat constructor: #325

The escaping that @shtumi proposed in #311 might work too but I believe that using the ignoreTag option is the way this is supposed to be solved according to the documentation:

ignoreTag: Whether to treat HTML/XML tags as string literal instead of parsing them as tag token.

See: https://formatjs.io/docs/intl-messageformat/#intlmessageformat-constructor

monteiro pushed a commit that referenced this issue Nov 19, 2021
@Kocal
Copy link
Contributor

Kocal commented Oct 28, 2022

This issue can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants