Non-ascii characters are pain in Visual Studio. While our team does not consist of people using different locales, we have occasional need for characters from different locales and we use several other compilers that behave differently. So here is what we found works:
- Visual Studio recognizes UTF-8 byte order mark. You can change the encoding in "File/Advanced Save Options" for individual file and default somewhere in Options. If you choose Unicode (UTF-8 with signature) - Codepage 65001, it is going to always display the same to all team members.
- Unicode characters in wide literals (L"...") are properly encoded in UTF-8 sources.
- Unicode characters in narrow literals ("...") are recoded to local charset. Without ability to select which one you want to recode to. So it will be recoded differently when different people compile it. Utterly useless; though I am not sure it is still not possible in VS2010, we use VS2008 and there it is not possible.
- Escape sequences are never recoded.
So use the UTF-8 to make files display correctly for everybody, but in narrow strings you have to always use escapes anyway. You may use the characters directly in wide literals, but if you ever need to port the code, using escape sequences there is preferred anyway. It's not readable, yes. You can have the actual text in comment, it will display fine if it is UTF-8.
Hm, that was in particular for encoding, which I know is can of worms in Visual Studio. For the other things, in comments you just use one common language, usually English. And in user output you have to use std::locale
.
As for actual localization, the resources system by default provided by Microsoft toolchain is notoriously difficult to maintain. I strongly recommend using system, that has English literals directly in code and translation catalogues from English to the other language. This ensures that you don't forget to update the translations when the source changes.
Either use Gettext, which can now be read by Boost.Locale or similar framework (e.g. Qt has similar system built in (and KDE replaces it with Gettext anyway)).
Boost.Locale also provides some function that make use of std::locale
more convenient. Mainly extended typesafe printf-like function extended to support calling the std::locale
number/currency/date... formatters internally.