Mobile applications are used on a variety of devices and, quite often, these devices are configured to use a language other than English. This recipe shows how to internationalize textual messages displayed in the application UI.
Review Chapter 4, Organizing a Virtual Filesystem, for the read-only file access using our implementation of the virtual filesystem abstraction.
For each language we want to support, we need to prepare a set of translated strings. We store these strings in a file. An example for the English-Russian language pair would be the
Localizer-ru.txt
file:Hello~Привет Good Bye~Пока
The
~
character is used as a delimiter between the original phrase and its translations. The original phrase can be used as a key, and it is stored with its translation in a globalstd::map
container:std::map<std::string, std::string> g_Translations; … g_Translations["Original phrase"] = "Translation"
Let us suppose we have a locale...