# HG changeset patch # User Tomas Zeman # Date 1334922441 -7200 # Node ID 2b0fafd71c1d40f542e5bd3172b6e47c7bd2377f # Parent 3ce7ecb6bc708be0286765263c14bac19a0f8c8f Language switcher diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/scala/bootstrap/liftweb/Boot.scala --- 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 } } } diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/scala/fis/base/ui/LangSwitcher.scala --- /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 + * + * 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: diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/webapp/images/cz.png Binary file src/main/webapp/images/cz.png has changed diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/webapp/images/en.png Binary file src/main/webapp/images/en.png has changed diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/webapp/templates-hidden/default.html --- 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 @@

Functional Information System

Project management, CRM, ...

+

diff -r 3ce7ecb6bc70 -r 2b0fafd71c1d src/main/webapp/templates-hidden/lang-switcher.html --- /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 @@ + + + +