[next] [up] [next]

The Translation Scheme in Smalltalk/X

In ST/X, language translations come from external files, which basically contain key-value pairs. This is similar to schemes in other languages, however, in ST/X, the english original string is used as key, not cryptic number, as in most other such schemes.

Our experience showed that there are good reasons for such a scheme:

  1. programmers can search for the english original string
  2. programmers see in the code, what is shown in a particular label, dialog, etc.
  3. language translations can be easily added later
  4. even english-to-english translations are possible, by providing an "en.rs" file. This is useful to fix typos in already deployed code.
  5. although we damand english as original language, third party private developers may choose any language as original and provide translations for other languages later. Including english.
  6. No special tools are needed to edit and maintain language translation files. They can be given to a translator without a need for deeper expertise in handling any special editor or tool.

Programmer API

Getting the Resources

Whenever a programmer needs a user-readable string (i.e. a UI-string), he/she writes: "resources string:''. instead of using the plain string.

The variable "resources" is an instance variable of ApplicationModel, thus every UI application automatically gets the required translations.

Class methods can refer to this via "self classResources".

If your class is not inheriting from ApplicationModel, use "self class classResources" or "self projectDefinitionClass classResources".

Getting a String Translated

For most situations, the above simple translation message is sufficient. However, often, other strings need to be embedded inside a UI-String. Typically, these are numeric values, file names etc. For this, use "resources string:'...%1..' with:argument, which first translates the string, then expands the %i with corresponding argumens from the with:-list. Up to 5 parameters can be provided by with:, with:with:... methods. More arguments are passed by the "withArguments:{ arg1 . ... argN }" array construct.

You should never ever concatenate individually translated string pieces, because different languages may have a different word order (subject-predicate-object), and thus often require different word ordering.

For this, a string such as 'bla bla %1 and %2 with %3" can be given as UI string, and translated to a string like "%1 und %2 sowie %3 wurden bla bla".

Finally, in some cases, a resource string may spawn multiple lines, and the newline-escape character should be escaped to linebreaks. However, this must happen before the expansion, as otherwise MSDOS-filenames woulf be presented in multiple lines. For this, use the "resources stringWithCRs:'...%1..' with:arg ... message. ... more to come ...


Next: The Main Menu

[stx logo] Copyright © 2008 eXept Software AG, all rights reserved


Doc $Revision: 1.2 $ $Date: 2016/04/29 14:05:19 $