views:

915

answers:

6

I'm playing around with the locale and i18n stuff in c++ and have been looking for real world examples. I've read through the Josuttis chapter on i18n in his book, and found it useful but with no real world examples to draw from I've no idea if I'm following best practices are committing beginner mistakes. What resources can stackoverflow point me towards both on the web and in print for doing i18n stuff in C++?

Also what libraries are available for C++ that makes i18n easier? What's not in the standard library that needs to be? At first glance, it seems that UTF8 support doesn't exist in the standard library.

Edit:

After doing some more reading, it seems that C and C++ are both Unicode "agnostic". It also seems that for dealing with data encoded in Unicode/UTF8/16/32 one needs to use a third party library. The crux of this is that the standard library itself only thinks about ISO 8859 and related character pages, which change based on what you're locale is set to. That means I probably want to use the ICU library for strings rather than using std::string or even std::wstring.

A: 

Take a look at GNU gettext

It would be interesting to know which C++ library are you using, as some GUI libraries already provide i18n support.

Milan Babuškov
A: 

I second GNU gettext. However, if you're using Qt (and chances are good if you want to do GUI with C++), Qt comes with its own version of gettext and a fine translation tool (Qt Linguist) that makes things easier, and can also be used from non-GUI applications without overhead. We have it even in a service.

However, regarding what C++ lacks, just what comes to my mind:

  • Full support for locales with regard to numbers, dates or currency. And remember that locales differ in more than just the decimal separator, including ordering, which brings me to the second point:
  • C++ itself does not have a format function supporting ordered arguments (because in another language, the word order might be different than in your language). You can use boost::format for this. Qt of course supports it as well.

Also have a look at what you had to do for yourself, even if these things are supported. .NET for example comes with a comprehensive list of locales that are ready for use.

OregonGhost
+1  A: 

You've been pointed to GNU gettext, which allows you to replace literal strings with localized versions at run time - one aspect of localization (which is what happens after you've done the internationalization, when someone actually uses your internationalized code in a specific locale). You've also been pointed to the Boost libraries; that is usually a good answer for anything related to C++.

Another place you might look is the ICU (International Components for Unicode) project. And as a source of data, you might look at the CLDR (Common Locale Data Repository) as a source of information about different locales; the Unicode web site also has lots of information about other aspects of different cultures because it deals with many languages.

And as a final resource for now, a rather specialized one, there is the Olson Time Zone database, which is updated multiple times each year to keep track of the way different countries change their rules on when to change between winter and summer (daylight saving and standard) time.

Jonathan Leffler
A: 

Take a look at wxWidgets examples of internationalization. It has a non-gnu implementation of the translation mechanism used in gettext (mentioned previously). You can use it even in commercial application because the wxWidgets license allows you to do so.

If you are just looking at a method for internationalizing the application gettext is the starting point.

Iulian Şerbănoiu
A: 

For the UTF-8 support, take a look at UTF-8 CPP library.

Nemanja Trifunovic
A: 

You do not need libraries to accomplish this task. See the MS guide for Satellite DLLs here.

If you specify to use Unicode in the project settings and use Unicode String functions (instead of char) then the standard use of Satellite DLLs to hold locale specific data (dialog boxes, Strings etc) will be enough.

Windows itself will take care of finding the correct resource so long as the DLL is correctly named. The suffixs needed for the satellite DLLs are here .

ewh105