From: Robert S. <bob...@us...> - 2003-07-25 05:05:30
|
Update of /cvsroot/docbook/gentext/xsl In directory sc8-pr-cvs1:/tmp/cvs-serv10597 Modified Files: xsl.xsl Log Message: Significant rewrite to use en.xml as master file to backfill any missing templates. Now processes en.xml, with locale file as a parameter. Index: xsl.xsl =================================================================== RCS file: /cvsroot/docbook/gentext/xsl/xsl.xsl,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** xsl.xsl 9 Jan 2003 10:02:42 -0000 1.7 --- xsl.xsl 25 Jul 2003 05:05:27 -0000 1.8 *************** *** 10,18 **** <xsl:strip-space elements="localization locale context"/> <xsl:template match="doc:*"/> <xsl:template match="locale"> ! <l:l10n language="{@language}" ! english-language-name="{@english-language-name}"> <xsl:text> </xsl:text> <xsl:text> </xsl:text> --- 10,23 ---- <xsl:strip-space elements="localization locale context"/> + <!-- Load the language file passed as a parameter into a variable --> + <xsl:param name="locale.file" select="''"/> + <xsl:param name="locale" select="document($locale.file, /)"/> + <xsl:template match="doc:*"/> <xsl:template match="locale"> ! <l:l10n> ! <xsl:copy-of select="$locale/locale/@*"/> ! <xsl:text> </xsl:text> <xsl:text> </xsl:text> *************** *** 35,40 **** <xsl:template match="gentext|dingbat"> <xsl:element name="l:{name(.)}"> ! <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:element> --- 40,67 ---- <xsl:template match="gentext|dingbat"> + <xsl:variable name="key"><xsl:value-of select="@key"/></xsl:variable> + <!-- Use localized text if available --> + <!-- otherwise use english --> + <xsl:variable name="localnode" + select="$locale/locale/*[local-name(.) = local-name(current())][@key = $key]"/> + <xsl:variable name="localtext"> + <xsl:value-of select="$localnode/@text"/> + </xsl:variable> <xsl:element name="l:{name(.)}"> ! <xsl:copy-of select="@key"/> ! <xsl:attribute name="text"> ! <xsl:choose> ! <xsl:when test="$localtext != ''"> ! <xsl:value-of select="$localtext"/> ! </xsl:when> ! <xsl:otherwise> ! <xsl:value-of select="@text"/> ! </xsl:otherwise> ! </xsl:choose> ! </xsl:attribute> ! <!-- Add lang=en if not in localized file or if marked as en there --> ! <xsl:if test="$localnode/@lang = 'en' or not($localnode)"> ! <xsl:attribute name="lang">en</xsl:attribute> ! </xsl:if> <xsl:apply-templates/> </xsl:element> *************** *** 50,58 **** <xsl:template match="template"> <l:template> <xsl:copy-of select="@*"/> <xsl:attribute name="text"> ! <xsl:apply-templates select="node()" mode="template-text"/> </xsl:attribute> </l:template> </xsl:template> --- 77,112 ---- <xsl:template match="template"> + <xsl:variable name="key"><xsl:value-of select="@name"/></xsl:variable> + <xsl:variable name="styleatt"><xsl:value-of select="@style"/></xsl:variable> + <xsl:variable name="context"><xsl:value-of select="ancestor::context[1]/@name"/></xsl:variable> + <!-- Use localized text if available --> + <!-- otherwise use english --> + <xsl:variable name="localnode" + select="$locale/locale/context[@name = $context]/template[@name = $key + and (($styleatt = '' and not(@style)) + or @style = $styleatt) ]"/> + <xsl:if test="count($localnode) > 1"> + <xsl:message>Warning: more than one localized template + for context <xsl:value-of select="$context"/> + and name <xsl:value-of select="$key"/>. + </xsl:message> + </xsl:if> <l:template> <xsl:copy-of select="@*"/> <xsl:attribute name="text"> ! <xsl:choose> ! <xsl:when test="$localnode"> ! <xsl:apply-templates select="$localnode/node()" mode="template-text"> ! <xsl:with-param name="en-locale" select="/*[1]"/> ! </xsl:apply-templates> ! </xsl:when> ! <xsl:otherwise> ! <xsl:apply-templates select="node()" mode="template-text"/> ! </xsl:otherwise> ! </xsl:choose> </xsl:attribute> + <xsl:if test="$localnode/@lang = 'en' or not($localnode)"> + <xsl:attribute name="lang">en</xsl:attribute> + </xsl:if> </l:template> </xsl:template> *************** *** 61,88 **** <xsl:template match="*" mode="template-text"> ! <xsl:variable name="key" select="local-name(.)"/> ! <xsl:variable name="gentext" select="ancestor::locale//gentext[@key=$key]"/> ! ! <xsl:if test="count($gentext) = 0"> ! <xsl:message terminate="yes"> ! <xsl:text>There is no gentext key '</xsl:text> ! <xsl:value-of select="$key"/> ! <xsl:text>' in the '</xsl:text> ! <xsl:value-of select="ancestor::locale/@language"/> ! <xsl:text>' locale.</xsl:text> ! </xsl:message> ! </xsl:if> ! <xsl:if test="count($gentext) > 1"> ! <xsl:message> ! <xsl:text>There is more than one gentext key '</xsl:text> ! <xsl:value-of select="$key"/> ! <xsl:text>' in the '</xsl:text> ! <xsl:value-of select="ancestor::locale/@language"/> ! <xsl:text>' locale.</xsl:text> ! </xsl:message> ! </xsl:if> ! ! <xsl:value-of select="$gentext[1]/@text"/> </xsl:template> --- 115,163 ---- <xsl:template match="*" mode="template-text"> ! <xsl:param name="en-locale"/> ! <xsl:variable name="key" select="local-name(.)"/> ! <!-- Use localized text if available --> ! <!-- otherwise use english --> ! <xsl:variable name="gentext" ! select="$locale//gentext[@key = $key] ! | $locale//dingbat[@key = $key]"/> ! ! <xsl:variable name="en-gentext" ! select="$en-locale//gentext[@key=$key] ! |$en-locale//dingbat[@key=$key]"/> ! <xsl:choose> ! <xsl:when test="count($gentext) > 1"> ! <xsl:message terminate="yes"> ! <xsl:text>There is more than one gentext key '</xsl:text> ! <xsl:value-of select="$key"/> ! <xsl:text>' in the '</xsl:text> ! <xsl:value-of select="ancestor::locale/@language"/> ! <xsl:text>' locale.</xsl:text> ! </xsl:message> ! </xsl:when> ! <xsl:when test="count($gentext) = 1"> ! <xsl:value-of select="$gentext[1]/@text"/> ! </xsl:when> ! <xsl:when test="count($en-gentext) = 1"> ! <xsl:message terminate="no"> ! <xsl:text>There is no gentext key '</xsl:text> ! <xsl:value-of select="$key"/> ! <xsl:text>' in the '</xsl:text> ! <xsl:value-of select="ancestor::locale/@language"/> ! <xsl:text>' locale. Using English.</xsl:text> ! </xsl:message> ! <xsl:value-of select="$en-gentext[1]/@text"/> ! </xsl:when> ! <xsl:otherwise> ! <xsl:message terminate="yes"> ! <xsl:text>There is no gentext key '</xsl:text> ! <xsl:value-of select="$key"/> ! <xsl:text>' in the '</xsl:text> ! <xsl:value-of select="ancestor::locale/@language"/> ! <xsl:text>' locale or in English.</xsl:text> ! </xsl:message> ! </xsl:otherwise> ! </xsl:choose> </xsl:template> |