]>
Commit | Line | Data |
---|---|---|
f8d8ae38 VZ |
1 | \section{Internationalization}\label{internationalization} |
2 | ||
f6bcfd97 | 3 | Although internationalization of an application (i18n for short) involves far |
dceb1c09 | 4 | more than just translating its text messages to another message - date, time and |
f8d8ae38 VZ |
5 | currency formats need changing too, some languages are written left to right |
6 | and others right to left, character encoding may differ and many other things | |
dceb1c09 | 7 | may need changing too - it is a necessary first step. wxWidgets provides |
f6bcfd97 | 8 | facilities for message translation with its |
f8d8ae38 | 9 | \helpref{wxLocale}{wxlocale} class and is itself fully translated into several |
fc2171bd | 10 | languages. Please consult wxWidgets home page for the most up-to-date |
2a47d3c1 | 11 | translations - and if you translate it into one of the languages not done |
43e8916f MW |
12 | yet, your translations would be gratefully accepted for inclusion into future |
13 | versions of the library! | |
f8d8ae38 | 14 | |
43e8916f | 15 | The wxWidgets approach to i18n closely follows the GNU gettext package. wxWidgets uses the |
f8d8ae38 VZ |
16 | message catalogs which are binary compatible with gettext catalogs and this |
17 | allows to use all of the programs in this package to work with them. But note | |
43e8916f | 18 | that no additional libraries are needed during run-time, however, so you |
f8d8ae38 VZ |
19 | have only the message catalogs to distribute and nothing else. |
20 | ||
2a47d3c1 | 21 | During program development you will need the gettext package for |
f8d8ae38 VZ |
22 | working with message catalogs. {\bf Warning:} gettext versions < 0.10 are known |
23 | to be buggy, so you should find a later version of it! | |
24 | ||
25 | There are two kinds of message catalogs: source catalogs which are text files | |
26 | with extension .po and binary catalogs which are created from the source ones | |
f6bcfd97 | 27 | with {\it msgfmt} program (part of gettext package) and have the extension .mo. |
f8d8ae38 VZ |
28 | Only the binary files are needed during program execution. |
29 | ||
30 | The program i18n involves several steps: | |
31 | ||
32 | \begin{enumerate}\itemsep=0pt | |
f8d8ae38 | 33 | \item Translating the strings in the program text using |
0bbe4e29 | 34 | \helpref{wxGetTranslation}{wxgettranslation} or equivalently the |
30e5722f | 35 | \helpref{\_()}{underscore} macro. |
f8d8ae38 | 36 | \item Extracting the strings to be translated from the program: this uses the |
0bbe4e29 VZ |
37 | work done in the previous step because {\tt xgettext} program used for string |
38 | extraction recognises the standard \_() as well as (using its {\tt -k} option) | |
39 | our wxGetTranslation and extracts all strings inside the calls to these | |
40 | functions. Alternatively, you may use {\tt -a} option to extract all the | |
41 | strings, but it will usually result in many strings being found which don't | |
dceb1c09 | 42 | have to be translated at all. This will create a text message catalog - a .po |
0bbe4e29 | 43 | file. |
f8d8ae38 VZ |
44 | \item Translating the strings extracted in the previous step to other |
45 | language(s). It involves editing the .po file. | |
f8d8ae38 | 46 | \item Compiling the .po file into .mo file to be used by the program. |
4fbbe847 VZ |
47 | \item Installing the .mo files with your application in the appropriate |
48 | location for the target system which is the one returned by | |
49 | \helpref{wxStandardPaths::GetLocalizedResourcesDir(wxStandardPaths::ResourceCat\_Messages)}{wxstandardpathsgetlocalizedresourcesdir}. | |
50 | If the message catalogs are not installed in this default location you may | |
51 | explicitly use \helpref{AddCatalogLookupPathPrefix()}{wxlocaleaddcataloglookuppathprefix} to | |
52 | still allow wxWidgets to find them but it is strongly recommended to use the | |
53 | default directory. | |
f8d8ae38 VZ |
54 | \item Setting the appropriate locale in your program to use the strings for the |
55 | given language: see \helpref{wxLocale}{wxlocale}. | |
f8d8ae38 VZ |
56 | \end{enumerate} |
57 | ||
2a47d3c1 | 58 | See also the GNU gettext documentation linked from {\tt docs/html/index.htm} in |
fc2171bd | 59 | your wxWidgets distribution. |
2a47d3c1 | 60 | |
528e0faf | 61 | See also \helpref{Writing non-English applications}{nonenglishoverview}. |
9005a56e VS |
62 | It focuses on handling charsets related problems. |
63 | ||
fb848f58 | 64 | Finally, take a look at the \helpref{i18n sample}{sampleinternat} which shows |
43e8916f | 65 | you how all this looks in practice. |
fb848f58 | 66 | |
03cc5f8e JS |
67 | \wxheading{Translating menu accelerators} |
68 | ||
69 | If you translate the accelerator modifier names (Ctrl, Alt and Shift) in your menu labels, you may find | |
70 | the accelerators no longer work. In your message catalogs, you need to provide individual translations | |
71 | of these modifiers from their lower case names (ctrl, alt, shift) so that the wxWidgets accelerator | |
72 | code can recognise them even when translated. wxWidgets does not provide translations for all of these | |
73 | currently. wxWidgets does not yet handle translated special key names such as Backspace, | |
74 | End, Insert, etc. | |
75 |