Skip to content

Using str() to localize expressions #2270

Answered by aomarks
jeromecambon asked this question in Q&A
Discussion options

You must be logged in to vote

I'm trying to localize a property, using the str() function as specified in the doc:

The str tag is only needed if you need to put expressions inside a plain string. Otherwise you can directly pass a string to msg.

Valid:

msg('Hello world');
msg(str`Hello ${name}`)
msg(html`Hello <b>world</b>`);
msg(html`Hello <b>${name}</b>`);

Invalid:

msg(`Hello ${name}`)

(The str tag is needed when there are expressions because otherwise we receive a string where expressions are already interpolated into a plain string, so it wouldn't be possible to update the template with a translation and substitute a new expression into the placeholder).

I would expect that my html label is translated when the…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jeromecambon
Comment options

@aomarks
Comment options

@jeromecambon
Comment options

Answer selected by jeromecambon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants