Full locale support now in SVN!
- Posted by Jeremy Cowgar <jeremy at c??gar.com> May 05, 2008
- 768 views
Wow, it's finally working! We can now format date/time values, money, numbers and finally also message translation. Instead of going with an INI file, I went with the same format that gettext uses, the po file because there are many nice editors (not text editors but translation tools) for .po files. There are also text editors for the po format, as it is a simple text file. So, here's an example program: ---- File: po/en_US.po # English language file for greeter app hello Hello world World greeting %s, %s! ---- File: po/es_MX.po # Spanish language file for greeter app hello Hola world Mundo greeting %s, %s! ---- File: greeter.ex
include locale.e as l include datetime.e as d d:datetime now now = d:now() l:set_po_path("po") l:set("en_US") printf(1, "Date: %s\n", {l:datetime("%A, %B %d, %Y", now)}) printf(1, "Average car price: %s\n", {l:money(22652)}) printf(1, "Population: %s\n", {l:number(10000)}) printf(1, l:w("greeting"), {l:w("hello"), l:w("world")}) puts(1, "\n") l:set("es_MX") printf(1, "Date: %s\n", {l:datetime("%A, %B %d, %Y", now)}) printf(1, "Average car price: %s\n", {l:money(22652)}) printf(1, "Population: %s\n", {l:number(10000)}) printf(1, l:w("greeting"), {l:w("hello"), l:w("world")})
---- Output: Date: Sunday, May 04, 2008 Average car price: $22,652.00 Population: 10,000 Hello, World! Date: domingo, mayo 04, 2008 Average car price: $22,652.00 Population: 10,000 Hola, Mundo! ---- So, that's it. Now, I do have one more problem that many other systems do not address and maybe they do not because it's a very rare case? The problem is in the example of Hello, World!. Some languages may say who they are greeting first, like: World Hello! or something like that. In this situation, our localization will not work. As it is positional ("%s, %s!"). Any thoughts from someone better at localizing apps than I am? Oh, I know the date/time, money, number formatting did not change, but it's the same for English and Spanish... here's output if the locale is changed to de_DE: Date: Sonntag, Mai 04, 2008 Average car price: 1.020,50 EUR Population: 10.000 -- Jeremy Cowgar http://jeremy.cowgar.com