Reputation: 2390
How far can the standard C/C++ library address the above concerns? How portable can I make my software across platforms? What are the standards / best-practices in this area?
Upvotes: 3
Views: 134
Reputation: 41
I would avoid using wchar_t
or std::wstring
because this data type is not the same size in different environments. For example on Windows it is 16 bit, while on Unix systems it is 32 bit. Which asks for trouble.
If you don't have time/resources to implement Unicode standard (the bare minimum) yourself, you better off using std::string
as a container for UTF-8 characters. Though you must be aware that in the case of UTF-8 you will have to deal with multibyte encoding (1 character may correspond to 1 or more bytes).
As for libraries ICU is something to consider, it will allow you to convert between encodings, transform to upper/lower/title case and etc. It can also help with locales.
Translations as Marius noted are generally done through a function that looks up a table by the key you provided (be it a string, id or anything else) and in the end returns you the translation string.
Porting will go smooth if you stick to using data types that are the same on every platform, not to mention ICU is a cross-platform library, so it must work out.
Upvotes: 4
Reputation: 2273
wchar_t
or std::wstring
are your friends. Use them with the approriate wide-character functions and objects like wcscpy()
or std::wcout
.
You also would use a string-table for each locale, and a function like std::wstring getLocalizedString(MY_MESSAGE)
that looks up the constant MY_MESSAGE
in a string-table for the current locale. How you implement the string table is up to you, storing such things in external files is always a good idea.
Upvotes: 0