Created
February 20, 2013 21:55
-
-
Save tgpfeiffer/4999981 to your computer and use it in GitHub Desktop.
An extended Link for the use of a single Loc for multiple languages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package code.lib | |
import net.liftweb.http.{S, Req} | |
import net.liftweb.sitemap.Loc | |
/** | |
* Loc that matches multiple paths, one for each language. | |
* | |
* @param uris Maps languages to paths, e.g. | |
* Map( | |
* "de" -> ("de" :: "mein-konto" :: Nil), | |
* "en" -> ("en" :: "my-account" :: Nil) | |
* ) | |
*/ | |
class LocalizedLink[T](uris: Map[String, List[String]]) | |
extends Loc.Link[T](uris.headOption.map(_._2).getOrElse(Nil)) { | |
val myPaths = uris.values.toList | |
override def isDefinedAt(req: Req): Boolean = { | |
if (matchHead_?) myPaths.contains(req.path.partPath.take(uriList.length)) | |
else myPaths.contains(req.path.partPath) | |
} | |
override def pathList(value: T): List[String] = { | |
uris.get(S.locale.getLanguage).getOrElse(uris("en")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment