home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / xml / gnome / xslt / gettext / gettext.xsl next >
Encoding:
Extensible Markup Language  |  2009-03-17  |  36.7 KB  |  1,016 lines

  1. <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
  2. <!--
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU Lesser General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option) any
  6. later version.
  7.  
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  11. details.
  12.  
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; see the file COPYING.LGPL.  If not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA.
  17. -->
  18.  
  19. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20.                 xmlns:msg="http://www.gnome.org/~shaunm/gnome-doc-utils/l10n"
  21.                 version="1.0">
  22.  
  23. <!--!!==========================================================================
  24. Localized Strings
  25. -->
  26.  
  27. <xsl:variable name="l10n" select="document('l10n.xml')"/>
  28. <xsl:key name="msg" match="msg:msgset/msg:msg"
  29.          use="concat(../msg:msgid, '__LC__', @xml:lang)"/>
  30.  
  31.  
  32. <!--@@==========================================================================
  33. l10n.locale
  34. The top-level locale of the document
  35. -->
  36. <xsl:param name="l10n.locale">
  37.   <xsl:choose>
  38.     <xsl:when test="/*/@xml:lang">
  39.       <xsl:value-of select="/*/@xml:lang"/>
  40.     </xsl:when>
  41.     <xsl:when test="/*/@lang">
  42.       <xsl:value-of select="/*/@lang"/>
  43.     </xsl:when>
  44.   </xsl:choose>
  45. </xsl:param>
  46.  
  47.  
  48. <!--@@==========================================================================
  49. l10n.language
  50. The language part of the top-level locale of the document
  51. -->
  52. <xsl:param name="l10n.language">
  53.   <xsl:choose>
  54.     <xsl:when test="contains($l10n.locale, '_')">
  55.       <xsl:value-of select="substring-before($l10n.locale, '_')"/>
  56.     </xsl:when>
  57.     <xsl:when test="contains($l10n.locale, '@')">
  58.       <xsl:value-of select="substring-before($l10n.locale, '@')"/>
  59.     </xsl:when>
  60.     <xsl:when test="contains($l10n.locale, '_')">
  61.       <xsl:value-of select="substring-before($l10n.locale, '@')"/>
  62.     </xsl:when>
  63.     <xsl:otherwise>
  64.       <xsl:value-of select="$l10n.locale"/>
  65.     </xsl:otherwise>
  66.   </xsl:choose>
  67. </xsl:param>
  68.  
  69.  
  70. <!--@@==========================================================================
  71. l10n.region
  72. The region part of the top-level locale of the document
  73. -->
  74. <xsl:param name="l10n.region">
  75.   <xsl:variable name="aft" select="substring-after($l10n.locale, '_')"/>
  76.   <xsl:choose>
  77.     <xsl:when test="contains($aft, '@')">
  78.       <xsl:value-of select="substring-before($aft, '@')"/>
  79.     </xsl:when>
  80.     <xsl:when test="contains($aft, '.')">
  81.       <xsl:value-of select="substring-before($aft, '.')"/>
  82.     </xsl:when>
  83.     <xsl:otherwise>
  84.       <xsl:value-of select="$aft"/>
  85.     </xsl:otherwise>
  86.   </xsl:choose>
  87. </xsl:param>
  88.  
  89.  
  90. <!--@@==========================================================================
  91. l10n.variant
  92. The variant part of the top-level locale of the document
  93. -->
  94. <xsl:param name="l10n.variant">
  95.   <xsl:variable name="aft" select="substring-after($l10n.locale, '@')"/>
  96.   <xsl:choose>
  97.     <xsl:when test="contains($aft, '.')">
  98.       <xsl:value-of select="substring-before($aft, '.')"/>
  99.     </xsl:when>
  100.     <xsl:otherwise>
  101.       <xsl:value-of select="$aft"/>
  102.     </xsl:otherwise>
  103.   </xsl:choose>
  104. </xsl:param>
  105.  
  106.  
  107. <!--@@==========================================================================
  108. l10n.charset
  109. The charset part of the top-level locale of the document
  110. -->
  111. <xsl:param name="l10n.charset">
  112.   <xsl:if test="contains($l10n.locale, '.')">
  113.     <xsl:value-of select="substring-after($l10n.locale, '.')"/>
  114.   </xsl:if>
  115. </xsl:param>
  116.  
  117.  
  118. <!--**==========================================================================
  119. l10n.gettext
  120. Looks up the translation for a string
  121. $msgid: The id of the string to look up, often the string in the C locale
  122. $lang: The locale to use when looking up the translated string
  123. $lang_language: The language portion of the ${lang}
  124. $lang_region: The region portion of ${lang}
  125. $lang_variant: The variant portion of ${lang}
  126. $lang_charset: The charset portion of ${lang}
  127. $number: The cardinality for plural-form lookups
  128. $form: The form name for plural-form lookups
  129.  
  130. REMARK: Lots of documentation is needed
  131. -->
  132. <xsl:template name="l10n.gettext">
  133.   <xsl:param name="msgid"/>
  134.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  135.   <xsl:param name="lang_language">
  136.     <xsl:call-template name="l10n.language">
  137.       <xsl:with-param name="lang" select="$lang"/>
  138.     </xsl:call-template>
  139.   </xsl:param>
  140.   <xsl:param name="lang_region">
  141.     <xsl:call-template name="l10n.region">
  142.       <xsl:with-param name="lang" select="$lang"/>
  143.     </xsl:call-template>
  144.   </xsl:param>
  145.   <xsl:param name="lang_variant">
  146.     <xsl:call-template name="l10n.variant">
  147.       <xsl:with-param name="lang" select="$lang"/>
  148.     </xsl:call-template>
  149.   </xsl:param>
  150.   <xsl:param name="lang_charset">
  151.     <xsl:call-template name="l10n.charset">
  152.       <xsl:with-param name="lang" select="$lang"/>
  153.     </xsl:call-template>
  154.   </xsl:param>
  155.   <xsl:param name="number"/>
  156.   <xsl:param name="form">
  157.     <xsl:if test="$number">
  158.       <xsl:call-template name="l10n.plural.form">
  159.         <xsl:with-param name="number" select="$number"/>
  160.         <xsl:with-param name="lang" select="$lang"/>
  161.         <xsl:with-param name="lang_language" select="$lang_language"/>
  162.         <xsl:with-param name="lang_region"   select="$lang_region"/>
  163.         <xsl:with-param name="lang_variant"  select="$lang_variant"/>
  164.         <xsl:with-param name="lang_charset"  select="$lang_charset"/>
  165.       </xsl:call-template>
  166.     </xsl:if>
  167.   </xsl:param>
  168.   <xsl:param name="node" select="."/>
  169.   <xsl:param name="role" select="''"/>
  170.   <xsl:param name="string"/>
  171.   <xsl:param name="format" select="false()"/>
  172.  
  173.   <xsl:for-each select="$l10n">
  174.     <xsl:choose>
  175.       <!-- fe_fi@fo.fum -->
  176.       <xsl:when test="($lang_region and $lang_variant and $lang_charset) and
  177.                       key('msg', concat($msgid, '__LC__',
  178.                                         $lang_language, '_', $lang_region,
  179.                                                         '@', $lang_variant,
  180.                                                         '.', $lang_charset))">
  181.         <xsl:call-template name="l10n.gettext.msg">
  182.           <xsl:with-param
  183.            name="msg"
  184.            select="key('msg', concat($msgid, '__LC__',
  185.                                      $lang_language, '_', $lang_region,
  186.                                                      '@', $lang_variant,
  187.                                                      '.', $lang_charset))"/>
  188.           <xsl:with-param name="form" select="$form"/>
  189.           <xsl:with-param name="node" select="$node"/>
  190.           <xsl:with-param name="role" select="$role"/>
  191.           <xsl:with-param name="string" select="$string"/>
  192.           <xsl:with-param name="format" select="$format"/>
  193.         </xsl:call-template>
  194.       </xsl:when>
  195.       <!-- fe_fi@fo -->
  196.       <xsl:when test="($lang_region and $lang_variant) and
  197.                       key('msg', concat($msgid, '__LC__',
  198.                                         $lang_language, '_', $lang_region,
  199.                                                         '@', $lang_variant))">
  200.         <xsl:call-template name="l10n.gettext.msg">
  201.           <xsl:with-param
  202.            name="msg"
  203.            select="key('msg', concat($msgid, '__LC__',
  204.                                      $lang_language, '_', $lang_region,
  205.                                                      '@', $lang_variant))"/>
  206.           <xsl:with-param name="form" select="$form"/>
  207.           <xsl:with-param name="node" select="$node"/>
  208.           <xsl:with-param name="role" select="$role"/>
  209.           <xsl:with-param name="string" select="$string"/>
  210.           <xsl:with-param name="format" select="$format"/>
  211.         </xsl:call-template>
  212.       </xsl:when>
  213.       <!-- fe@fo.fum -->
  214.       <xsl:when test="($lang_variant and $lang_charset) and
  215.                       key('msg', concat($msgid, '__LC__',
  216.                                         $lang_language, '@', $lang_variant,
  217.                                                         '.', $lang_charset))">
  218.         <xsl:call-template name="l10n.gettext.msg">
  219.           <xsl:with-param
  220.            name="msg"
  221.            select="key('msg', concat($msgid, '__LC__',
  222.                                      $lang_language, '@', $lang_variant,
  223.                                                      '.', $lang_charset))"/>
  224.           <xsl:with-param name="form" select="$form"/>
  225.           <xsl:with-param name="node" select="$node"/>
  226.           <xsl:with-param name="role" select="$role"/>
  227.           <xsl:with-param name="string" select="$string"/>
  228.           <xsl:with-param name="format" select="$format"/>
  229.         </xsl:call-template>
  230.       </xsl:when>
  231.       <!-- fe@fo -->
  232.       <xsl:when test="($lang_variant) and
  233.                       key('msg', concat($msgid, '__LC__',
  234.                                         $lang_language, '@', $lang_variant))">
  235.         <xsl:call-template name="l10n.gettext.msg">
  236.           <xsl:with-param
  237.            name="msg"
  238.            select="key('msg', concat($msgid, '__LC__',
  239.                                      $lang_language, '@', $lang_variant))"/>
  240.           <xsl:with-param name="form" select="$form"/>
  241.           <xsl:with-param name="node" select="$node"/>
  242.           <xsl:with-param name="role" select="$role"/>
  243.           <xsl:with-param name="string" select="$string"/>
  244.           <xsl:with-param name="format" select="$format"/>
  245.         </xsl:call-template>
  246.       </xsl:when>
  247.       <!-- fe_fi.fum -->
  248.       <xsl:when test="($lang_region and $lang_charset) and
  249.                       key('msg', concat($msgid, '__LC__',
  250.                                         $lang_language, '_', $lang_region,
  251.                                                         '.', $lang_charset))">
  252.         <xsl:call-template name="l10n.gettext.msg">
  253.           <xsl:with-param
  254.            name="msg"
  255.            select="key('msg', concat($msgid, '__LC__',
  256.                                      $lang_language, '_', $lang_region,
  257.                                                      '.', $lang_charset))"/>
  258.           <xsl:with-param name="form" select="$form"/>
  259.           <xsl:with-param name="node" select="$node"/>
  260.           <xsl:with-param name="role" select="$role"/>
  261.           <xsl:with-param name="string" select="$string"/>
  262.           <xsl:with-param name="format" select="$format"/>
  263.         </xsl:call-template>
  264.       </xsl:when>
  265.       <!-- fe_fi -->
  266.       <xsl:when test="($lang_region) and
  267.                       key('msg', concat($msgid, '__LC__',
  268.                                         $lang_language, '_', $lang_region))">
  269.         <xsl:call-template name="l10n.gettext.msg">
  270.           <xsl:with-param
  271.            name="msg"
  272.            select="key('msg', concat($msgid, '__LC__',
  273.                                      $lang_language, '_', $lang_region))"/>
  274.           <xsl:with-param name="form" select="$form"/>
  275.           <xsl:with-param name="node" select="$node"/>
  276.           <xsl:with-param name="role" select="$role"/>
  277.           <xsl:with-param name="string" select="$string"/>
  278.           <xsl:with-param name="format" select="$format"/>
  279.         </xsl:call-template>
  280.       </xsl:when>
  281.       <!-- fe.fum -->
  282.       <xsl:when test="($lang_charset) and
  283.                       key('msg', concat($msgid, '__LC__',
  284.                                            $lang_language, '.', $lang_charset))">
  285.         <xsl:call-template name="l10n.gettext.msg">
  286.           <xsl:with-param
  287.            name="msg"
  288.            select="key('msg', concat($msgid, '__LC__',
  289.                                      $lang_language, '.', $lang_charset))"/>
  290.           <xsl:with-param name="form" select="$form"/>
  291.           <xsl:with-param name="node" select="$node"/>
  292.           <xsl:with-param name="role" select="$role"/>
  293.           <xsl:with-param name="string" select="$string"/>
  294.           <xsl:with-param name="format" select="$format"/>
  295.         </xsl:call-template>
  296.       </xsl:when>
  297.       <!-- fe -->
  298.       <xsl:when test="key('msg', concat($msgid, '__LC__', $lang_language))">
  299.         <xsl:call-template name="l10n.gettext.msg">
  300.           <xsl:with-param
  301.            name="msg"
  302.            select="key('msg', concat($msgid, '__LC__', $lang_language))"/>
  303.           <xsl:with-param name="form" select="$form"/>
  304.           <xsl:with-param name="node" select="$node"/>
  305.           <xsl:with-param name="role" select="$role"/>
  306.           <xsl:with-param name="string" select="$string"/>
  307.           <xsl:with-param name="format" select="$format"/>
  308.         </xsl:call-template>
  309.       </xsl:when>
  310.       <!-- "C" -->
  311.       <xsl:when test="key('msg', concat($msgid, '__LC__C'))">
  312.         <xsl:call-template name="l10n.gettext.msg">
  313.           <xsl:with-param
  314.            name="msg" select="key('msg', concat($msgid, '__LC__C'))"/>
  315.           <xsl:with-param name="form" select="$form"/>
  316.           <xsl:with-param name="node" select="$node"/>
  317.           <xsl:with-param name="role" select="$role"/>
  318.           <xsl:with-param name="string" select="$string"/>
  319.           <xsl:with-param name="format" select="$format"/>
  320.         </xsl:call-template>
  321.       </xsl:when>
  322.       <!-- not() -->
  323.       <xsl:when test="key('msg', concat($msgid, '__LC__'))">
  324.         <xsl:call-template name="l10n.gettext.msg">
  325.           <xsl:with-param
  326.            name="msg" select="key('msg', concat($msgid, '__LC__'))"/>
  327.           <xsl:with-param name="form" select="$form"/>
  328.           <xsl:with-param name="node" select="$node"/>
  329.           <xsl:with-param name="role" select="$role"/>
  330.           <xsl:with-param name="string" select="$string"/>
  331.           <xsl:with-param name="format" select="$format"/>
  332.         </xsl:call-template>
  333.       </xsl:when>
  334.       <xsl:otherwise>
  335.         <xsl:message>
  336.           <xsl:text>No translation available for string '</xsl:text>
  337.           <xsl:value-of select="$msgid"/>
  338.           <xsl:text>'.</xsl:text>
  339.         </xsl:message>
  340.         <xsl:value-of select="$msgid"/>
  341.       </xsl:otherwise>
  342.     </xsl:choose>
  343.   </xsl:for-each>
  344. </xsl:template>
  345.  
  346. <!--#* l10n.gettext.msg -->
  347. <xsl:template name="l10n.gettext.msg">
  348.   <xsl:param name="msg"/>
  349.   <xsl:param name="form" select="''"/>
  350.   <xsl:param name="node" select="."/>
  351.   <xsl:param name="role" select="''"/>
  352.   <xsl:param name="string"/>
  353.   <xsl:param name="format" select="false()"/>
  354.   <xsl:choose>
  355.     <xsl:when test="not($msg/msg:msgstr)">
  356.       <xsl:call-template name="l10n.gettext.msgstr">
  357.         <xsl:with-param name="msgstr" select="$msg"/>
  358.         <xsl:with-param name="node" select="$node"/>
  359.         <xsl:with-param name="role" select="$role"/>
  360.         <xsl:with-param name="string" select="$string"/>
  361.         <xsl:with-param name="format" select="$format"/>
  362.       </xsl:call-template>
  363.     </xsl:when>
  364.     <!-- FIXME: OPTIMIZE: this needs to be faster -->
  365.     <xsl:when test="$form != '' and $role != ''">
  366.       <xsl:variable name="msgstr_form" select="$msg/msg:msgstr[@form = $form]"/>
  367.       <xsl:choose>
  368.         <xsl:when test="$msgstr_form">
  369.           <xsl:choose>
  370.             <xsl:when test="msgstr_form[@role = $role]">
  371.               <xsl:call-template name="l10n.gettext.msgstr">
  372.                 <xsl:with-param name="msgstr"
  373.                                 select="msgstr_form[@role = $role][1]"/>
  374.                 <xsl:with-param name="node" select="$node"/>
  375.                 <xsl:with-param name="role" select="$role"/>
  376.                 <xsl:with-param name="string" select="$string"/>
  377.                 <xsl:with-param name="format" select="$format"/>
  378.               </xsl:call-template>
  379.             </xsl:when>
  380.             <xsl:when test="msgstr_form[not(@role)]">
  381.               <xsl:call-template name="l10n.gettext.msgstr">
  382.                 <xsl:with-param name="msgstr"
  383.                                 select="msgstr_form[not(@role)][1]"/>
  384.                 <xsl:with-param name="node" select="$node"/>
  385.                 <xsl:with-param name="role" select="$role"/>
  386.                 <xsl:with-param name="string" select="$string"/>
  387.                 <xsl:with-param name="format" select="$format"/>
  388.               </xsl:call-template>
  389.             </xsl:when>
  390.             <xsl:otherwise>
  391.               <xsl:call-template name="l10n.gettext.msgstr">
  392.                 <xsl:with-param name="msgstr"
  393.                                 select="msgstr_form[1]"/>
  394.                 <xsl:with-param name="node" select="$node"/>
  395.                 <xsl:with-param name="role" select="$role"/>
  396.                 <xsl:with-param name="string" select="$string"/>
  397.                 <xsl:with-param name="format" select="$format"/>
  398.               </xsl:call-template>
  399.             </xsl:otherwise>
  400.           </xsl:choose>
  401.         </xsl:when>
  402.         <xsl:otherwise>
  403.           <xsl:choose>
  404.             <xsl:when test="$msg/msg:msgstr[@role = $role]">
  405.               <xsl:call-template name="l10n.gettext.msgstr">
  406.                 <xsl:with-param name="msgstr"
  407.                                 select="$msg/msg:msgstr[@role = $role][1]"/>
  408.                 <xsl:with-param name="node" select="$node"/>
  409.                 <xsl:with-param name="role" select="$role"/>
  410.                 <xsl:with-param name="string" select="$string"/>
  411.                 <xsl:with-param name="format" select="$format"/>
  412.               </xsl:call-template>
  413.             </xsl:when>
  414.             <xsl:when test="$msg/msg:msgstr[not(@role)]">
  415.               <xsl:call-template name="l10n.gettext.msgstr">
  416.                 <xsl:with-param name="msgstr"
  417.                                 select="$msg/msg:msgstr[not(@role)][1]"/>
  418.                 <xsl:with-param name="node" select="$node"/>
  419.                 <xsl:with-param name="role" select="$role"/>
  420.                 <xsl:with-param name="string" select="$string"/>
  421.                 <xsl:with-param name="format" select="$format"/>
  422.               </xsl:call-template>
  423.             </xsl:when>
  424.             <xsl:otherwise>
  425.               <xsl:call-template name="l10n.gettext.msgstr">
  426.                 <xsl:with-param name="msgstr"
  427.                                 select="$msg/msg:msgstr[1]"/>
  428.                 <xsl:with-param name="node" select="$node"/>
  429.                 <xsl:with-param name="role" select="$role"/>
  430.                 <xsl:with-param name="string" select="$string"/>
  431.                 <xsl:with-param name="format" select="$format"/>
  432.               </xsl:call-template>
  433.             </xsl:otherwise>
  434.           </xsl:choose>
  435.         </xsl:otherwise>
  436.       </xsl:choose>
  437.     </xsl:when>
  438.     <xsl:when test="$form != ''">
  439.       <xsl:choose>
  440.         <xsl:when test="$msg/msg:msgstr[@form = $form]">
  441.           <xsl:call-template name="l10n.gettext.msgstr">
  442.             <xsl:with-param name="msgstr"
  443.                             select="$msg/msg:msgstr[@form = $form][1]"/>
  444.             <xsl:with-param name="node" select="$node"/>
  445.             <xsl:with-param name="role" select="$role"/>
  446.             <xsl:with-param name="string" select="$string"/>
  447.             <xsl:with-param name="format" select="$format"/>
  448.           </xsl:call-template>
  449.         </xsl:when>
  450.         <xsl:when test="$msg/msg:msgstr[not(@form)]">
  451.           <xsl:call-template name="l10n.gettext.msgstr">
  452.             <xsl:with-param name="msgstr"
  453.                             select="$msg/msg:msgstr[not(@form)][1]"/>
  454.             <xsl:with-param name="node" select="$node"/>
  455.             <xsl:with-param name="role" select="$role"/>
  456.             <xsl:with-param name="string" select="$string"/>
  457.             <xsl:with-param name="format" select="$format"/>
  458.           </xsl:call-template>
  459.         </xsl:when>
  460.         <xsl:otherwise>
  461.           <xsl:call-template name="l10n.gettext.msgstr">
  462.             <xsl:with-param name="msgstr" select="$msg/msg:msgstr[1]"/>
  463.             <xsl:with-param name="node" select="$node"/>
  464.             <xsl:with-param name="role" select="$role"/>
  465.             <xsl:with-param name="string" select="$string"/>
  466.             <xsl:with-param name="format" select="$format"/>
  467.           </xsl:call-template>
  468.         </xsl:otherwise>
  469.       </xsl:choose>
  470.     </xsl:when>
  471.     <xsl:when test="$role != ''">
  472.       <xsl:choose>
  473.         <xsl:when test="$msg/msg:msgstr[@role = $role]">
  474.           <xsl:call-template name="l10n.gettext.msgstr">
  475.             <xsl:with-param name="msgstr"
  476.                             select="$msg/msg:msgstr[@role = $role][1]"/>
  477.             <xsl:with-param name="node" select="$node"/>
  478.             <xsl:with-param name="role" select="$role"/>
  479.             <xsl:with-param name="string" select="$string"/>
  480.             <xsl:with-param name="format" select="$format"/>
  481.           </xsl:call-template>
  482.         </xsl:when>
  483.         <xsl:when test="$msg/msg:msgstr[not(@role)]">
  484.           <xsl:call-template name="l10n.gettext.msgstr">
  485.             <xsl:with-param name="msgstr"
  486.                             select="$msg/msg:msgstr[not(@role)][1]"/>
  487.             <xsl:with-param name="node" select="$node"/>
  488.             <xsl:with-param name="role" select="$role"/>
  489.             <xsl:with-param name="string" select="$string"/>
  490.             <xsl:with-param name="format" select="$format"/>
  491.           </xsl:call-template>
  492.         </xsl:when>
  493.         <xsl:otherwise>
  494.           <xsl:call-template name="l10n.gettext.msgstr">
  495.             <xsl:with-param name="msgstr" select="$msg/msg:msgstr[1]"/>
  496.             <xsl:with-param name="node" select="$node"/>
  497.             <xsl:with-param name="role" select="$role"/>
  498.             <xsl:with-param name="string" select="$string"/>
  499.             <xsl:with-param name="format" select="$format"/>
  500.           </xsl:call-template>
  501.         </xsl:otherwise>
  502.       </xsl:choose>
  503.     </xsl:when>
  504.     <xsl:otherwise>
  505.       <xsl:choose>
  506.         <xsl:when test="$msg/msg:msgstr[not(@role)]">
  507.           <xsl:call-template name="l10n.gettext.msgstr">
  508.             <xsl:with-param name="msgstr"
  509.                             select="$msg/msg:msgstr[not(@role)][1]"/>
  510.             <xsl:with-param name="node" select="$node"/>
  511.             <xsl:with-param name="role" select="$role"/>
  512.             <xsl:with-param name="string" select="$string"/>
  513.             <xsl:with-param name="format" select="$format"/>
  514.           </xsl:call-template>
  515.         </xsl:when>
  516.         <xsl:otherwise>
  517.           <xsl:call-template name="l10n.gettext.msgstr">
  518.             <xsl:with-param name="msgstr" select="$msg/msg:msgstr[1]"/>
  519.             <xsl:with-param name="node" select="$node"/>
  520.             <xsl:with-param name="role" select="$role"/>
  521.             <xsl:with-param name="string" select="$string"/>
  522.             <xsl:with-param name="format" select="$format"/>
  523.           </xsl:call-template>
  524.         </xsl:otherwise>
  525.       </xsl:choose>
  526.     </xsl:otherwise>
  527.   </xsl:choose>
  528. </xsl:template>
  529.  
  530. <!--#* l10n.gettext.msgstr -->
  531. <xsl:template name="l10n.gettext.msgstr">
  532.   <xsl:param name="msgstr"/>
  533.   <xsl:param name="node" select="."/>
  534.   <xsl:param name="role"/>
  535.   <xsl:param name="string"/>
  536.   <xsl:param name="format" select="false()"/>
  537.   <xsl:choose>
  538.     <xsl:when test="$format">
  539.       <xsl:apply-templates mode="l10n.format.mode" select="$msgstr/node()">
  540.         <xsl:with-param name="node" select="$node"/>
  541.         <xsl:with-param name="string" select="$string"/>
  542.       </xsl:apply-templates>
  543.     </xsl:when>
  544.     <xsl:otherwise>
  545.       <xsl:value-of select="$msgstr"/>
  546.     </xsl:otherwise>
  547.   </xsl:choose>
  548. </xsl:template>
  549.  
  550.  
  551. <!--**==========================================================================
  552. l10n.plural.form
  553. Extracts he plural form string for a given cardinality
  554. $number: The cardinality of the plural form
  555. $lang: The locale to use when looking up the translated string
  556. $lang_language: The language portion of the ${lang}
  557. $lang_region: The region portion of ${lang}
  558. $lang_variant: The variant portion of ${lang}
  559. $lang_charset: The charset portion of ${lang}
  560.  
  561. REMARK: Lots of documentation is needed
  562. -->
  563. <xsl:template name="l10n.plural.form">
  564.   <xsl:param name="number" select="1"/>
  565.   <xsl:param name="lang" select="$l10n.locale"/>
  566.   <xsl:param name="lang_language">
  567.     <xsl:call-template name="l10n.language">
  568.       <xsl:with-param name="lang" select="$lang"/>
  569.     </xsl:call-template>
  570.   </xsl:param>
  571.   <xsl:param name="lang_region">
  572.     <xsl:call-template name="l10n.region">
  573.       <xsl:with-param name="lang" select="$lang"/>
  574.     </xsl:call-template>
  575.   </xsl:param>
  576.   <xsl:param name="lang_variant">
  577.     <xsl:call-template name="l10n.variant">
  578.       <xsl:with-param name="lang" select="$lang"/>
  579.     </xsl:call-template>
  580.   </xsl:param>
  581.   <xsl:param name="lang_charset">
  582.     <xsl:call-template name="l10n.charset">
  583.       <xsl:with-param name="lang" select="$lang"/>
  584.     </xsl:call-template>
  585.   </xsl:param>
  586.  
  587.   <xsl:choose>
  588.     <!--
  589.     Keep variants first!
  590.     When adding new languages, make sure the tests are in a format that
  591.     can be extracted by the plurals.sh script in the i18n directory.
  592.     -->
  593.  
  594.     <!-- == pt_BR == -->
  595.     <xsl:when test="concat($lang_language, '_', $lang_region) = 'pt_BR'">
  596.       <xsl:choose>
  597.         <xsl:when test="$number > 1">
  598.           <xsl:text>0</xsl:text>
  599.         </xsl:when>
  600.         <xsl:otherwise>
  601.           <xsl:text>1</xsl:text>
  602.         </xsl:otherwise>
  603.       </xsl:choose>
  604.     </xsl:when>
  605.  
  606.     <!-- == ar == -->
  607.     <xsl:when test="$lang_language = 'ar'">
  608.       <xsl:choose>
  609.         <xsl:when test="$number = 1">
  610.           <xsl:text>0</xsl:text>
  611.         </xsl:when>
  612.         <xsl:when test="$number = 2">
  613.           <xsl:text>1</xsl:text>
  614.         </xsl:when>
  615.         <xsl:when test="$number >= 3 and $number < 10">
  616.           <xsl:text>2</xsl:text>
  617.         </xsl:when>
  618.         <xsl:otherwise>
  619.           <xsl:text>3</xsl:text>
  620.         </xsl:otherwise>
  621.       </xsl:choose>
  622.     </xsl:when>
  623.  
  624.     <!-- == be bs cs ru sr uk == -->
  625.     <xsl:when test="($lang_language = 'be') or ($lang_language = 'bs') or
  626.                     ($lang_language = 'cs') or ($lang_language = 'ru') or
  627.                     ($lang_language = 'sr') or ($lang_language = 'uk') ">
  628.       <xsl:choose>
  629.         <xsl:when test="($number mod 10 = 1) and ($number mod 100 != 11)">
  630.           <xsl:text>0</xsl:text>
  631.         </xsl:when>
  632.         <xsl:when test="($number mod 10 >= 2) and ($number mod 10 <= 4) and
  633.                         (($number mod 100 < 10) or ($number mod 100 >= 20))">
  634.           <xsl:text>1</xsl:text>
  635.         </xsl:when>
  636.         <xsl:otherwise>
  637.           <xsl:text>2</xsl:text>
  638.         </xsl:otherwise>
  639.       </xsl:choose>
  640.     </xsl:when>
  641.  
  642.     <!-- == cy == -->
  643.     <xsl:when test="$lang_language = 'cy'">
  644.       <xsl:choose>
  645.         <xsl:when test="$number != 2">
  646.           <xsl:text>0</xsl:text>
  647.         </xsl:when>
  648.         <xsl:otherwise>
  649.           <xsl:text>1</xsl:text>
  650.         </xsl:otherwise>
  651.       </xsl:choose>
  652.     </xsl:when>
  653.  
  654.     <!-- == fa hu ja ko th tr vi zh == -->
  655.     <xsl:when test="($lang_language = 'fa') or ($lang_language = 'hu') or
  656.                     ($lang_language = 'ja') or ($lang_language = 'ko') or
  657.                     ($lang_language = 'th') or ($lang_language = 'tr') or
  658.                     ($lang_language = 'vi') or ($lang_language = 'zh') ">
  659.       <xsl:text>0</xsl:text>
  660.     </xsl:when>
  661.  
  662.     <!-- == fr nso wa == -->
  663.     <xsl:when test="($lang_language = 'fr') or ($lang_language = 'nso') or
  664.                     ($lang_language = 'wa') ">
  665.       <xsl:choose>
  666.         <xsl:when test="$number > 1">
  667.           <xsl:text>1</xsl:text>
  668.         </xsl:when>
  669.         <xsl:otherwise>
  670.           <xsl:text>0</xsl:text>
  671.         </xsl:otherwise>
  672.       </xsl:choose>
  673.     </xsl:when>
  674.  
  675.     <!-- == ga == -->
  676.     <xsl:when test="$lang_language = 'ga'">
  677.       <xsl:choose>
  678.         <xsl:when test="$number = 1">
  679.           <xsl:text>0</xsl:text>
  680.         </xsl:when>
  681.         <xsl:when test="$number = 2">
  682.           <xsl:text>1</xsl:text>
  683.         </xsl:when>
  684.         <xsl:otherwise>
  685.           <xsl:text>2</xsl:text>
  686.         </xsl:otherwise>
  687.       </xsl:choose>
  688.     </xsl:when>
  689.  
  690.     <!-- == sk == -->
  691.     <xsl:when test="$lang_language = 'sk'">
  692.       <xsl:choose>
  693.         <xsl:when test="$number = 1">
  694.           <xsl:text>0</xsl:text>
  695.         </xsl:when>
  696.         <xsl:when test="($number >= 2) and ($number <= 4)">
  697.           <xsl:text>1</xsl:text>
  698.         </xsl:when>
  699.         <xsl:otherwise>
  700.           <xsl:text>2</xsl:text>
  701.         </xsl:otherwise>
  702.       </xsl:choose>
  703.     </xsl:when>
  704.  
  705.     <!-- == sl == -->
  706.     <xsl:when test="$lang_language = 'sl'">
  707.       <xsl:choose>
  708.         <xsl:when test="$number mod 100 = 1">
  709.           <xsl:text>0</xsl:text>
  710.         </xsl:when>
  711.         <xsl:when test="$number mod 100 = 2">
  712.           <xsl:text>1</xsl:text>
  713.         </xsl:when>
  714.         <xsl:when test="($number mod 100 = 3) or ($number mod 100 = 4)">
  715.           <xsl:text>2</xsl:text>
  716.         </xsl:when>
  717.         <xsl:otherwise>
  718.           <xsl:text>3</xsl:text>
  719.         </xsl:otherwise>
  720.       </xsl:choose>
  721.     </xsl:when>
  722.  
  723.     <!-- == C == -->
  724.     <xsl:otherwise>
  725.       <xsl:choose>
  726.         <xsl:when test="$number = 1">
  727.           <xsl:text>0</xsl:text>
  728.         </xsl:when>
  729.         <xsl:otherwise>
  730.           <xsl:text>1</xsl:text>
  731.         </xsl:otherwise>
  732.       </xsl:choose>
  733.     </xsl:otherwise>
  734.   </xsl:choose>
  735. </xsl:template>
  736.  
  737.  
  738. <!--**==========================================================================
  739. l10n.direction
  740. Determines the text direction for the language of the document
  741. $lang: The locale to use to determine the text direction
  742. $lang_language: The language portion of the ${lang}
  743. $lang_region: The region portion of ${lang}
  744. $lang_variant: The variant portion of ${lang}
  745. $lang_charset: The charset portion of ${lang}
  746.  
  747. REMARK: Lots of documentation is needed
  748. -->
  749. <xsl:template name="l10n.direction">
  750.   <xsl:param name="lang" select="$l10n.locale"/>
  751.   <xsl:param name="lang_language">
  752.     <xsl:call-template name="l10n.language">
  753.       <xsl:with-param name="lang" select="$lang"/>
  754.     </xsl:call-template>
  755.   </xsl:param>
  756.   <xsl:param name="lang_region">
  757.     <xsl:call-template name="l10n.region">
  758.       <xsl:with-param name="lang" select="$lang"/>
  759.     </xsl:call-template>
  760.   </xsl:param>
  761.   <xsl:param name="lang_variant">
  762.     <xsl:call-template name="l10n.variant">
  763.       <xsl:with-param name="lang" select="$lang"/>
  764.     </xsl:call-template>
  765.   </xsl:param>
  766.   <xsl:param name="lang_charset">
  767.     <xsl:call-template name="l10n.charset">
  768.       <xsl:with-param name="lang" select="$lang"/>
  769.     </xsl:call-template>
  770.   </xsl:param>
  771.   <xsl:variable name="direction">
  772.     <xsl:call-template name="l10n.gettext">
  773.       <xsl:with-param name="msgid" select="'default:LTR'"/>
  774.       <xsl:with-param name="lang" select="$lang"/>
  775.       <xsl:with-param name="lang_language" select="$lang_language"/>
  776.       <xsl:with-param name="lang_region"   select="$lang_region"/>
  777.       <xsl:with-param name="lang_variant"  select="$lang_variant"/>
  778.       <xsl:with-param name="lang_charset"  select="$lang_charset"/>
  779.     </xsl:call-template>
  780.   </xsl:variable>
  781.   <xsl:choose>
  782.     <xsl:when test="$direction = 'default:RTL'">
  783.       <xsl:text>rtl</xsl:text>
  784.     </xsl:when>
  785.     <xsl:otherwise>
  786.       <xsl:text>ltr</xsl:text>
  787.     </xsl:otherwise>
  788.   </xsl:choose>
  789. </xsl:template>
  790.  
  791.  
  792. <!--**==========================================================================
  793. l10n.align.start
  794. Determines the start alignment
  795. $direction: The text direction
  796.  
  797. REMARK: Lots of documentation is needed
  798. -->
  799. <xsl:template name="l10n.align.start">
  800.   <xsl:param name="direction">
  801.     <xsl:call-template name="l10n.direction"/>
  802.   </xsl:param>
  803.   <xsl:choose>
  804.     <xsl:when test="$direction = 'rtl'">
  805.       <xsl:text>right</xsl:text>
  806.     </xsl:when>
  807.     <xsl:otherwise>
  808.       <xsl:text>left</xsl:text>
  809.     </xsl:otherwise>
  810.   </xsl:choose>
  811. </xsl:template>
  812.  
  813.  
  814. <!--**==========================================================================
  815. l10n.align.end
  816. Determines the end alignment
  817. $direction: The text direction
  818.  
  819. REMARK: Lots of documentation is needed
  820. -->
  821. <xsl:template name="l10n.align.end">
  822.   <xsl:param name="direction">
  823.     <xsl:call-template name="l10n.direction"/>
  824.   </xsl:param>
  825.   <xsl:choose>
  826.     <xsl:when test="$direction = 'rtl'">
  827.       <xsl:text>left</xsl:text>
  828.     </xsl:when>
  829.     <xsl:otherwise>
  830.       <xsl:text>right</xsl:text>
  831.     </xsl:otherwise>
  832.   </xsl:choose>
  833. </xsl:template>
  834.  
  835.  
  836. <!--**==========================================================================
  837. l10n.arrow.previous
  838. FIXME
  839. $direction: The text direction
  840.  
  841. REMARK: Lots of documentation is needed
  842. -->
  843. <xsl:template name="l10n.arrow.previous">
  844.   <xsl:param name="direction">
  845.     <xsl:call-template name="l10n.direction"/>
  846.   </xsl:param>
  847.   <xsl:choose>
  848.     <xsl:when test="$direction = 'rlt'">
  849.       <xsl:text>◀  </xsl:text>
  850.     </xsl:when>
  851.     <xsl:otherwise>
  852.       <xsl:text>  ▶</xsl:text>
  853.     </xsl:otherwise>
  854.   </xsl:choose>
  855. </xsl:template>
  856.  
  857.  
  858. <!--**==========================================================================
  859. l10n.arrow.next
  860. FIXME
  861. $direction: The text direction
  862.  
  863. REMARK: Lots of documentation is needed
  864. -->
  865. <xsl:template name="l10n.arrow.next">
  866.   <xsl:param name="direction">
  867.     <xsl:call-template name="l10n.direction"/>
  868.   </xsl:param>
  869.   <xsl:choose>
  870.     <xsl:when test="$direction = 'rlt'">
  871.       <xsl:text>  ▶</xsl:text>
  872.     </xsl:when>
  873.     <xsl:otherwise>
  874.       <xsl:text>◀  </xsl:text>
  875.     </xsl:otherwise>
  876.   </xsl:choose>
  877. </xsl:template>
  878.  
  879.  
  880. <!--**==========================================================================
  881. l10n.language
  882. Extracts the langauge portion of a locale
  883. $lang: The locale to extract the language from
  884.  
  885. REMARK: Lots of documentation is needed
  886. -->
  887. <xsl:template name="l10n.language">
  888.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  889.   <xsl:choose>
  890.     <xsl:when test="$lang = $l10n.locale">
  891.       <xsl:value-of select="$l10n.language"/>
  892.     </xsl:when>
  893.     <xsl:when test="contains($lang, '_')">
  894.       <xsl:value-of select="substring-before($lang, '_')"/>
  895.     </xsl:when>
  896.     <xsl:when test="contains($lang, '@')">
  897.       <xsl:value-of select="substring-before($lang, '@')"/>
  898.     </xsl:when>
  899.     <xsl:when test="contains($lang, '_')">
  900.       <xsl:value-of select="substring-before($lang, '@')"/>
  901.     </xsl:when>
  902.     <xsl:otherwise>
  903.       <xsl:value-of select="$lang"/>
  904.     </xsl:otherwise>
  905.   </xsl:choose>
  906. </xsl:template>
  907.  
  908.  
  909. <!--**==========================================================================
  910. l10n.region
  911. Extracts the region portion of a locale
  912. $lang: The locale to extract the region from
  913.  
  914. REMARK: Lots of documentation is needed
  915. -->
  916. <xsl:template name="l10n.region">
  917.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  918.   <xsl:choose>
  919.     <xsl:when test="$lang = $l10n.locale">
  920.       <xsl:value-of select="$l10n.region"/>
  921.     </xsl:when>
  922.     <xsl:when test="contains($lang, '_')">
  923.       <xsl:variable name="aft" select="substring-after($lang, '_')"/>
  924.       <xsl:choose>
  925.         <xsl:when test="contains($aft, '@')">
  926.           <xsl:value-of select="substring-before($aft, '@')"/>
  927.         </xsl:when>
  928.         <xsl:when test="contains($aft, '.')">
  929.           <xsl:value-of select="substring-before($aft, '.')"/>
  930.         </xsl:when>
  931.         <xsl:otherwise>
  932.           <xsl:value-of select="$aft"/>
  933.         </xsl:otherwise>
  934.       </xsl:choose>
  935.     </xsl:when>
  936.   </xsl:choose>
  937. </xsl:template>
  938.  
  939.  
  940. <!--**==========================================================================
  941. l10n.variant
  942. Extracts the variant portion of a locale
  943. $lang: The locale to extract the variant from
  944.  
  945. REMARK: Lots of documentation is needed
  946. -->
  947. <xsl:template name="l10n.variant">
  948.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  949.   <xsl:choose>
  950.     <xsl:when test="$lang = $l10n.locale">
  951.       <xsl:value-of select="$l10n.variant"/>
  952.     </xsl:when>
  953.     <xsl:when test="contains($lang, '@')">
  954.       <xsl:variable name="aft" select="substring-after($lang, '@')"/>
  955.       <xsl:choose>
  956.         <xsl:when test="contains($aft, '.')">
  957.           <xsl:value-of select="substring-before($aft, '.')"/>
  958.         </xsl:when>
  959.         <xsl:otherwise>
  960.           <xsl:value-of select="$aft"/>
  961.         </xsl:otherwise>
  962.       </xsl:choose>
  963.     </xsl:when>
  964.   </xsl:choose>
  965. </xsl:template>
  966.  
  967.  
  968. <!--**==========================================================================
  969. l10n.charset
  970. Extracts the charset portion of a locale
  971. $lang: The locale to extract the charset from
  972.  
  973. REMARK: Lots of documentation is needed
  974. -->
  975. <xsl:template name="l10n.charset">
  976.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  977.   <xsl:choose>
  978.     <xsl:when test="$lang = $l10n.locale">
  979.       <xsl:value-of select="$l10n.charset"/>
  980.     </xsl:when>
  981.     <xsl:when test="contains($lang, '.')">
  982.       <xsl:value-of select="substring-after($lang, '.')"/>
  983.     </xsl:when>
  984.   </xsl:choose>
  985. </xsl:template>
  986.  
  987.  
  988. <!--%%==========================================================================
  989. l10n.format.mode
  990. FIXME
  991. $node: The node being processed in the original document
  992. $string: String content to use for certain message format nodes
  993.  
  994. REMARK: Lots and lots of documentation is needed
  995. -->
  996. <xsl:template mode="l10n.format.mode" match="*">
  997.   <xsl:param name="node"/>
  998.   <xsl:apply-templates mode="l10n.format.mode">
  999.     <xsl:with-param name="node" select="$node"/>
  1000.   </xsl:apply-templates>
  1001. </xsl:template>
  1002.  
  1003. <!-- = l10n.format.mode % msg:node = -->
  1004. <xsl:template mode="l10n.format.mode" match="msg:node">
  1005.   <xsl:param name="node"/>
  1006.   <xsl:apply-templates select="$node/node()"/>
  1007. </xsl:template>
  1008.  
  1009. <!-- = l10n.format.mode % msg:string = -->
  1010. <xsl:template mode="l10n.format.mode" match="msg:string">
  1011.   <xsl:param name="string"/>
  1012.   <xsl:value-of select="$string"/>
  1013. </xsl:template>
  1014.  
  1015. </xsl:stylesheet>
  1016.