Getting localized string in chosen locale (not calculated)

82 views
Skip to first unread message

Lukasz Kuczera

unread,
Aug 19, 2011, 8:37:43 AM8/19/11
to Lift
S.?(str: String) is great thing but is there any way to do S.?(str:
String, loc: Locale) to get string in specified locale (not calculated
by LocaleCalculator) ?

Lukasz Kuczera

unread,
Aug 19, 2011, 9:25:11 AM8/19/11
to Lift
I workarounded it by this:

def getLocalizedString(key: String, loc: Locale) = {
val bundles = LiftRules.resourceForCurrentLoc.vend() :::
LiftRules.resourceNames.flatMap(name => tryo {
if (Props.devMode) {
tryo {
val clz =
this.getClass.getClassLoader.loadClass("java.util.ResourceBundle")
val meth = clz.getDeclaredMethods.
filter { m => m.getName == "clearCache" &&
m.getParameterTypes.length == 0 }.
toList.head
meth.invoke(null)
}
}
List(ResourceBundle.getBundle(name, locale))
}.openOr(
NamedPF.applyBox((name, locale),
LiftRules.resourceBundleFactories.toList).map(List(_)) openOr Nil))

bundles.find(bundle =>
bundle.containsKey(key)).map(_.getString(key))

David Pollak

unread,
Aug 19, 2011, 12:13:00 PM8/19/11
to lif...@googlegroups.com

No... but I but I believe you're a committer and it'd be wicked cool for you to add this feature. ;-)
 

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net

Łukasz Kuczera

unread,
Aug 19, 2011, 1:34:26 PM8/19/11
to Lift

Yeah there are some of stuff waiting for that but I dont have tickets for them would that be ok without tickets ? Sorry for complaining but we have very close deadline so all coding time is very precious now :/

David Pollak

unread,
Aug 19, 2011, 1:57:05 PM8/19/11
to lif...@googlegroups.com


2011/8/19 Łukasz Kuczera <l.ku...@jextreme.pl>

Yeah there are some of stuff waiting for that but I dont have tickets for them would that be ok without tickets ?


I'd prefer that you open tickets and go through the review board process for non-trivial changes (like this).  I will be very responsive to review board requests and you're welcome to open tickets.
 

Sorry for complaining but we have very close deadline so all coding time is very precious now :/


I understand and I apologize for being conservative about asking you to follow process. :-(
 

Andreas Joseph Krogh

unread,
Aug 19, 2011, 3:04:55 PM8/19/11
to lif...@googlegroups.com
On 08/19/2011 06:13 PM, David Pollak wrote:


On Fri, Aug 19, 2011 at 5:37 AM, Lukasz Kuczera <kuk...@gmail.com> wrote:
S.?(str: String) is great thing but is there any way to do S.?(str:
String, loc: Locale) to get string in specified locale (not calculated
by LocaleCalculator) ?

No... but I but I believe you're a committer and it'd be wicked cool for you to add this feature. ;-)

As an alternative I implemented my own i18n-handling which I use in my Lift-projects. I use a custom Localizable trait ( https://github.com/andreak/on-example-rpm/blob/master/web/src/main/scala/no/officenet/example/rpm/web/lib/Localizable.scala) which provides useful i18-methods, where you may specify the locale used. It also provides type-safe i18n, using custom resource-bundle enums (extending Scala-enums).

Feel free to copy whatever you want.

-- 
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 Trollåsen          | somebody else doing it wrong, without       |
NORWAY                  | comment.                                    |
Org.nr: NO 981 479 076  |                                             |
                        |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

Luc

unread,
Aug 10, 2013, 6:30:41 AM8/10/13
to lif...@googlegroups.com
Hello,

I'm looking exactly for this "def getLocalizedString(key: String, loc: Locale)", but I can't make it work.
Has it been implemented in Lift or anywhere?

Thanks!

Richard Dallaway

unread,
Aug 12, 2013, 4:42:45 AM8/12/13
to liftweb
Looks like it was added in https://github.com/lift/framework/issues/1093 as: ?(str: String, locale: Locale): String

Cheers
Richard




--
--
Lift, the simply functional web framework: http://liftweb.net
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages