This might seem odd as you can get those resources from the VM:
scala> import java.util._
scala> Locale.UK.getDisplayCountry
res0: java.lang.String = United Kingdom
scala> Locale.UK.getDisplayCountry(Locale.FRANCE)
res1: java.lang.String = Royaume-Uni
scala> Locale.UK.getLanguage
res2: java.lang.String = en
scala> Locale.UK.getCountry
res3: java.lang.String = GB
…but country codes change, and possibly the VM doesn't have everything, or might not be relied on for non-international installs, so doesn't hurt to keep a separate numbering system and lookup.
Perhaps you can use the translations to get the instances of Countries? This looks iffy to me but might get somewhere:
List("de", "fr", "gb").map( cc => new Locale("en", cc).getDisplayCountry ).flatMap( c => Countries.values.find(_.toString == c) )
res16: List[net.liftweb.mapper.Countries.Value] = List(Germany, France, United Kingdom)
Yuk… but perhaps useful for generating lookup code:
List("de", "fr", "gb").map( cc => new Locale("en", cc).getDisplayCountry ).flatMap( c => Countries.values.find(_.toString == c) ).map(_.id)
res21: List[Int] = List(65, 61, 184)
i.e C65 is Germany.
Richard
On Wednesday, 8 February 2012 at 11:00, Franz Bettag wrote:
> Morning,
>
> i've really been working a lot with countries in mapper-objects lately, now i've got another challenge which is to import a country based on the 2-letter ISO Code.
>
> I thought that maybe the Country-Codes in https://github.com/lift/framework/blob/master/persistence/mapper/src/main/scala/net/liftweb/mapper/MappedPostalCode.scala are ISO Codes, but it turns out they are not :/
>
> Is there any way to get a Mapping from ISO to net.liftweb.mapper.Countries (http://web.mapper.Countries)? Otherwise i'll have to come up with something ;)
>
> thanks in advance!
>
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
This goes from Country to a Locale…but...
scala> Locale.getAvailableLocales.find( _.getDisplayCountry == Countries.UK.toString)
res19: Option[java.util.Locale] = Some(en_GB)
…has pain written all over it. It's matching against a I18N resource name ("United Kingdom" in this case) so you want to be careful what locale you're running in. Good luck! :-)
--
http://richard.dallaway.com
On Thursday, 9 February 2012 at 15:46, Franz Bettag wrote:
> the goal is to get as far as possible with lift base components, also prolly only 4-5 countries will be effectively used. Reinventing the wheel doesn't seem necessary :)
>