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