links to this page:    
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to make user text translatable
Last updated at 8:12 pm UTC on 25 July 2004
Question: April 09, 2004 Is there a how-to document about making code translatable ?
Answer: Diego Gomez Deck For the 90% of the cases you only need to send #translated to every visible String. When #translated is evaluated, the receiver (one string) answers the version of this string/phrase in the current language. So,
  "answer 'casa' when Spanish is 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 is 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'.
Where we need to translate mix constants and variables. As you can see, the order used in the concatenation above makes sense only in English. Since, the #format: replaces the symbolics based on position, the translator can rearrange the places where the expansion occurs.

Combining #translated and #format: you can translate almost any piece of code, For example:
  'My name is {1} and I'm {2} years old' translated 
     format: {anObject name. anObject age}.

Question: How do I install translation capablitity and get it going in my image?