Comet internationalization

46 views
Skip to first unread message

Mirko Saiu

unread,
Apr 7, 2015, 10:55:55 AM4/7/15
to lif...@googlegroups.com
Hi everyone

We have a problem with lift 2.5.
The problem is that inside the CometActor we cannot use S.? to internationalize strings because it always returns the wrong locale.

We tried to use the syntax S.?(string, locale) but it didn't work
The value returned from cometActorLocale is always correct


 Is there any trick or way to solve this problem?

Antonio Salazar Cardozo

unread,
Apr 7, 2015, 2:47:39 PM4/7/15
to lif...@googlegroups.com
What locale is it using? The default, or something else?

Could you perhaps create an example project for us? (https://www.assembla.com/wiki/show/liftweb/Posting_example_code)
Thanks,
Antonio

Vasya Novikov

unread,
Apr 8, 2015, 3:00:21 AM4/8/15
to lif...@googlegroups.com, mirko...@gmail.com
It's a known restriction of Lift. AFAIremember, the "request" data is
not available in a comet because a comet works outside of a request
scope.. Try to search this mailing list or stackoverflow for your
problem, you'll find the topic with detailed explanations. A work-around
might be to add the locale to an additional SessionVar.

Please write if will not find the information that easy, or if you will
have questions on how to use all this.
--
Vasya Novikov

Mirko Saiu

unread,
Apr 9, 2015, 6:48:45 AM4/9/15
to lif...@googlegroups.com

object internationalization{

  def localeCalculator(request : Box[HTTPRequest]): Locale =
    request.flatMap(r => {
      def localeCookie(in: String): HTTPCookie =
        HTTPCookie("internationalization",Full(in),
          Full(S.hostName),Full(S.contextPath),Full(2629743),Empty,Empty)
      def localeFromString(in: String): Locale = {
        val x = in.split("_").toList;
        new Locale(x.head,x.last)
      }
      def calcLocale: Box[Locale] = {
        if (GMRConfig.sessionVars.selected_lang.get != "unknown"){
          Full(localeFromString(GMRConfig.sessionVars.selected_lang.get))}
        else {

          S.findCookie("internationalization").map(
            _.value.map(localeFromString)
          ).openOr(Full(LiftRules.defaultLocaleCalculator(request)))
        }
      }

      S.param("locale") match {
        case Full(null) => calcLocale
        case f@Full(selectedLocale) =>
          S.addCookie(localeCookie(selectedLocale))
          tryo(localeFromString(selectedLocale))
        case _ => calcLocale
      }
    }).openOr(Locale.getDefault())

}


Antonio, it is using the default Locale. 
This is the code from our internationalization file. 

Is there any way to use the Locale inside the session var to localize our strings?


Joe Barnes

unread,
Apr 16, 2015, 10:20:38 PM4/16/15
to lif...@googlegroups.com
Did you figure out how to store the local in a SessionVar as previously suggested?

Joe
Reply all
Reply to author
Forward
0 new messages