From: <fxp...@us...> - 2008-04-08 11:01:50
|
Revision: 1261 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1261&view=rev Author: fxprunayre Date: 2008-04-08 04:01:55 -0700 (Tue, 08 Apr 2008) Log Message: ----------- Added test.i18n and test.i18n.xml service to check loc files Added Paths: ----------- trunk/web/geonetwork/WEB-INF/config-test.xml trunk/web/geonetwork/xsl/test-i18n-xml.xsl trunk/web/geonetwork/xsl/test-i18n.xsl Added: trunk/web/geonetwork/WEB-INF/config-test.xml =================================================================== --- trunk/web/geonetwork/WEB-INF/config-test.xml (rev 0) +++ trunk/web/geonetwork/WEB-INF/config-test.xml 2008-04-08 11:01:55 UTC (rev 1261) @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<geonet> + <services package="org.fao.geonet"> + <!-- Test services - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> + <service name="test.i18n"> + <output sheet="test-i18n.xsl"> + <!-- strings.xml --> + <xml name="strings.en" file="loc/en/xml/strings.xml" + localized="false" /> + <xml name="strings.fr" file="loc/fr/xml/strings.xml" + localized="false" /> + <xml name="strings.es" file="loc/es/xml/strings.xml" + localized="false" /> + <xml name="strings.cn" file="loc/cn/xml/strings.xml" + localized="false" /> + <xml name="strings.ar" file="loc/ar/xml/strings.xml" + localized="false" /> + <!-- about.xml --> + <xml name="about.en" file="loc/en/xml/about.xml" + localized="false" /> + <xml name="about.fr" file="loc/fr/xml/about.xml" + localized="false" /> + <xml name="about.es" file="loc/es/xml/about.xml" + localized="false" /> + <xml name="about.cn" file="loc/cn/xml/about.xml" + localized="false" /> + <xml name="about.ar" file="loc/ar/xml/about.xml" + localized="false" /> + <!-- config.xml --> + <xml name="config.en" file="loc/en/xml/config.xml" + localized="false" /> + <xml name="config.fr" file="loc/fr/xml/config.xml" + localized="false" /> + <xml name="config.es" file="loc/es/xml/config.xml" + localized="false" /> + <xml name="config.cn" file="loc/cn/xml/config.xml" + localized="false" /> + <xml name="config.ar" file="loc/ar/xml/config.xml" + localized="false" /> + <!-- harvesting.xml --> + <xml name="harvesting.en" + file="loc/en/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.fr" + file="loc/fr/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.es" + file="loc/es/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.cn" + file="loc/cn/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.ar" + file="loc/ar/xml/harvesting.xml" localized="false" /> + <!-- TODO : add other loc files --> + </output> + </service> + + <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> + <service name="test.i18n.xml"> + <output sheet="test-i18n-xml.xsl" + contentType="text/xml; charset=UTF-8"> + <!-- strings.xml --> + <xml name="strings.en" file="loc/en/xml/strings.xml" + localized="false" /> + <xml name="strings.fr" file="loc/fr/xml/strings.xml" + localized="false" /> + <xml name="strings.es" file="loc/es/xml/strings.xml" + localized="false" /> + <xml name="strings.cn" file="loc/cn/xml/strings.xml" + localized="false" /> + <xml name="strings.ar" file="loc/ar/xml/strings.xml" + localized="false" /> + <!-- about.xml --> + <xml name="about.en" file="loc/en/xml/about.xml" + localized="false" /> + <xml name="about.fr" file="loc/fr/xml/about.xml" + localized="false" /> + <xml name="about.es" file="loc/es/xml/about.xml" + localized="false" /> + <xml name="about.cn" file="loc/cn/xml/about.xml" + localized="false" /> + <xml name="about.ar" file="loc/ar/xml/about.xml" + localized="false" /> + <!-- config.xml --> + <xml name="config.en" file="loc/en/xml/config.xml" + localized="false" /> + <xml name="config.fr" file="loc/fr/xml/config.xml" + localized="false" /> + <xml name="config.es" file="loc/es/xml/config.xml" + localized="false" /> + <xml name="config.cn" file="loc/cn/xml/config.xml" + localized="false" /> + <xml name="config.ar" file="loc/ar/xml/config.xml" + localized="false" /> + <!-- harvesting.xml --> + <xml name="harvesting.en" + file="loc/en/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.fr" + file="loc/fr/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.es" + file="loc/es/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.cn" + file="loc/cn/xml/harvesting.xml" localized="false" /> + <xml name="harvesting.ar" + file="loc/ar/xml/harvesting.xml" localized="false" /> + <!-- TODO : add other loc files --> + </output> + </service> + </services> +</geonet> \ No newline at end of file Property changes on: trunk/web/geonetwork/WEB-INF/config-test.xml ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/web/geonetwork/xsl/test-i18n-xml.xsl =================================================================== --- trunk/web/geonetwork/xsl/test-i18n-xml.xsl (rev 0) +++ trunk/web/geonetwork/xsl/test-i18n-xml.xsl 2008-04-08 11:01:55 UTC (rev 1261) @@ -0,0 +1,214 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xalan="http://xml.apache.org/xalan"> + + <xsl:output method="xml"/> + + <xsl:variable name="langs"> + <langs> + <!-- TODO : add a master lang param to be able to compare to other lang than en <en master="true"/> --> + <fr /> + <es /> + <cn /> + <ar /> + </langs> + </xsl:variable> + + <xsl:template match="/"> + + <root> + <info>This service produce an XML document containing all missing localized terms in each loc files. + You could use this service in order to have more up to date localized files. + Use copy/paste to update the files and translate the term from english to the other language.</info> + <warning>WARNING: This will not produce sub-child elements. It will only produce correct + localized file for the first level of element with no attribute or with an id, value or type attribute.</warning> + <strings file="strings.xml"> + <xsl:variable name="master" select="//strings.en"/> + + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + + <xsl:variable name="l" select="name(.)"/> + <xsl:element name="{$l}"> + <xsl:for-each select="$master/*"> + <xsl:call-template name="checki18n-lang"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="lang" select="$l" /> + <xsl:with-param name="file">strings</xsl:with-param> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:for-each> + </strings> + <about file="about.xml"> + <xsl:variable name="master" select="//about.en"/> + + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + + <xsl:variable name="l" select="name(.)"/> + + <xsl:element name="{$l}"> + <xsl:for-each select="$master/*"> + <xsl:call-template name="checki18n-lang"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="lang" select="$l" /> + <xsl:with-param name="file">about</xsl:with-param> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:for-each> + </about> + <config file="config.xml"> + <xsl:variable name="master" select="//config.en"/> + + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + + <xsl:variable name="l" select="name(.)"/> + + <xsl:element name="{$l}"> + <xsl:for-each select="$master/*"> + <xsl:call-template name="checki18n-lang"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="lang" select="$l" /> + <xsl:with-param name="file">config</xsl:with-param> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:for-each> + </config> + <harvesting file="harvesting.xml"> + <xsl:variable name="master" select="//harvesting.en"/> + + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + + <xsl:variable name="l" select="name(.)"/> + + <xsl:element name="{$l}"> + <xsl:for-each select="$master/*"> + <xsl:call-template name="checki18n-lang"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="lang" select="$l" /> + <xsl:with-param name="file">harvesting</xsl:with-param> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:for-each> + </harvesting> + </root> + </xsl:template> + + + + <xsl:template name="checki18n-lang"> + <xsl:param name="elem"></xsl:param> + <xsl:param name="lang"></xsl:param> + <xsl:param name="file"></xsl:param> + + <xsl:variable name="tag" select="name($elem)" /> + <xsl:variable name="string" select="$elem/." /> + <xsl:variable name="value" select="$elem/@value" /> + <xsl:variable name="id" select="$elem/@id" /> + <xsl:variable name="type" select="$elem/@type" /> + + + <xsl:variable name="ok"> + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=concat($file, '.', $lang)]/*)" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=concat($file, '.', $lang)]/*/*)" /> + </xsl:call-template><!-- TODO add lang param --> + </xsl:variable> + + <xsl:if test="$ok='red'"> + <!-- FIXME : this will not take sub-child element --> + <!-- TODO : how to create an element name from var ? + <xsl:element name="$tag"></xsl:element> + --> + <xsl:element name="{$tag}"> + + <xsl:if test="$value"> + <xsl:attribute name="value"> + <xsl:value-of select="$value" /> + </xsl:attribute> + </xsl:if> + <xsl:if test="$id"> + <xsl:attribute name="id"> + <xsl:value-of select="$id" /> + </xsl:attribute> + </xsl:if> + <xsl:if test="$type"> + <xsl:attribute name="type"> + <xsl:value-of select="$type" /> + </xsl:attribute> + </xsl:if> + <xsl:value-of select="$string" /> + </xsl:element> + </xsl:if> + </xsl:template> + + + <xsl:template name="compare"> + <xsl:param name="tag"></xsl:param> + <xsl:param name="string"></xsl:param> + <xsl:param name="value"></xsl:param> + <xsl:param name="type"></xsl:param> + <xsl:param name="id"></xsl:param> + <xsl:param name="loctag1"></xsl:param> + <xsl:param name="loctag2"></xsl:param> + <xsl:choose> + <xsl:when test="$value or $id or $type"> + <xsl:choose> + <xsl:when + test="count($loctag2[name(.)=$tag and (@type=$type or @value=$value or @id=$id)])=1"> + <xsl:text>green</xsl:text> + </xsl:when> + <xsl:when + test="count($loctag1[name(.)=$tag and (@type=$type or @value=$value or @id=$id)])=1"> + <xsl:text>green</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>red</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:choose> + <xsl:when test="count($loctag2[name(.)=$tag])=1"> + <xsl:choose> + <xsl:when + test="$loctag2[name(.)=$tag]/. = $string"> + <xsl:text>yellow</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>green</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:when test="count($loctag1[name(.)=$tag])=1"> + <xsl:choose> + <xsl:when + test="$loctag1[name(.)=$tag]/. = $string"> + <xsl:text>yellow</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>green</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:text>red</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + +</xsl:stylesheet> + Property changes on: trunk/web/geonetwork/xsl/test-i18n-xml.xsl ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/web/geonetwork/xsl/test-i18n.xsl =================================================================== --- trunk/web/geonetwork/xsl/test-i18n.xsl (rev 0) +++ trunk/web/geonetwork/xsl/test-i18n.xsl 2008-04-08 11:01:55 UTC (rev 1261) @@ -0,0 +1,300 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xalan="http://xml.apache.org/xalan"> + + + <xsl:variable name="langs"> + <langs> + <!-- TODO : add a master lang param to be able to compare to other lang than en <en master="true"/> --> + <fr/> + <es/> + <cn/> + <ar/> + </langs> + </xsl:variable> + + <xsl:template match="/"> + <h1>Test i18n</h1> + <p>This service should help GeoNetwork opensource developpers to have up to date localized files. + Even if there's no tranlsation, all terms should be added to all localized files (even if no translation + are available). If new terms appear, you could ask to the gen...@so... for + some contribution on that. <b>Try to reduce the number of red squares in that page ;).</b> Thanks.</p> + <i> + "en" is master language. Each element of english files are + compared to the others + </i> + <p> + A draft XML document to use to update localized files is available <a href="test.i18n.xml">here</a>. + </p> + <table> + <tr> + <td bgcolor="green" width="30px"></td> + <td>ok</td> + </tr> + <tr> + <td bgcolor="red" width="30px"></td> + <td>missing element</td> + </tr> + <tr> + <td bgcolor="yellow" width="30px"></td> + <td> + existing element but translation is equal to "en" value + (and that could be valid) + </td> + </tr> + </table> + + <table> + <th> + <td width="20px"><b>en</b></td> + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + <td width="20px"><b><xsl:value-of select="name(.)"/></b></td> + </xsl:for-each> + </th> + + <!-- FIXME: This loop over xml loc files is not really elegant :( --> + <tr> + <td colspan="5"> + <h1>strings.xml</h1> + </td> + </tr> + <xsl:for-each select="//strings.en/*"> + <tr> + <xsl:call-template name="checki18n"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="file">strings</xsl:with-param> + </xsl:call-template> + </tr> + </xsl:for-each> + <tr> + <td colspan="4"> + <h1>about.xml</h1> + </td> + </tr> + <xsl:for-each select="//about.en/*"> + <tr> + <xsl:call-template name="checki18n"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="file">about</xsl:with-param> + </xsl:call-template> + </tr> + </xsl:for-each> + <tr> + <td colspan="4"> + <h1>config.xml</h1> + </td> + </tr> + <xsl:for-each select="//config.en/*"> + <tr> + <xsl:call-template name="checki18n"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="file">config</xsl:with-param> + </xsl:call-template> + </tr> + </xsl:for-each> + <tr> + <td colspan="4"> + <h1>harvesting.xml</h1> + </td> + </tr> + <xsl:for-each select="//harvesting.en/*"> + <tr> + <xsl:call-template name="checki18n"> + <xsl:with-param name="elem" select="." /> + <xsl:with-param name="file">harvesting</xsl:with-param> + </xsl:call-template> + </tr> + </xsl:for-each> + + + </table> + + + <p> + TODO: + <ul> + <li>Check all elements exist somewhere in XSL files</li> + <li>Check all loc files</li> + <li>Add a master lang parameter</li> + </ul> + </p> + </xsl:template> + + + + <xsl:template name="checki18n"> + <xsl:param name="elem"></xsl:param> + <xsl:param name="file"></xsl:param> + + <xsl:variable name="tag" select="name($elem)" /> + <xsl:variable name="string" select="$elem/." /> + <xsl:variable name="value" select="$elem/@value" /> + <xsl:variable name="id" select="$elem/@id" /> + <xsl:variable name="type" select="$elem/@type" /> + + + <td> + <xsl:attribute name="title"> + <xsl:value-of select="$string" /> + </xsl:attribute> + + <xsl:value-of select="$tag" /> + <xsl:if test="$value"> + (value: + <xsl:value-of select="$value" /> + ) + </xsl:if> + <xsl:if test="$id"> + (id: + <xsl:value-of select="$id" /> + ) + </xsl:if> + <xsl:if test="$type"> + (type: + <xsl:value-of select="$type" /> + ) + </xsl:if> + </td> + <!-- FIXME: Why can't loop on $la ? + <xsl:for-each select="xalan:nodeset($langs)/langs/*"> + <td> + <xsl:variable name="la"><xsl:value-of select="concat($file, '.', name(.))"/></xsl:variable> + <xsl:value-of select="$la"/> + <xsl:value-of select="count(xalan:nodeset(//*[name()='strings.fr']/*))"/> + + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=$la]/*)" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=$la]/*/*)" /> + </xsl:call-template> + </td> + </xsl:for-each> --> + <!-- FIXME: This loop over languages is not really elegant too :( --> + <td bgcolor="green"></td> + <td> + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=concat($file, '.fr')]/*)" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=concat($file, '.fr')]/*/*)" /> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=concat($file, '.es')]/*)" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=concat($file, '.es')]/*/*)" /> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=concat($file, '.cn')]/*)" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=concat($file, '.cn')])/*/*" /> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="compare"> + <xsl:with-param name="tag" select="$tag" /> + <xsl:with-param name="string" select="$string" /> + <xsl:with-param name="value" select="$value" /> + <xsl:with-param name="type" select="$type" /> + <xsl:with-param name="id" select="$id" /> + <xsl:with-param name="loctag1" + select="xalan:nodeset(//*[name(.)=concat($file, '.ar')])/*" /> + <xsl:with-param name="loctag2" + select="xalan:nodeset(//*[name(.)=concat($file, '.ar')])/*/*" /> + </xsl:call-template> + </td> + </xsl:template> + + + + + + <xsl:template name="compare"> + <xsl:param name="tag"></xsl:param> + <xsl:param name="string"></xsl:param> + <xsl:param name="value"></xsl:param> + <xsl:param name="type"></xsl:param> + <xsl:param name="id"></xsl:param> + <xsl:param name="loctag1"></xsl:param> + <xsl:param name="loctag2"></xsl:param> + <xsl:choose> + <xsl:when test="$value or $id or $type"> + <xsl:choose> + <xsl:when + test="count($loctag2[name(.)=$tag and (@type=$type or @value=$value or @id=$id)])=1"> + <xsl:attribute name="bgcolor">green</xsl:attribute> + </xsl:when> + <xsl:when + test="count($loctag1[name(.)=$tag and (@type=$type or @value=$value or @id=$id)])=1"> + <xsl:attribute name="bgcolor">green</xsl:attribute> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="bgcolor">red</xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:choose> + <xsl:when test="$string=''"><!-- Empty tag --> + <xsl:attribute name="bgcolor">green</xsl:attribute> + </xsl:when> + <xsl:when test="count($loctag2[name(.)=$tag])=1"> + <xsl:choose> + <xsl:when + test="$loctag2[name(.)=$tag]/. = $string"> + <xsl:attribute name="bgcolor">yellow</xsl:attribute> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="bgcolor">green</xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:when test="count($loctag1[name(.)=$tag])=1"> + <xsl:choose> + <xsl:when + test="$loctag1[name(.)=$tag]/. = $string"> + <xsl:attribute name="bgcolor">yellow</xsl:attribute> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="bgcolor">green</xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="bgcolor">red</xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + +</xsl:stylesheet> + Property changes on: trunk/web/geonetwork/xsl/test-i18n.xsl ___________________________________________________________________ Name: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |