代码之家  ›  专栏  ›  技术社区  ›  vip

如何翻译随site.html添加的Trac自定义内容?

  •  0
  • vip  · 技术社区  · 10 年前

    我们定制了Trac实例,以向 newticket page ,包括以下内容 site.html 文件(如中所述 documentation ):

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:py="http://genshi.edgewall.org/"
          py:strip="">
        <form py:match="div[@id='content' and @class='ticket']/form[@action='/newticket#ticket']" py:attrs="select('@*')">
          <div class="warning">
            <p>You are about to create a new JOSM ticket.
            </p>
            <p>Please make sure to always use this link in <a href="wiki/Help/Action/About">About Dialog</a> (Shift-F1) to come here:</p>
            <img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
            <p>Clicking on this link prefills the bug report with useful information for us (<a href="wiki/Help/Action/ShowStatusReport">Status Report</a>).
            </p>
            <p>In any case, don't be shy :) Please let us a way to contact you if needed (either by <a href="register">creating an account</a> or entering your e-mail address below (it won't be publicly visible but will allow us to reach you, and you will be notified about ticket progress).
            </p>
          </div>
          ${select('*')}
        </form>
    </html>
    

    我在文档中没有看到任何关于翻译的内容。我们现在如何翻译这篇课文?

    2 回复  |  直到 10 年前
        1
  •  2
  •   hasienda    10 年前

    不幸的是,这并不容易,直到 proposal for custom labels 已经实现。

    目前,它需要将额外的msgid添加到Trac核心PO文件中,并重新编译和安装自定义的Trac版本-非常难看,而且无法像模板那样远程修改。

    在插件中提供自定义翻译将不会有效,因为插件翻译将驻留在翻译域中,这对于Trac核心模板(如(新)票据页面)来说是不评估的。

        2
  •  0
  •   vip    10 年前

    我终于想出了一个小的JavaScript解决方案。

    当你只需要几种语言的文本不变时,这很简单:

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:py="http://genshi.edgewall.org/"
          py:strip="">
        <form py:match="div[@id='content' and @class='ticket']/form[@action='/newticket#ticket']" py:attrs="select('@*')">
          <div class="warning">
            <table style="border:0; border-collapse:separate; border-spacing:0 10px" class="wiki">
            <tr><td style="background:#FFFC75; border:1px solid #ccc; border-right:0" valign="top">
            <p id="josm_warning_01">You are about to create a new JOSM ticket.
            </p>
            <p id="josm_warning_02">Please make sure to always use <a href="wiki/Help/Action/ReportBug">Help/Report bug</a> or this link in <a href="wiki/Help/Action/About">About Dialog</a> (Shift-F1) to come here:</p>
            <img src="raw-attachment/wiki/Help/Action/ReportBug/reportbug.png" alt="Bug report menu entry" height="84" width="207" />
            <img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
            </td></tr>
            </table>
          </div>
          <script type="text/javascript">
    
    if (navigator.language.indexOf('fr') == 0) {
      document.getElementById("josm_warning_01").innerHTML = 'Vous êtes sur le point de créer un nouveau ticket JOSM.';
      document.getElementById("josm_warning_02").innerHTML = 'S\'il vous plaît, assurez-vous de toujours utiliser <a href="wiki/Help/Action/ReportBug">Aide/Rapporter un bug</a> ou ce lien dans la <a href="wiki/Help/Action/About">fenêtre À propos</a> (Shift-F1) pour venir ici:';
    
    } else if (navigator.language.indexOf('de') == 0) {
      document.getElementById("josm_warning_01").innerHTML = 'Sie sind dabei, ein neues JOSM-Ticket zu erstellen.';
      document.getElementById("josm_warning_02").innerHTML = 'Bitte nutzen Sie immer <a href="wiki/De:Help/Action/ReportBug">Hilfe → Fehler melden</a> oder diesen Link im <a href="wiki/De:Help/Action/About">"Über JOSM..."-Fenster</a>, um hierher zu gelangen:';
    }
          </script>
          ${select('*')}
        </form>
    </html>