[wp-polyglots] JavaScript seems to break HTML entities
Xavier Borderie
xavier at borderie.net
Sun Nov 9 11:28:40 GMT 2008
(double-posted in wp-testers and wp-polyglots, since it seems to me it
might be of interest to both audiences)
---
This is about the Update Post button in the Publish section.
By default, it is displayed through HTML, but it seems that its title
string is re-assigned through JS at one time.
Case in point:
In French, "Update Post" is translated "Mettre à jour l'article", but
for typographical correctness (in the spirit of our founding father,
Matt's Curly Quotes patch for b2/cafelog :-) ), we chose to translate
it "Mettre à jour l’article".
It works great: the apostrophe (ok, "right single quote", but it reads
better than ') is there in the button and all the strings where
it's needed (and there are quite a few).
BUT, if I click the Edit link from the "Published on..." line to open
the scheduling tool, and then hit cancel, the button text gets updated
to "Mettre à jour l’article" litterally before the tool closes:
the ’ is no longer turned into a quote, it's just there.
I'm guessing this is due to JS not parsing HTML entities. Could it be
made to? Or should I forget about typographical correctness
altogether?
---
Additionally, and in the same typographical spirit, we chose to
translate the date() arguments from "g:i:s a" to "G \\h i \\m\\i\\n s
\\s", as it should be
(http://fr.wikipedia.org/wiki/Heure_(temps)#Typographie_de_l.27heure).
Typographically, as you can see, we need spaces between the time value
and its symbol, and that brings to parts being sent to the next line.
In this particular example
(http://trac.wordpress.org/browser/trunk/wp-admin/admin-ajax.php#L722),
I thought I solved it by using HTML entities for non-breaking spaces:
"G \\h i \\m\\i\\n s \\s", quite a mouthful,
sure, but it seems to work.
But once the current edit is autosaved (using Ajax, hence JS/DOM
update to the string), the string is rendered like this: "Brouillon
enregistré à 11&11b51p;h&11b51p;27&11b51p;min&11b51p;51&11b51p;s".
The "Last edited by %1$s on %2$s at %3$s" line does work as expected,
though: it renders "Dernière modification par admin, le 9 novembre
2008 à 11 h 26 min 45 s", which is correct.
The "M j, Y @ G:i|Publish box date format" line I had to trick-out,
since it wouldn't display the 's as expected. After many trials
and errors, I came up with "j F Y
à\\&\\n\\b\\s\\p\\;G\\&\\n\\b\\s\\p\\;\\h\\&\\n\\b\\s\\p\\;i\\&\\n\\b\\s\\p\\;\\m\\i\\n"
- yes, escaping each non-date characters, so each character from the
's. That gets tough to read, but at least it seems to work: it
displays...
Publié le : 27 octobre 2008
à 11 h 01 min Modifier
...and not...
Publié le : 27 octobre 2008 à 11
h 01 min Modifier
The "j F, Y @ G:i|revision date format" line also gets the "j F Y
à\\&\\n\\b\\s\\p\\;G\\&\\n\\b\\s\\p\\;\\h\\&\\n\\b\\s\\p\\;i\\&\\n\\b\\s\\p\\;\\m\\i\\n"
treatement, even if it's not as much needed, but it works.
--
That's why it seems the issue stems from JavaScript not taking HTML
entities into account - or rather, taking them too literally. Isn't
there a way to have to work properly? Like adding an entities-filter
to all JS string-updating code?
This would be mucho-safe, since locale translations use entities kinda
everywhere: "word ?", "word :", "« %s »" (or
even, "« %s »"), etc.
We pride ourselves in having a typographically-correct translation,
and I would hate to have to revert back - although in this case, we're
just talking of a couple exceptions here and there, which I can live
with, sure, but still :-)
--
Xavier Borderie
More information about the wp-polyglots
mailing list