--- a/src/main/scala/bootstrap/liftweb/Boot.scala Fri Apr 20 13:47:03 2012 +0200
+++ b/src/main/scala/bootstrap/liftweb/Boot.scala Fri Apr 20 13:47:21 2012 +0200
@@ -63,6 +63,10 @@
Html5Properties(r.userAgent) }
ScreenRules.init()
+
+ /* Language */
+ LangSwitcher.init()
+ LiftRules.localeCalculator = { _ => CurLanguage.get }
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/fis/base/ui/LangSwitcher.scala Fri Apr 20 13:47:21 2012 +0200
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package fis.base.ui
+
+import java.util.Locale
+import net.liftweb.common._
+import net.liftweb.http._
+import net.liftweb.http.js.JsCmds._
+import net.liftweb.util._
+import net.liftweb.util.Helpers._
+import net.tz.lift.model._
+import net.tz.lift.snippet._
+import scala.xml.NodeSeq
+
+/**
+ * Language switcher.
+ */
+object LangSwitcher {
+
+ private object curUrl extends RequestVar[Box[String]](Empty)
+
+ def init() {
+ LiftRules.snippets.append {
+ case List("lang-switcher") => { _ => render(load) }
+ }
+ }
+
+ def render: CssTr =
+ ".lang-cz" #> switchLocale("cs") &
+ ".lang-en" #> switchLocale("en")
+
+ def switchLocale(l: String): CssTr = { in =>
+ SHtml.a(in) {
+ CurLanguage(new Locale(l))
+ Run("window.location.reload()")
+ }
+ }
+
+ protected def load: NodeSeq =
+ Templates(List("templates-hidden", "lang-switcher")) openOr NodeSeq.Empty
+}
+
+object CurLanguage extends SessionVar[Locale](Locale.getDefault)
+
+
+// vim: set ts=2 sw=2 et:
Binary file src/main/webapp/images/cz.png has changed
Binary file src/main/webapp/images/en.png has changed
--- a/src/main/webapp/templates-hidden/default.html Fri Apr 20 13:47:03 2012 +0200
+++ b/src/main/webapp/templates-hidden/default.html Fri Apr 20 13:47:21 2012 +0200
@@ -26,6 +26,7 @@
<h1>Functional Information System</h1>
<p>Project management, CRM, ...</p>
<p id="user-label" class="pull-right">
+ <span class="lift:lang-switcher"></span>
<span class="lift:user-label"></span>
</p>
</div>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/templates-hidden/lang-switcher.html Fri Apr 20 13:47:21 2012 +0200
@@ -0,0 +1,4 @@
+<span>
+ <img class="lang-cz" src="/images/cz.png"/>
+ <img class="lang-en" src="/images/en.png"/>
+</span>