ttag-org / ttag

:orange_book: simple approach for javascript localization
https://ttag.js.org/
MIT License
338 stars 41 forks source link

When variable is a money and `$` is used, first 2 chars are removed #193

Open andyWynyard opened 4 years ago

andyWynyard commented 4 years ago

ONLY iOS and Safari

Using your regex in the Safari console: 'hello ${ amount }'.replace(new RegExp(\$\{(?:[\s]+?|\s?)${'amount'}(?:[\s]+?|\s?)}), '$20') gives "hello 0"

We have multi locales and a money function that returns the value in either $ £ or depending on routing. It works fine on everything except the $ variables.

eg: t`Hi there, you have ${amount} avaliable`

This will return Hi there, you have £20 available also is fine. However, with USD it returns Hi there, you have 0 available omitting the first two characters. This happens on any amount.

So another example if it is $3522 it will show 522.

Testing this without ttag it is not broken, so the money function is fine.

Is this a known issue anywhere?

AlexMost commented 4 years ago

Hi @andyWynyard! Thanks for the report. I guess you have found a bug. Can you provide please some minimal js source file to reproduce the case? Something like: source file, expected result, actual result.

andyWynyard commented 4 years ago

@AlexMost As the edit above indicates, the issue comes from the regex and Safari/iOS handling of these things. The bug goes back to 2008 (as far as we found) with this article. We used one of the workarounds listed.

The above info and the linked article outlining the issue should be what you need.