]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tnoneng.tex
implemented nested index entries and index entries pointing to multiple documents...
[wxWidgets.git] / docs / latex / wx / tnoneng.tex
CommitLineData
9005a56e
VS
1\section{Writing non-English applications}\label{nonenglishoverview}
2
3This article describes how to write applications that communicate with
4user in language other than English. Unfortunately many languages use
5different charsets under Unix and Windows (and other platforms, to make
6situation even more complicated). These charsets usually differ in so
7many characters it is impossible to use same texts under all platforms.
07e285be 8
fc2171bd 9wxWidgets library provides mechanism that helps you avoid distributing many
9005a56e
VS
10identical, only differently encoded, packages with your application
11(e.g. help files and menu items in iso8859-13 and windows-1257). Thanks
f6bcfd97 12to this mechanism you can, for example, distribute only iso8859-13 data
9005a56e
VS
13and it will be handled transparently under all systems.
14
54cd4332 15Please read \helpref{Internationalization}{internationalization} which
f6bcfd97 16describes the locales concept.
9005a56e 17
f6bcfd97 18In the following text, wherever {\it iso8859-2} and {\it windows-1250} are
9005a56e
VS
19used, any encodings are meant and any encodings may be substituted there.
20
9005a56e
VS
21\wxheading{Locales}
22
f6bcfd97 23The best way to ensure correctly displayed texts in a GUI across platforms
54cd4332 24is to use locales. Write your in-code messages in English or without
f6bcfd97 25diacritics and put real messages into the message catalog (see
54cd4332 26\helpref{Internationalization}{internationalization}).
9005a56e 27
f6bcfd97 28A 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
35msgid ""
36msgstr ""
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
ae71a6e8 47Note 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
53It specifies the charset used by the catalog. All strings in the catalog
54are encoded using this charset.
54cd4332 55
07e285be
VS
56You have to fill in proper charset information. Your .po file may look like this
57after 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#
64msgid ""
65msgstr ""
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
fc2171bd 78wxWidgets 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
80Windows).
54cd4332 81
f6bcfd97 82How is this done? When you tell the wxLocale class to load a message catalog that
ae71a6e8
VS
83contains correct header, it checks the charset. The catalog is then converted
84to the charset used (see
85\helpref{wxLocale::GetSystemEncoding}{wxlocalegetsystemencoding} and
86\helpref{wxLocale::GetSystemEncodingName}{wxlocalegetsystemencodingname}) by
87user's operating system. This is default behaviour of the
88\helpref{wxLocale}{wxlocale} class; you can disable it by {\bf not} passing
89{\tt wxLOCALE\_CONV\_ENCODING} to \helpref{wxLocale::Init}{wxlocaleinit}.
9005a56e 90
d721baa9
VS
91\wxheading{Non-English strings or 8-bit characters in the source code}
92
93By convention, you should only use characters without diacritics (i.e. 7-bit
94ASCII strings) for msgids in the source code and write them in English.
95
96If you port software to wxWindows, you may be confronted with legacy source
97code containing non-English string literals. Instead of translating the strings
98in the source code to English and putting the original strings into message
99catalog, you may configure wxWidgets to use non-English msgids and translate to
100English using message catalogs:
101
102\begin{enumerate}
103\item{If you use the program {\tt xgettext} to extract the strings from
104the source code, specify the option {\tt --from-code=<source code charset>}.}
105\item{Specify the source code language and charset as arguments to
106\helpref{wxLocale::AddCatalog}{wxlocaleaddcatalog}. For example:
107\begin{verbatim}
108locale.AddCatalog(_T("myapp"),
109 wxLANGUAGE_GERMAN, _T("iso-8859-1"));
110\end{verbatim}
111}
112\end{enumerate}
113
9005a56e
VS
114\wxheading{Font mapping}
115
a663cce7 116You can use \helpref{wxMBConv classes}{mbconvclasses} and
54cd4332
VS
117\helpref{wxFontMapper}{wxfontmapper} to display text:
118
119\begin{verbatim}
142b3bc2 120if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
54cd4332
VS
121{
122 wxFontEncoding alternative;
a663cce7
VS
123 if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
124 facename, false))
54cd4332 125 {
a663cce7
VS
126 wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
127 wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
128 text = wxString(text.mb_str(convFrom), convTo);
54cd4332
VS
129 }
130 else
a663cce7 131 ...failure (or we may try iso8859-1/7bit ASCII)...
54cd4332
VS
132}
133...display text...
134\end{verbatim}
135
54cd4332
VS
136\wxheading{Converting data}
137
138You may want to store all program data (created documents etc.) in
a663cce7
VS
139the same encoding, let's say {\tt utf-8}. You can use
140\helpref{wxCSConv}{wxcsconv} class to convert data to encoding used by the
141system your application is running on (see
142\helpref{wxLocale::GetSystemEncoding}{wxlocalegetsystemencoding}).
54cd4332 143
9005a56e
VS
144\wxheading{Help files}
145
146If you're using \helpref{wxHtmlHelpController}{wxhtmlhelpcontroller} there is
f6bcfd97
BP
147no problem at all. You must only make sure that all the HTML files contain
148the META tag, e.g.
9005a56e
VS
149
150\begin{verbatim}
ea129d33 151<meta http-equiv="Content-Type" content="text/html; charset=iso8859-2">
9005a56e
VS
152\end{verbatim}
153
f6bcfd97 154and that the hhp project file contains one additional line in the {\tt OPTIONS}
9005a56e
VS
155section:
156
157\begin{verbatim}
158Charset=iso8859-2
159\end{verbatim}
160
f6bcfd97 161This additional entry tells the HTML help controller what encoding is used
9005a56e 162in contents and index tables.
457e6c54 163