Posted by
Miguel Cobá on
Sep 10, 2010; 3:19pm
URL: https://forum.world.st/i18n-tools-tp2533446p2534612.html
El jue, 09-09-2010 a las 22:12 +0300, Panu Suominen escribió:
> I am researching wether out team could start using Pharo. I have tried to locate
> some tools to do user interface translations but I did not find
> anything in time so I had
> to develop some rudimentary key-based translation tools my self. I would like
> to know is this lack of translation tools reality and if others are having same
> kind of problems?
>
There are effort to bring gettext infrastructure to Pharo and seaside.
Search the archives for details.
What I do in Seaside is to store create a base class for the default
languan, lets say, english:
MyLanguage
with class methods for each string that I want localized, f.e.
MyLanguage class>>greet
^ 'Hello User'
MyLanguage class>>numItems: num
^ '{1} items' format: {num}
This allows me to have parametrized messages.
Now for each language you want to support you create a subclass:
MyLanguage subclass: #MyLanguageESMX
and override each method you want to translate:
MyLanguageESMX class>>greet
^ 'Hola usuario'
MyLanguageESMX class>>numItems: num
^ '{1} elementos' format: {num}
If some method is missing in the subclass, it will take the value of the
parent class.
Now, to use it, store in each user session a inst var holding the
prefered _class_ for the language the user wants. And create an accessor
for this inst var:
WASession subclass: #MySession
instanceVariableNames: 'user announcer language'
classVariableNames: ''
poolDictionaries: ''
category: 'MyPackage'
MySession>>lang
^ self user preferences language
Now when you want to emit a string do:
MyLogin>>renderContentOn: html
html div
id: 'login';
with: [
self session lang greet;
self renderLoginOn: html ]
As the lang accessor returns the preferred lang class for the user, the
message greet is understood (they are class methods) and returns the
correct translated string for the given user.
To create a new translation, you copy a existent subclass of MyLanguage
and rewrite the strings for the new language.
Of course this only takes care of the string translation, and does
nothing about currency and left-to-right issues in distinct languages.
For the currency issue you can add a format message that emits the
correct representation of a number in the current locale but for the
direction of text, you'll need to look for other options, like the
gettext code I mentioned before.
Hope this helps.
Cheers
--
Miguel Cobá
http://miguel.leugim.com.mx_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users