|
forrest 0.7 multi language site contribution and question (second version): msg#00141text.xml.forrest.user
Hi list, May be this mail should be send to a dev list. In order to display with dynamic forrest (started with forrest run) a page with a text corresponding to the language of the preference of the browser of the user, I did the following modifications. This only concerns the page, not the menu or the tabs. The basic idea is to - created a new DTD for document to introduce an element tt which surround the text to be translated. - to translate this tt element to an i18:text element with an xslt stylesheet - apply the i18n transformation to translate. Note In the examples forrest is in D:\DATA\apache\apache-forrest-0.7 forrest site is in D:\DATA\apache\apache-forrest-0.7-paul-site A) I create a new DTD document-v21.dtd with a new module document-v21.mod in directory D:\DATA\apache\apache-forrest-0.7\main\webapp\resources\schema\dtd\ The document-v21.dtd is <!ENTITY % common-charents PUBLIC "-//APACHE//ENTITIES Common Character Entity Sets V1.0//EN" "common-charents-v10.mod"> %common-charents; <!-- =============================================================== --> <!-- Document --> <!-- =============================================================== --> <!ENTITY % document PUBLIC "-//APACHE//ENTITIES Documentation V2.1//EN" "document-v21.mod"> %document; Note Only the two lines are different from document-v20.dtd "-//APACHE//ENTITIES Documentation V2.1//EN" "document-v21.mod"> in directory D:\DATA\apache\apache-forrest-0.7\main\webapp\resources\schema\dtd\ The document document-v21.mod is a copy of document-v20.mod with differences given hereafter 1) The line <!ENTITY % text "#PCDATA"> becomes <!-- <!ENTITY % text "#PCDATA"> --> This line is put in comment 2) The folowing lines are added after <!ENTITY % simpletext "#PCDATA"> <!ENTITY % text "simpletext|tt"> 3) before the lines <!-- ==================================================== --> <!-- Body --> <!-- ==================================================== --> add <!-- tt text to translate --> <!ELEMENT tt (%simpletext;)> The basic idea is to surround text to be translated with the tt element. B) A new stylesheet i18ntext.xsl to replace <tt> by <i18n:text> in directory D:\DATA\apache\apache-forrest-0.7\main\webapp\resources\stylesheets <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:i18n="http://apache.org/cocoon/i18n/2.1" > <xsl:import href=""> <xsl:template match="tt"> <i18n:text> <xsl:apply-templates select="@*"/> <xsl:apply-templates /> </i18n:text> </xsl:template> </xsl:stylesheet> C) Modify the sitemap.xmap in order to do the two modifications (markup modification and translation) for html page and pdf page in directory D:\DATA\apache\apache-forrest-0.7\main\webapp After the lines <map:match pattern="**body-*.html"> <map:generate src=""> <map:transform type="idgen"/> <map:transform type="xinclude"/> Add the lines <!-- paul begin --> <map:select type="config"> <map:parameter name="value" value="{defaults:i18n}"/> <map:when test="true"> <map:transform src="" <map:transform type="i18n"> <map:parameter name="locale" value="{request:locale}"/> </map:transform> </map:when> </map:select> <!-- paul end --> and after the lines <map:match type="regexp" pattern="^(.*?)([^/]*).fo$"> <map:select type="exists"> <map:when test="{project:content.xdocs}{1}{2}.fo"> <map:generate src=""> </map:when> <map:otherwise> <map:aggregate element="site"> <map:part src=""> <map:part src=""> </map:aggregate> <!-- <map:transform type="idgen"/> --> <map:transform type="xinclude"/> add the lines <!-- paul begin --> <map:select type="config"> <map:parameter name="value" value="{defaults:i18n}"/> <map:when test="true"> <map:transform src="" <map:transform type="i18n"> <map:parameter name="locale" value="{request:locale}"/> </map:transform> </map:when> </map:select> <!-- paul end --> D) in the pdf plugin output.xmap we inverse the presence test to solve a problem of cache (this is a workaround) (the cache does not recognise that the language has changed, so it displays the same page) in the directory D:\DATA\apache\apache-forrest-0.7\build\plugins\org.apache.forrest.plugin.output.pdf\ After the lines <map:pipelines> <map:pipeline> <!-- generate .pdf files from .fo --> <map:match type="regexp" pattern="^(.*?)([^/]*).pdf$"> <map:select type="exists"> put in comment the lines <!-- <map:when test="{project:content.xdocs}/{1}{2}.pdf"> <map:read src=""> </map:when> <map:otherwise> <map:generate src=""> <map:serialize type="fo2pdf"/> </map:otherwise> --> and after add the lines <!-- paul begin --> <map:when test="{project:content.xdocs}/{1}{2}.xml"> <map:generate src=""> <map:serialize type="fo2pdf"/> </map:when> <map:otherwise> <map:select type="exists"> <map:when test="{project:content.xdocs}/{1}{2}.pdf"> <map:read src=""> </map:when> </map:select> </map:otherwise> <!-- paul end --> E) In forrest.xmap in D:\DATA\apache\apache-forrest-0.7\main\webapp In order to catch the new DTD. After the lines <sourcetype name="document-v20"> <document-declaration public-id="-//APACHE//DTD Documentation V2.0//EN" /> </sourcetype> Add the lines <!-- add paul begin --> <sourcetype name="document-v21"> <document-declaration public-id="-//APACHE//DTD Documentation V2.1//EN" /> </sourcetype> <!-- add paul end --> Afer the lines <map:when test="document-v20"> <map:transform src="" /> </map:when> Add the lines <!-- add paul begin --> <map:when test="document-v21"> <map:transform src="" /> </map:when> <!-- add paul end --> F) in D:\DATA\apache\apache-forrest-0.7\main\webapp\skins\common\translations fill catalogs CommonMessages_xx.xml with in the languages you want. For the example I use CommonMessages_en_US.xml and CommonMessages_fr.xml with already translated "Search". <message key="Search">Rechercher</message> G) Update Catalog of forrest In D:\DATA\apache\apache-forrest-0.7\main\webapp\resources\schema\catalog.forrest After the line -- Document Type Definitions -- add the line PUBLIC "-//APACHE//DTD Documentation V2.1//EN" "dtd/document-v21.dtd" H)in catalog.forrest.xcat in the directory D:\DATA\apache\apache-forrest-0.7\main\webapp\resources\schema After the line <!-- Document Type Definitions (current) --> add the lines <!-- paul begin --> <public publicId="-//APACHE//DTD Documentation V2.1//EN" uri="dtd/document-v21.dtd"/> <!-- paul end --> After the line <!-- Reusable modules --> add the lines <!-- paul begin --> <public publicId="-//APACHE//ENTITIES Documentation V2.1//EN" uri="dtd/document-v21.mod"/> <!-- paul end --> I) Put in your page the new DOCTYPE and the text to translate in <tt> markup. Exemple indexi.xml in the directory D:\DATA\apache\apache-forrest-0.7-paul-site\src\documentation\content\xdocs <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.1//EN" "http://forrest.apache.org/dtd/document-v21.dtd"> <document> <header> <title><tt>Search</tt> untranslate</title> </header> <body> <section id="overview"> <title><tt>Search</tt> untranslate</title> <p><tt>Search</tt> untranslate </p> </section> </body> </document> J) In forrest.properties of the site put the indicator to true Example D:\DATA\apache\apache-forrest-0.7-paul-site After the line #project.i18n=true add the line project.i18n=true K) In the directory of your site start the site with command "forrest run" Example cd D:\DATA\apache\apache-forrest-0.7-paul-site SET JAVA_HOME=C:\java\j2sdk1.4.2_03 set FOREST_HOME=C:\apache\apache-forrest-0.7 set PATH=%PATH%;%FOREST_HOME%\bin forrest run L) To look at the results - With your favorit browser put your language preferences to english en_US (tool/internet option/language ..) http://localhost:8888/indexi.html You can see "Search" and if you clic on the PDF icon you should see the same in pdf format. - With your favorit browser put your language preferences to german de http://localhost:8888/indexi.html You can see "Suche" and if you clic on the PDF icon you should see the same in pdf format. - With your favorit browser put your language preferences to french fr http://localhost:8888/indexi.html You can see "Rechercher" and if you clic on the PDF icon you should see the same in pdf format. Note For the tab and the menu Catalogues of the language should be define D:\DATA\apache\apache-forrest-0.7-paul-site\src\documentation\translations langcode.xml menu_de.xml menu_fr.xml the menu_lang file should exist Restrictions - The research function in the site is looking at the text in the page Only the basic langague is seen, not the translations. Some work is needed to add to the index the text of each language. - The other tags of i18n like "if" are not taken into account. - To inform the user of the multi language possibilities a new skin should be done. - Only document-v20.dtd can be translated all the other formats cannot. The question is: Why the Pdf function has no translation? Paul |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Forrestbot help: 00141, David Crossley |
|---|---|
| Next by Date: | Re: Forrestbot help: 00141, David Crossley |
| Previous by Thread: | finding documentation about Forresti: 00141, Tiscar Sebastien |
| Next by Thread: | Re: forrest 0.7 multi language site contribution and question (second version): 00141, Thorsten Scherler |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |