changeset 706:cd0d1f0130db

Fixed language switcher.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 04 Oct 2012 15:02:32 +0000
parents e159f385c62b
children b133b1f44765
files GNUmakefile xsls/article.xsls xsls/download.xsls xsls/menu.xsls xsls/news.xsls
diffstat 5 files changed, 19 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/GNUmakefile	Thu Oct 04 14:58:56 2012 +0000
+++ b/GNUmakefile	Thu Oct 04 15:02:32 2012 +0000
@@ -20,32 +20,17 @@
 	if [ ! -s $(2) ]; then rm $(2); fi; test -s $(2)
 endef
 
-# List of available languages
-LANGS:=$(find xml/ -mindepth 1 -maxdepth 1 -type d -not -name '.svn' \
-		-exec basename {} \; | xargs)
-
-# process xslt and create/pass some variables into XSLT processor:
-#
-# ORIGIN	 xml source of processed document ($o in shell script)
-# NOLANGORIGIN	 html document without xml/lang prefix ($ox in shell script)
-# TRANS		 list of languages to which document is translated ($trans)
-#
-# list of all languages is used to scan thorough to determine if current
-# document has translation in each of them.
-#
 define	XSLT
 	xmllint --noout --valid $2
 	xsltproc -o $3							\
-		$(shell f=`echo $2 | sed 's,^xml/,,;s,[^/]*/,en/,'`;	\
-			ox=`echo $2 | sed 's,^xml/,,;s,[^/]*/,,'`;	\
-			o=`echo $$ox | sed 's,\.xml,\.html,'`;		\
-			trans=`for LANG in $(LANGS);			\
-			do						\
-			[ -f xml/$$LANG/$$ox ] && echo -ne "$$LANG ";	\
-			done`;						\
-		[ -f xml/$$f ] && echo --stringparam ORIGIN "$$f"; 	\
-		echo --stringparam NOLANGORIGIN "$$o";			\
-		echo --stringparam TRANS \""$$trans\"")			\
+		$(shell ff=`echo $2`; ff=$${ff#xml/};			\
+		f=$${ff#*/};						\
+		if [ "$$f" != "$$ff" ]; then				\
+		[ -f xml/en/$$f ] && echo --stringparam ORIGIN "en/$$f";\
+		t=; for l in $(LANGS); do				\
+		[ -f "xml/$$l/$$f" ] && t="$$t$$l "; done;		\
+		echo --stringparam TRANS "\"$$t\"";			\
+		fi)							\
 		$(shell p="$4"; [ -n "$$p" ] &&				\
 		echo --stringparam $${p%%=*} $${p#*=})			\
 		$1 $2
--- a/xsls/article.xsls	Thu Oct 04 14:58:56 2012 +0000
+++ b/xsls/article.xsls	Thu Oct 04 15:02:32 2012 +0000
@@ -16,7 +16,6 @@
 X:param XML = "'../xml'";
 X:param YEAR;
 X:param ORIGIN;
-X:param NOLANGORIGIN;
 X:param TRANS;
 
 X:var LINK = "/article/@link | /module/@link";
--- a/xsls/download.xsls	Thu Oct 04 14:58:56 2012 +0000
+++ b/xsls/download.xsls	Thu Oct 04 15:02:32 2012 +0000
@@ -17,6 +17,7 @@
 X:param YEAR;
 
 X:var LINK = "/article/@link";
+X:var LANG = "/article/@lang";
 
 X:include href = "dirname.xslt";
 X:include href = "link.xslt";
--- a/xsls/menu.xsls	Thu Oct 04 14:58:56 2012 +0000
+++ b/xsls/menu.xsls	Thu Oct 04 15:02:32 2012 +0000
@@ -25,9 +25,8 @@
         <!--
           -- If a menu item has the switchlang attribute, then it will point
           -- to the same document in the specified language.
-          -- The document will be taken from $NOLANGORIGIN variable.
           -->
-        X:if "@switchlang != ''" {
+        X:if "$TRANS and @switchlang" {
 
             <!--
               -- Check if list of available translations ($TRANS) contains
@@ -36,18 +35,15 @@
               -->
             X:if "contains($TRANS, @switchlang)" {
                 <a>
-                 X:attribute "href" {
-                  X:if "$ROOT != '' " {
-                     !{ concat($ROOT, '/', @switchlang, '/', $NOLANGORIGIN) }
-                  } else {
-                     !{ concat(@switchlang, '/', $NOLANGORIGIN) }
-                  }
-                 }
-                 !{ normalize-space(text()) }
+                X:attribute "href" {
+                    !{ concat($ROOT, '/', @switchlang, '/',
+                        substring-after($LINK, concat('/', $LANG, '/'))) }
+                }
+                !{ normalize-space(text()) }
                 </a>
 
             } else {
-               <a class="notrans"> !{ normalize-space(text()) } </a>
+                <a class="notrans"> !{ normalize-space(text()) } </a>
             }
         } else {
 
@@ -62,7 +58,6 @@
                     }
 
                 } else {
-
                     !{ concat($ROOT, @href) }
                 }
             }
--- a/xsls/news.xsls	Thu Oct 04 14:58:56 2012 +0000
+++ b/xsls/news.xsls	Thu Oct 04 15:02:32 2012 +0000
@@ -15,9 +15,12 @@
   -->
 X:param XML = "'../xml'";
 X:param YEAR;
+X:param ORIGIN;
+X:param TRANS;
 
 X:var SITE = "'http://nginx.org'";
 X:var LINK = "/news/@link";
+X:var LANG = "/news/@lang";
 
 X:include href = "dirname.xslt";
 X:include href = "link.xslt";