format-message / message-format-rb

Parse and format i18n messages using ICU MessageFormat patterns
MIT License
17 stars 14 forks source link

Simple argument interpolation does not work without spaces around #4

Closed ghostd closed 7 years ago

ghostd commented 7 years ago

Hi,

The following code:

message = MessageFormat.new("<a href='{link_service}'>", 'en-US')
puts message.format({ :link_service => 'http://www.google.com' })

does not work:

<a href={link_service}>

But the following code:

message = MessageFormat.new("<a href=' {link_service} '>", 'en-US')
puts message.format({ :link_service => 'http://www.google.com' })

does work:

<a href=' http://www.google.com '>

Regards

vanwagonet commented 7 years ago

That is because ' is used to escape the special character {. This is working as expected with the rules for ICU MessageFormat. The space makes it so the ' is no longer followed directly by a character that needs escaping.

As a side note, do you really want translators to translate your html tags?

ghostd commented 7 years ago

Ok, thanks for the explanation. I didn't note the quote is an escape marker.