My language switcher does not work only from the blog page

146 views Asked by At

I've written my language switcher as below.

It works from / or from /blog/<blog-post> but it does not work from the /blog page even if /en/blog is available.

<a href="{{ '.'|url(alt='jp') }}">Japanese</a> | <a href="{{ '.'|url(alt='en') }}"> English </a>

Is it bug or should I fix something?

Below is my web site language switcher is available on top-right of the page.

2

There are 2 answers

2
Armin Ronacher On

In Lektor versions < 2 there are some limitations with regards to the alts. This is working correctly in Lektor 2 which is currently in development only. But you can install it from the git master if you already want to use it.

0
a2csuga On

It can be reproduced by adding the following patch to quickstart project (project name: alt_test)

Tested environment is below.

lektor version: bc61976a0c7aca3374a40d55f633a83e0686c247

python version: 2.7.10

diff --git a/alt_test.lektorproject b/alt_test.lektorproject
index d53bfea..e3da734 100644
--- a/alt_test.lektorproject
+++ b/alt_test.lektorproject
@@ -1,2 +1,12 @@
 [project]
 name = alt_test
+
+[alternatives.jp]
+name = Japanese
+primary = yes
+locale = ja_JP
+
+[alternatives.en]
+name = English
+url_prefix = /en/
+locale = en_US
diff --git a/templates/layout.html b/templates/layout.html
index ed7a449..1a61a9c 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -17,6 +17,7 @@
             <li{% if this.is_child_of(href) %} class="active"{% endif
             %}><a href="{{ href|url }}">{{ title }}</a></li>
         {% endfor %}
+        <a href="{{ '.'|url(alt='jp') }}">Japanese</a> | <a href="{{ '.'|url(alt='en') }}"> English </a>
       </ul>
     </nav>
   </header>