<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <b>tl;dr<br>
      <br>
    </b>I tried to switch the main Thunderbird Conversations HTML file
    to XML so that the outer conversation chrome could be localized
    using entities. This played very bad with jquery-templates, and
    since I'm integrating user data, such as emails, conversation
    subjects, etc. etc., I have no control over the well-formedness of
    these strings, and I have to make sure they are all well-formed
    before injecting them into the document. I'm very afraid it'll take
    weeks before all errors are ruled out. Does anyone have an
    alternative solution that will allow me to:<br>
    1) keep the conversations UI file as html,<br>
    2) localize the html tags with a mechanism similar to entities, and<br>
    3) localize the jquery templates?<br>
    <br>
    <b>Full version</b><br>
    <br>
    In the process of localizing Thunderbird Conversations, I had to
    tackle the main conversation UI. The main conversation UI is
    structured as an HTML document (content/stub.html, namely), on which
    various pieces of code operate.<br>
    - modules/message.js gather relevant data and uses jquery-tmpl to
    output each message in the conversation view,<br>
    - content/stub.compose-ui.js takes care of various tasks related to
    setting up the quick reply,<br>
    - content/stub.completion-ui.js fills the "facebook-style"
    autocomplete feature which is provided by,<br>
    - content/js/jquery.tokeninput.js (a plugin I found on teh
    interweb).<br>
    <br>
    I had to localize both a) the HTML from stub.html and b) the HTML
    that's generated by the jquery templates. The HTML from b) is stored
    in <script type="text/tmpl"> nodes, the contents of which or
    NOT to be parsed by the XML parser. This means a CDATA block, so the
    entities solution is not applicable here.<br>
    <br>
    I switched my document to a xhtml file, and here's the errors I
    bumped into:<br>
    - I initially forgot to rename my file from html to xhtml. An XML
    DTD at the beginning of a .html file does not work. You get
    completely unrelated errors (of course), such as "XML cannot be the
    whole program", or whatever, and even the rendering seems to be
    weird (probably something that got interpreted as text at the
    beginning of the document).<br>
    - Once I managed to figure that out, my document was still not
    XML-compliant. The first source of errors was the use of &nsbp;
    entities in the templates. When these were injected in the XML
    document, apparently, the entity was not defined. Solution:
    &#xa0;<br>
    - After that, I had ampersands lying around in the HTML generated by
    the templates − because of URIs, mainly: the template would end up
    generating <img
    src="imap-mail://your/message/then/its/image/attachment" /> with
    an ampersand in the URL. Bam, you're dead. I had to review all the
    data that was passed to the template to make sure it's wrapped in
    escapeHtml() calls.<br>
    - Once that was settled, I managed somehow to get the thing working.
    But the *-ui.js files were still causing me trouble. These were
    using jquery, and it turns out I was writing the following patterns:<br>
    <br>
    $("<li title="+theTitle+">....</li>");<br>
    <br>
    This is wrong, because theTitle will never be checked for quotes,
    ampersands, brackets, etc. and that was causing jquery's internal
    calls to innerHTML to fail, because now the document was switched to
    XML, Gecko expected proper XML to be injected through innerHTML.<br>
    <br>
    - I still had trouble in some parts that were not written by me: my
    "never use someone else's jquery plugin, you'll end up rewriting it
    anyway" rule got verified once again. The "tokeninput" plugin I had
    borrowed, heavily cleaned up and modified, still was wrong. The guy
    was doing $("<input>") without the closing tag, and was doing
    the same wrong pattern I mentioned above.<br>
    <br>
    I finally got it all working, but:<br>
    1) this seems extremely fragile, I'm pretty sure I'll bump into
    string data that may contain <s, >s or &s and that I
    forgot to escape, which means it will fail at some point in the
    future, and<br>
    2) I still haven't found  a way to localize the jquery templates
    yet: I'll probably pass them the localized strings, but still, I
    wish I could deal with that inside the template, not in the code
    that generates the template.<br>
    <br>
    Debugging malformed XML errors is incredibly hard, mainly because
    Gecko does not help you. Since the template data is extremely large,
    the only solution I found was hack into jquery, insert a dump
    statement before the error, and run the HTML through xmllint.<br>
    <br>
    I'm posting this in the hope that people might have a better
    solution, or idea.<br>
    <br>
    1) Any good hints on localizing jquery-templates?<br>
    2) Any way I can have the entities goodness and not force my
    document to be XML?<br>
    <br>
    Thanks for all the comments,<br>
    <br>
    jonathan<br>
  </body>
</html>