New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculating Locale Based on Cookies invalid characters (fix code) #52

heralight opened this Issue Mar 7, 2012 · 0 comments


None yet
1 participant

heralight commented Mar 7, 2012

In in the end of file part "Calculating Locale Based on Cookies and Parameters" code

wrong code character : replace ’-’, ’’ with ’-’, ’’ and remove invisible illegal characters. fixed code:

// Properly convert a language tag to a Locale
def computeLocale(tag : String) = tag.split(Array(’-’, ’_’)) match {
  case Array(lang) => new Locale(lang)
  case Array(lang, country) => new Locale(lang, country)
  case Array(lang, country, variant) => new Locale(lang, country, variant)

// Define this to be whatever name you want
val LOCALE_COOKIE_NAME = "SelectedLocale"

LiftRules.localeCalculator = {
  case fullReq @ Full(req) => {
    // Check against a set cookie, or the locale sent in the request
    def currentLocale : Locale =
      S.findCookie(LOCALE_COOKIE_NAME).flatMap {
        cookie =>
      } openOr LiftRules.defaultLocaleCalculator(fullReq)

    // Check to see if the user explicitly requests a new locale
    S.param("locale") match {
      case Full(requestedLocale) if requestedLocale != null => {
        val computedLocale = computeLocale(requestedLocale)
        S.addCookie(HTTPCookie(LOCALE_COOKIE_NAME, requestedLocale))
      case _ => currentLocale
  case _ => Locale.getDefault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment