writing non-english applicationsthis article describes how to write applications that communicate with the user in a language other than english. unfortunately many languages use different charsets under unix and windows (and other platforms, to make the situation even more complicated). these charsets usually differ in so many characters that it is impossible to use the same texts under all platforms. the wxwidgets library provides a mechanism that helps you avoid distributing many identical, only differently encoded, packages with your application (e.g. help files and menu items in iso8859-13 and windows-1257). thanks to this mechanism you can, for example, distribute only iso8859-13 data and it will be handled transparently under all systems. please read internationalization which describes the locales concept. in the following text, wherever iso8859-2 and windows-1250 are used, any encodings are meant and any encodings may be substituted there. locales the best way to ensure correctly displayed texts in a gui across platforms is to use locales. write your in-code messages in english or without diacritics and put real messages into the message catalog (see internationalization). a standard .po file begins with a header like this:
# some descriptive title. # copyright (c) year free software foundation, inc. # first author <email@address>, year. # msgid "" msgstr "" "project-id-version: package version\n" "pot-creation-date: 1999-02-19 16:03+0100\n" "po-revision-date: year-mo-da ho:mi+zone\n" "last-translator: full name <email@address>\n" "language-team: language <ll@li.org>\n" "mime-version: 1.0\n" "content-type: text/plain; charset=charset\n" "content-transfer-encoding: encoding\n"note this particular line:
"content-type: text/plain; charset=charset\n"it specifies the charset used by the catalog. all strings in the catalog are encoded using this charset. you have to fill in proper charset information. your .po file may look like this after doing so:
# some descriptive title. # copyright (c) year free software foundation, inc. # first author <email@address>, year. # msgid "" msgstr "" "project-id-version: package version\n" "pot-creation-date: 1999-02-19 16:03+0100\n" "po-revision-date: year-mo-da ho:mi+zone\n" "last-translator: full name <email@address>\n" "language-team: language <ll@li.org>\n" "mime-version: 1.0\n" "content-type: text/plain; charset=iso8859-2\n" "content-transfer-encoding: 8bit\n"(make sure that the header is not marked as fuzzy.) wxwidgets is able to use this catalog under any supported platform (although iso8859-2 is a unix encoding and is normally not understood by windows). how is this done? when you tell the wxlocale class to load a message catalog that contains a correct header, it checks the charset. the catalog is then converted to the charset used (see wxlocale::getsystemencoding and wxlocale::getsystemencodingname) by the user's operating system. this is the default behaviour of the wxlocale class; you can disable it by not passing wxlocale_conv_encoding to wxlocale::init. non-english strings or 8-bit characters in the source code by convention, you should only use characters without diacritics (i.e. 7-bit ascii strings) for msgids in the source code and write them in english. if you port software to wxwindows, you may be confronted with legacy source code containing non-english string literals. instead of translating the strings in the source code to english and putting the original strings into message catalog, you may configure wxwidgets to use non-english msgids and translate to english using message catalogs:
font mapping you can use wxmbconv classes and wxfontmapper to display text:
if (!wxfontmapper::get()->isencodingavailable(enc, facename)) { wxfontencoding alternative; if (wxfontmapper::get()->getaltforencoding(enc, &alternative, facename, false)) { wxcsconv convfrom(wxfontmapper::get()->getencodingname(enc)); wxcsconv convto(wxfontmapper::get()->getencodingname(alternative)); text = wxstring(text.mb_str(convfrom), convto); } else ...failure (or we may try iso8859-1/7bit ascii)... } ...display text...converting data you may want to store all program data (created documents etc.) in the same encoding, let's say utf-8. you can use wxcsconv class to convert data to the encoding used by the system your application is running on (see wxlocale::getsystemencoding). help files if you're using wxhtmlhelpcontroller there is no problem at all. you only need to make sure that all the html files contain the meta tag, e.g.
<meta http-equiv="content-type" content="text/html; charset=iso8859-2">and that the hhp project file contains one additional line in the options section:
charset=iso8859-2this additional entry tells the html help controller what encoding is used in contents and index tables.
|