3.7 Full: Packages and translations
Diego Gomez Deck
DiegoGomezDeck at ConsultAr.com
Fri Apr 9 09:38:59 UTC 2004
Hi Stef,
(this email use html violating every rule in netiquete, but it includes
some code and the colors (i hope) will help)
> is there a how-to document about making code translatable ? I have no
> idea how this is supposed to work.
For the 90% of the cases you only need to send #translated to every
visible String. When #translated is evaluated, the receiver (one
string) answer the version of this string/phrase to the current
language. So,
"answer 'casa' when Spanish if the current language"
'house' translated.
The other useful message (needed to cover the missing 10%) is #format:.
String>>format: is a type of "printf()" with a really simple (aka
stupid) syntax. The occurrences of '{N}' will be replaced by the string
representation of the object at position N in the given
SequenceableCollection, so:
"evaluates to 'My name is Diego and I'm 31 years old' when anObject
it's me"
'My name is {1} and I'm {2} years old' format: {anObject name.
anObject age}.
The goal with format is to replace former string concatenations like:
'My name is ', anObject name, ' and I'm ', anObject age asString, ' years old'.
As you can see, the order used in the concatenation makes sense only in
English. Combining #translated and #format: you can make translatable
almost any piece of code.
The full previous example has to be:
'My name is {1} and I'm {2} years old' translated format: {anObject name. anObject age}.
Note: As the replacing made by #format: use positions, the translator
can rearrange the places where the expansion occurs.
Let me know if the explanation is clear enough.
Cheers,
Diego
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040409/cd217d5b/attachment.htm
More information about the Squeak-dev
mailing list
|