ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7


4 - The Nuts and Bolt of Translating

You now know the OS language, which logically is the preferred language - now what? Quite likely, although you will add support as more languages are translated, you'll need a gradual upgrade path. If your language-specific data is limited to text, a simple way to handle it is to create a two-dimensional array of strings and use indexes to refer to them. Each language would be the first index value, and enums could be used to address individual language elements. For instance, the array
  extern const char *s_languageStrings[s_maxLanguage][4]={
    { "button",    "text",          "cancel",      "hello"   },
    { "drukknoop", "tekst",         "afbestellen", "hallo"   },
    { "botón",     "texto",         "cancelación", "hola"    },
    { "bouton",    "texte",         "annuler",     "bonjour" },
    { "der taster","der zeilentext","zurückziehen","hallo"   } };
would allow us to display English while using s_languageStrings[0], Dutch with s_languageStrings[1], and so on.

This column's program shows how this can be done. It consists of a display and some language buttons. Initially, the program looks up the OS language, and sets part of the display to display in that language. It also provides a list of languages you can choose from; selecting any changes the display. Using a variation of this code will allow you to easily add foreign language text to your programs. Look over the lang_fun.cpp file for details on modifying the code to suit your needs.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice