Discussion:
[Wt-interest] WTemplates, WString, UTF-8 and operator<<
Aarón Bueno Villares
2016-10-28 06:43:45 UTC
Permalink
I was trying to bind a simple string to a `WTemplate`, containing a euro
sign:

<message id="msg">60€</message>

tmpl->bindString("placeholder", tr("msg"));

But instead of render the € symbol, a ? is written in the HTML output
instead. That's is because, when rendering the template, if a variable
placeholder is binded to a string instead of a widget, the string
(`WString` internally) is written to the stream using `operator<<`
(WTemplate::resolveString).

And the implementation of `operator<<` pass forcefully through
`Wt::narrow`, which discards non-ASCII-7 symbols (like €), replacing them
by '?'.

I tried to change € by &euro;, but, when parsing the localized string file,
code entities are replace by their unicode versions (which are later
replaced by ? when writting to the buffer).

My only change is to bind a `WText` instead of a string:

tmpl->bindWidget("placeholder", new Wt::WText(tr("msg")));

And the € symbol is correctly displayed.

Is that a bug? Is still present in current versions? (mine is 3.3.4).
Koen Deforche
2016-10-28 12:05:17 UTC
Permalink
Hey,

That sounds like a bug which has been fixed since as I now read:

StringMap::const_iterator i = strings_.find(varName);
if (i != strings_.end())
result << i->second.toUTF8();

(I can't recall a bug or a fix though)

Regards,
koen

Loading...