I18N

From Lift

Jump to: navigation, search

lift has a bunch of different mechanisms to localize. lift automatically selects an appropriate template based on the current locale. (The current locales is the locale that the browser supplies, or, if someone has already logged in, the locale that they select.)

Within a template (presumably the default template), one can also localize a subsection of the template with <lift:loc [locid="localization id"]>default string</lift:loc> which will use the current locale and Java resource bundles to look up a localized string or XML fragment.

In inline code, the developer can type: ?("cheeseburger") and using the same localization mechanism "cheeseburger" will be localized. If there's no appropriate text to be inserted, a developer-supplied notification function will be called to presumably log the error. (Tip: have it spit out a link to add the text on the fly)

If you need i18n, you can use ?(locId, params ...) and the Java string formatting routines will be applied the localized string and the params. In this way, you get number formatting, currency formatting/symbols, etc.

The resource resource bundle base name is set in LiftServlet.resourceName and defaults to lift. The localized strings have to be in the classpath root as lift_en_US.properties. No narrowing of language type is done: if the browser is configured for en_US and no file lift_en_US.properties exists lift wont look for lift_en.properties.

In the immediate instance, lift has some i18n and localization features that satisfy the existing European and North American developers (I don't know of any lift based projects that are being done outside of these regions.) If someone has a need that's not being satisfied in lift and can't easily be satisfied with an existing library and/or the Java platform, then we'll spend some cycles determining the priority of supplying those features.

In terms of other web frameworks, yes, I'm sure there are others that provide feature x or feature y and lift doesn't. On the other hand, in November 2006, it was impossible for me to display a page with mixed English and Chinese (I'm not sure what dialect... just some Chinese blog postings) in Rails. lift is already far ahead of that... mainly because lift sits on top of Java and Scala.


David Pollak (extract frome mailings-list)

Minor edits by Viktor Klang

00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)Marius 00:41, 20 February 2008 (PST)

Internal lift classes (specially existent model classes) can be used to generate markup fragments. Such fragments contains string eligible for internationalization. 
For instance now one can use MetaMegaProtoUser safely for virtually any language. 

Currently lift string exist in the SNAPSHOT 0.6 jar (after the build) under i18n/lift-core_en_US.properties. 
If you need to internationalize lift strings (say for French or any other language) please copy this properties file into WEB-INF/classes/i18n folder 
(you can also add them in the lift jar file but I don't see why would anyone do that). 
The container will load the resources first from WEB-INF/classes and then from jars from WEB-INF/lib folder as per servlet specifications.

Now the default resource bundle name for internal lift resource bundle is i18n.lift-core, however this can be changed by 
setting LiftServlet.liftCoreResourceName var to something else (preferably in the boot).

To reference a lift core string do not use S.? function. Instead use S.?? function (for example S.??("invalid.email.address")). 
The reason is that lift now keeps separately user's resource bundle and lift's resource bundle so the two to be completely decoupled and evolve separately. 
Of course that S.?? function is not private to lift packages so users can also reference strings (in order to leverage them) from lift core resource bundle 
in their application. Probably this is not a very common scenario though.

00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)00:41, 20 February 2008 (PST)Marius 00:41, 20 February 2008 (PST)


Internal lift localization by Marius Danciu

Personal tools