praekeltfoundation / jspot

Extracts gettext strings from Javascript files into pot files
BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

Handle single & double quote #29

Closed JSteunou closed 10 years ago

JSteunou commented 10 years ago

Should fix issue #27

This issue comes when in handlebars you have this kind of thing

{{{sprintf (gettext '<span class="counter">%s</span> foo' '<span class="counter">%s</span> foos' much) much }}}

It's a weird case where HTML is included in string to translate because you want another typo or font size for the variable but in a big long sentence. As you want to preserve localization, because in some other language the variable can be set in another place in the sentence, you include it in the sentence to translate.

So... double quote in the sentence...

And the hbs extractors transforms it to JS like function before calling execution in gettext context

gettext("<span class="counter">%s</span> foo", "<span class="counter">%s</span> foos", 0)

See how double quote ruins everything.

This PR fixes it by choosing which quote to use, single or double.

justinvdm commented 10 years ago

Ah, I see the use case for html in the strings, thanks for the explanation. Looks good, merging.

justinvdm commented 10 years ago

Oh, actually, just noticed something, commenting.

justinvdm commented 10 years ago

Looks good, just a request for that extra test for the mixed quotes case.

JSteunou commented 10 years ago

Just added it :)

I even have the luxe to get the line, column and filename for the error message!

justinvdm commented 10 years ago

\o/ awesome :) merging