[gimp-help-2] Attempt to fix #168256.



commit 2e00b705dd98dbb3ac47be62dd86b91520595d6b
Author: Roman Joost <roman bromeco de>
Date:   Thu Sep 20 14:13:19 2012 +1000

    Attempt to fix #168256.
    
    Since every translation is now providing content for each id, we can
    generate links to corresponding translations via XSLT. XSLT 1.0 does not
    provide a tokenizer. So I've implemented one to use with gimp-help.
    Proof of concept:
    https://github.com/romanofski/problemsolvingsnippets/blob/master/tokenize/tokenize.xslt

 stylesheets/plainhtml.xsl.in |   13 +++++++++-
 stylesheets/tokenize.xsl     |   52 ++++++++++++++++++++++++++++++++++++++++++
 stylesheets/vocab.xml        |    4 +++
 3 files changed, 68 insertions(+), 1 deletions(-)
---
diff --git a/stylesheets/plainhtml.xsl.in b/stylesheets/plainhtml.xsl.in
index f36107f..246b437 100644
--- a/stylesheets/plainhtml.xsl.in
+++ b/stylesheets/plainhtml.xsl.in
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This file is part of the gimp-help-2 project and is
-     (C) 2002, 2003, 2004, 2005, 2006 Daniel Egger, RÃman Joost
+     (C) 2002-2012 Daniel Egger, RÃman Joost
      You may use this file in accordance to the GNU General Public License
      Version 2 which is available from http://www.gnu.org.
 -->
@@ -8,6 +8,7 @@
     xmlns="http://www.w3.org/1999/xhtml";>
 
   <xsl:import href="@STYLEBASE@/xhtml/chunk.xsl" />
+  <xsl:import href="tokenize.xsl" />
   <xsl:import href="float-images.xsl" />
   <xsl:include href="htmlalternate.xsl" />
 
@@ -64,6 +65,7 @@
   <xsl:param name="targets.filename" select="'gimp-xrefs.xml'" />
   <xsl:param name="toc.section.depth" select="2" />
   <xsl:param name="use.id.as.filename">1</xsl:param>
+  <xsl:param name="all_linguas">@ALL_LINGUAS@</xsl:param>
 
   <!-- Add NotInToc role to simplesect, which is using in fdl.xml to
   deal with FDL-In-TOC issue.
@@ -174,6 +176,15 @@
         <xsl:if test="$header.rule != 0">
           <hr/>
         </xsl:if>
+        <div id="show_other_language">
+            <xsl:variable name="uri">
+                <xsl:call-template name="href.target" />
+            </xsl:variable>
+            <xsl:call-template name="tokenize">
+                <xsl:with-param name="linguas" select="$all_linguas" />
+                <xsl:with-param name="uri" select="$uri" />
+            </xsl:call-template>
+        </div>
       </div>
     </xsl:if>
   </xsl:template>
diff --git a/stylesheets/tokenize.xsl b/stylesheets/tokenize.xsl
new file mode 100644
index 0000000..f84c5f6
--- /dev/null
+++ b/stylesheets/tokenize.xsl
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
+  xmlns="http://www.w3.org/1999/xhtml";>
+
+  <xsl:output method="xml" encoding="UTF-8" indent="yes" />
+
+  <xsl:variable name="vocab" select="document('vocab.xml')" />
+  <xsl:variable name="splitstr" select="' '" />
+
+  <xsl:template name="tokenize">
+    <xsl:param name="linguas" />
+    <xsl:param name="uri" />
+    <xsl:param name="tail">
+      <xsl:value-of select="substring-after($linguas, $splitstr)" />
+    </xsl:param>
+    <xsl:param name="lang">
+      <xsl:value-of select="substring-before($linguas, $splitstr)" />
+    </xsl:param>
+
+    <xsl:choose>
+      <xsl:when test="contains($tail, $splitstr)">
+        <xsl:call-template name="create_link">
+            <xsl:with-param name="href" select="concat('..', $lang, '/', $uri)" />
+          <xsl:with-param name="title" select="$vocab/vocab/item[ value=$lang]" />
+        </xsl:call-template>
+
+        <xsl:call-template name="tokenize">
+          <xsl:with-param name="linguas" select="$tail" />
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="create_link">
+          <xsl:with-param name="href" select="$tail" />
+          <xsl:with-param name="title" select="$vocab/vocab/item[ value=$tail]" />
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="create_link">
+    <xsl:param name="href" />
+    <xsl:param name="title" />
+
+    <xsl:element name="a">
+      <xsl:attribute name="href">
+        <xsl:value-of select="$href" />
+      </xsl:attribute>
+      <xsl:value-of select="$title" />
+    </xsl:element>
+  </xsl:template>
+
+</xsl:stylesheet>
diff --git a/stylesheets/vocab.xml b/stylesheets/vocab.xml
new file mode 100644
index 0000000..9a821cb
--- /dev/null
+++ b/stylesheets/vocab.xml
@@ -0,0 +1,4 @@
+<vocab>
+  <item value="de">German</item>
+  <item value="en">English</item>
+</vocab>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]