Multi-Language supporting app
What is the best/proper way to write a multi-language supporting app?
Creating an 2 dimensional char array and caching all the strings to it?
Have a nice day
You could use a std::map (I am assuming, you are using C++) that maps strings to strings. Each entry would map a key to the actual string:
e.g. "CONFIRM_QUIT" -> "You you really want to quit?"
Every time you need a string that is presented to the user, you look it up using the corresponding key.
The string you get out of the map would depend on the language you have loaded previously. For example, if you had loaded the German version "CONFIRM_QUIT" would give you the string "Wollen sie das Programm wirklich beenden?"
You could store the strings for each language in a separate file.
Note that there are other things that have to be kept in mind, when you deal with localization. For example date formats and decimal separators vary from language to language.
e.g. "CONFIRM_QUIT" -> "You you really want to quit?"
Every time you need a string that is presented to the user, you look it up using the corresponding key.
The string you get out of the map would depend on the language you have loaded previously. For example, if you had loaded the German version "CONFIRM_QUIT" would give you the string "Wollen sie das Programm wirklich beenden?"
You could store the strings for each language in a separate file.
Note that there are other things that have to be kept in mind, when you deal with localization. For example date formats and decimal separators vary from language to language.
If the game does not require any input from its users, and does not make use of string formatting, then a simple array can work. For most projects, sadly, the only way to deal with that is to use a library like GNU gettext. You can't simply stuff everything in a map and hope it'll work. Format strings, for instance, are problematic. For example:
printf("%s supporting app\n", "multi-languages");
will output something that's valid English, but in French, it'd be
printf("app supportant %s\n", "de multiples langages");.
As you can see, the "%s" is located at the very beginning of the format string in English, and at the very end in French.
As Deaken Frost mentioned, you'll also have issues with:
That's not even taking into account:
I personally use ICU along with GNU gettext and FriBiDi to solve almost all of these problems(*), at least when coding in C or C++. I'm a GNU/Linux user though: I don't know how easy gettext is to integrate to Visual Studio. If you're using another language (eg Java or a .NET language) or API (eg Qt), it's quite possible the problem's been solved for you.
(*) the only problem it does not solve is CJK input.
EDIT: added FriBiDi.
printf("%s supporting app\n", "multi-languages");
will output something that's valid English, but in French, it'd be
printf("app supportant %s\n", "de multiples langages");.
As you can see, the "%s" is located at the very beginning of the format string in English, and at the very end in French.
As Deaken Frost mentioned, you'll also have issues with:
- dates and time zones,
- decimal separators,
- currencies,
- measures (imperial vs metrics vs ...),
- titles (PhD, san, Mr, etc),
- titles (English capitalizes most first-letters, French doesn't, etc),
- various cultural meanings attached to symbols and colours in images (I believe white is the colour of funerals in Japan, but not in the West),
- etc.
That's not even taking into account:
- encoding (eg Unicode),
- CJK input (usually requires an "input server", in X lingo),
- complex scripts input and rendering (Right-to-Left, but can switch to Left-to-Right in the middle of a sentence for various reasons),
- probably more things I'm not even thinking of right now.
I personally use ICU along with GNU gettext and FriBiDi to solve almost all of these problems(*), at least when coding in C or C++. I'm a GNU/Linux user though: I don't know how easy gettext is to integrate to Visual Studio. If you're using another language (eg Java or a .NET language) or API (eg Qt), it's quite possible the problem's been solved for you.
(*) the only problem it does not solve is CJK input.
EDIT: added FriBiDi.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement