# HG changeset patch # User Ruslan Ermilov # Date 1349362952 0 # Node ID cd0d1f0130db064cc73faf77b2babdae0c940780 # Parent e159f385c62ba85063889361a7a0737c21c344a9 Fixed language switcher. diff -r e159f385c62b -r cd0d1f0130db GNUmakefile --- 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 diff -r e159f385c62b -r cd0d1f0130db xsls/article.xsls --- 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"; diff -r e159f385c62b -r cd0d1f0130db xsls/download.xsls --- 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"; diff -r e159f385c62b -r cd0d1f0130db xsls/menu.xsls --- 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 @@ - X:if "@switchlang != ''" { + X:if "$TRANS and @switchlang" { X:if "contains($TRANS, @switchlang)" { - 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()) } } else { - !{ normalize-space(text()) } + !{ normalize-space(text()) } } } else { @@ -62,7 +58,6 @@ } } else { - !{ concat($ROOT, @href) } } } diff -r e159f385c62b -r cd0d1f0130db xsls/news.xsls --- 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";