]>
Commit | Line | Data |
---|---|---|
9005a56e VS |
1 | \section{Writing non-English applications}\label{nonenglishoverview} |
2 | ||
3 | This article describes how to write applications that communicate with | |
4 | user in language other than English. Unfortunately many languages use | |
5 | different charsets under Unix and Windows (and other platforms, to make | |
6 | situation even more complicated). These charsets usually differ in so | |
7 | many characters it is impossible to use same texts under all platforms. | |
07e285be VS |
8 | |
9 | wxWindows library provides mechanism that helps you avoid distributing many | |
9005a56e VS |
10 | identical, only differently encoded, packages with your application |
11 | (e.g. help files and menu items in iso8859-13 and windows-1257). Thanks | |
f6bcfd97 | 12 | to this mechanism you can, for example, distribute only iso8859-13 data |
9005a56e VS |
13 | and it will be handled transparently under all systems. |
14 | ||
54cd4332 | 15 | Please read \helpref{Internationalization}{internationalization} which |
f6bcfd97 | 16 | describes the locales concept. |
9005a56e | 17 | |
f6bcfd97 | 18 | In the following text, wherever {\it iso8859-2} and {\it windows-1250} are |
9005a56e VS |
19 | used, any encodings are meant and any encodings may be substituted there. |
20 | ||
9005a56e VS |
21 | \wxheading{Locales} |
22 | ||
f6bcfd97 | 23 | The best way to ensure correctly displayed texts in a GUI across platforms |
54cd4332 | 24 | is to use locales. Write your in-code messages in English or without |
f6bcfd97 | 25 | diacritics and put real messages into the message catalog (see |
54cd4332 | 26 | \helpref{Internationalization}{internationalization}). |
9005a56e | 27 | |
f6bcfd97 | 28 | A standard .po file begins with a header like this: |
54cd4332 VS |
29 | |
30 | \begin{verbatim} | |
31 | # SOME DESCRIPTIVE TITLE. | |
32 | # Copyright (C) YEAR Free Software Foundation, Inc. | |
33 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | |
34 | # | |
54cd4332 VS |
35 | msgid "" |
36 | msgstr "" | |
37 | "Project-Id-Version: PACKAGE VERSION\n" | |
38 | "POT-Creation-Date: 1999-02-19 16:03+0100\n" | |
39 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
40 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
41 | "Language-Team: LANGUAGE <LL@li.org>\n" | |
42 | "MIME-Version: 1.0\n" | |
43 | "Content-Type: text/plain; charset=CHARSET\n" | |
44 | "Content-Transfer-Encoding: ENCODING\n" | |
45 | \end{verbatim} | |
46 | ||
07e285be | 47 | Notice this particular line: |
54cd4332 VS |
48 | |
49 | \begin{verbatim} | |
54cd4332 VS |
50 | "Content-Type: text/plain; charset=CHARSET\n" |
51 | \end{verbatim} | |
52 | ||
07e285be VS |
53 | It specifies the charset used by the catalog. All strings in the catalog |
54 | are encoded using this charset. | |
54cd4332 | 55 | |
07e285be VS |
56 | You have to fill in proper charset information. Your .po file may look like this |
57 | after doing so: | |
54cd4332 VS |
58 | |
59 | \begin{verbatim} | |
60 | # SOME DESCRIPTIVE TITLE. | |
61 | # Copyright (C) YEAR Free Software Foundation, Inc. | |
62 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | |
63 | # | |
64 | msgid "" | |
65 | msgstr "" | |
66 | "Project-Id-Version: PACKAGE VERSION\n" | |
67 | "POT-Creation-Date: 1999-02-19 16:03+0100\n" | |
68 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
69 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
70 | "Language-Team: LANGUAGE <LL@li.org>\n" | |
71 | "MIME-Version: 1.0\n" | |
72 | "Content-Type: text/plain; charset=iso8859-2\n" | |
07e285be | 73 | "Content-Transfer-Encoding: 8bit\n" |
54cd4332 VS |
74 | \end{verbatim} |
75 | ||
07e285be VS |
76 | (Make sure that the header is {\bf not} marked as {\it fuzzy}.) |
77 | ||
54cd4332 | 78 | wxWindows is able to use this catalog under any supported platform |
07e285be VS |
79 | (although iso8859-2 is a Unix encoding and is normally not understood by |
80 | Windows). | |
54cd4332 | 81 | |
f6bcfd97 | 82 | How is this done? When you tell the wxLocale class to load a message catalog that |
07e285be | 83 | contains correct header, it checks the charset. If the |
54cd4332 | 84 | charset is "alien" on the platform the program is currently running (e.g. |
f6bcfd97 | 85 | any of ISO encodings under Windows or CP12XX under Unix) it uses |
54cd4332 | 86 | \helpref{wxEncodingConverter::GetPlatformEquivalents}{wxencodingconvertergetplatformequivalents} |
f6bcfd97 | 87 | to obtain an encoding that is more common on this platform and converts |
54cd4332 | 88 | the message catalog to this encoding. Note that it does {\bf not} check |
07e285be VS |
89 | for presence of fonts in the "platform" encoding! It only assumes that it is |
90 | always better to have strings in platform native encoding than in an encoding | |
91 | that is rarely (if ever) used. | |
54cd4332 | 92 | |
f6bcfd97 | 93 | The behaviour described above is disabled by default. |
54cd4332 VS |
94 | You must set {\it bConvertEncoding} to TRUE in |
95 | \helpref{wxLocale constructor}{wxlocaledefctor} in order to enable | |
f6bcfd97 | 96 | runtime encoding conversion. |
9005a56e | 97 | |
9005a56e VS |
98 | \wxheading{Font mapping} |
99 | ||
528e0faf | 100 | You can use \helpref{wxEncodingConverter}{wxencodingconverter} and |
54cd4332 VS |
101 | \helpref{wxFontMapper}{wxfontmapper} to display text: |
102 | ||
103 | \begin{verbatim} | |
104 | if (!wxTheFontMapper->IsEncodingAvailable(enc, facename)) | |
105 | { | |
106 | wxFontEncoding alternative; | |
107 | if (wxTheFontMapper->GetAltForEncoding(enc, &alternative, | |
108 | facename, FALSE)) | |
109 | { | |
110 | wxEncodingConverted encconv; | |
111 | if (!encconv.Init(enc, alternative)) | |
112 | ...failure... | |
113 | else | |
114 | text = encconv.Convert(text); | |
115 | } | |
116 | else | |
117 | ...failure... | |
118 | } | |
119 | ...display text... | |
120 | \end{verbatim} | |
121 | ||
54cd4332 VS |
122 | \wxheading{Converting data} |
123 | ||
124 | You may want to store all program data (created documents etc.) in | |
f6bcfd97 | 125 | the same encoding, let's say windows1250. Obviously, the best way would |
54cd4332 VS |
126 | be to use \helpref{wxEncodingConverter}{wxencodingconverter}. |
127 | ||
9005a56e VS |
128 | \wxheading{Help files} |
129 | ||
130 | If you're using \helpref{wxHtmlHelpController}{wxhtmlhelpcontroller} there is | |
f6bcfd97 BP |
131 | no problem at all. You must only make sure that all the HTML files contain |
132 | the META tag, e.g. | |
9005a56e VS |
133 | |
134 | \begin{verbatim} | |
ea129d33 | 135 | <meta http-equiv="Content-Type" content="text/html; charset=iso8859-2"> |
9005a56e VS |
136 | \end{verbatim} |
137 | ||
f6bcfd97 | 138 | and that the hhp project file contains one additional line in the {\tt OPTIONS} |
9005a56e VS |
139 | section: |
140 | ||
141 | \begin{verbatim} | |
142 | Charset=iso8859-2 | |
143 | \end{verbatim} | |
144 | ||
f6bcfd97 | 145 | This additional entry tells the HTML help controller what encoding is used |
9005a56e | 146 | in contents and index tables. |
457e6c54 | 147 |