]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tnoneng.tex
Use generic collapsible pane for wxUniv based builds.
[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
f70c0443 4the user in a language other than English. Unfortunately many languages use
9005a56e 5different charsets under Unix and Windows (and other platforms, to make
f70c0443
WS
6the situation even more complicated). These charsets usually differ in so
7many characters that it is impossible to use the same texts under all
8platforms.
07e285be 9
f70c0443 10The wxWidgets library provides a mechanism that helps you avoid distributing many
9005a56e
VS
11identical, only differently encoded, packages with your application
12(e.g. help files and menu items in iso8859-13 and windows-1257). Thanks
f6bcfd97 13to this mechanism you can, for example, distribute only iso8859-13 data
9005a56e
VS
14and it will be handled transparently under all systems.
15
54cd4332 16Please read \helpref{Internationalization}{internationalization} which
f6bcfd97 17describes the locales concept.
9005a56e 18
f6bcfd97 19In the following text, wherever {\it iso8859-2} and {\it windows-1250} are
9005a56e
VS
20used, any encodings are meant and any encodings may be substituted there.
21
9005a56e
VS
22\wxheading{Locales}
23
f6bcfd97 24The best way to ensure correctly displayed texts in a GUI across platforms
54cd4332 25is to use locales. Write your in-code messages in English or without
f6bcfd97 26diacritics and put real messages into the message catalog (see
54cd4332 27\helpref{Internationalization}{internationalization}).
9005a56e 28
f6bcfd97 29A standard .po file begins with a header like this:
54cd4332
VS
30
31\begin{verbatim}
32# SOME DESCRIPTIVE TITLE.
33# Copyright (C) YEAR Free Software Foundation, Inc.
34# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
35#
54cd4332
VS
36msgid ""
37msgstr ""
38"Project-Id-Version: PACKAGE VERSION\n"
39"POT-Creation-Date: 1999-02-19 16:03+0100\n"
40"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
41"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
42"Language-Team: LANGUAGE <LL@li.org>\n"
43"MIME-Version: 1.0\n"
44"Content-Type: text/plain; charset=CHARSET\n"
45"Content-Transfer-Encoding: ENCODING\n"
46\end{verbatim}
47
ae71a6e8 48Note this particular line:
54cd4332
VS
49
50\begin{verbatim}
54cd4332
VS
51"Content-Type: text/plain; charset=CHARSET\n"
52\end{verbatim}
53
07e285be
VS
54It specifies the charset used by the catalog. All strings in the catalog
55are encoded using this charset.
54cd4332 56
07e285be
VS
57You have to fill in proper charset information. Your .po file may look like this
58after doing so:
54cd4332
VS
59
60\begin{verbatim}
61# SOME DESCRIPTIVE TITLE.
62# Copyright (C) YEAR Free Software Foundation, Inc.
63# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
64#
65msgid ""
66msgstr ""
67"Project-Id-Version: PACKAGE VERSION\n"
68"POT-Creation-Date: 1999-02-19 16:03+0100\n"
69"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
70"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
71"Language-Team: LANGUAGE <LL@li.org>\n"
72"MIME-Version: 1.0\n"
73"Content-Type: text/plain; charset=iso8859-2\n"
07e285be 74"Content-Transfer-Encoding: 8bit\n"
54cd4332
VS
75\end{verbatim}
76
07e285be
VS
77(Make sure that the header is {\bf not} marked as {\it fuzzy}.)
78
fc2171bd 79wxWidgets is able to use this catalog under any supported platform
07e285be
VS
80(although iso8859-2 is a Unix encoding and is normally not understood by
81Windows).
54cd4332 82
f6bcfd97 83How is this done? When you tell the wxLocale class to load a message catalog that
f70c0443 84contains a correct header, it checks the charset. The catalog is then converted
ae71a6e8
VS
85to the charset used (see
86\helpref{wxLocale::GetSystemEncoding}{wxlocalegetsystemencoding} and
87\helpref{wxLocale::GetSystemEncodingName}{wxlocalegetsystemencodingname}) by
f70c0443 88the user's operating system. This is the default behaviour of the
ae71a6e8
VS
89\helpref{wxLocale}{wxlocale} class; you can disable it by {\bf not} passing
90{\tt wxLOCALE\_CONV\_ENCODING} to \helpref{wxLocale::Init}{wxlocaleinit}.
9005a56e 91
d721baa9
VS
92\wxheading{Non-English strings or 8-bit characters in the source code}
93
94By convention, you should only use characters without diacritics (i.e. 7-bit
95ASCII strings) for msgids in the source code and write them in English.
96
97If you port software to wxWindows, you may be confronted with legacy source
98code containing non-English string literals. Instead of translating the strings
99in the source code to English and putting the original strings into message
100catalog, you may configure wxWidgets to use non-English msgids and translate to
101English using message catalogs:
102
103\begin{enumerate}
104\item{If you use the program {\tt xgettext} to extract the strings from
105the source code, specify the option {\tt --from-code=<source code charset>}.}
106\item{Specify the source code language and charset as arguments to
107\helpref{wxLocale::AddCatalog}{wxlocaleaddcatalog}. For example:
108\begin{verbatim}
109locale.AddCatalog(_T("myapp"),
110 wxLANGUAGE_GERMAN, _T("iso-8859-1"));
111\end{verbatim}
112}
113\end{enumerate}
114
9005a56e
VS
115\wxheading{Font mapping}
116
a663cce7 117You can use \helpref{wxMBConv classes}{mbconvclasses} and
54cd4332
VS
118\helpref{wxFontMapper}{wxfontmapper} to display text:
119
120\begin{verbatim}
142b3bc2 121if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
54cd4332
VS
122{
123 wxFontEncoding alternative;
a663cce7
VS
124 if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
125 facename, false))
54cd4332 126 {
a663cce7
VS
127 wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
128 wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
129 text = wxString(text.mb_str(convFrom), convTo);
54cd4332
VS
130 }
131 else
a663cce7 132 ...failure (or we may try iso8859-1/7bit ASCII)...
54cd4332
VS
133}
134...display text...
135\end{verbatim}
136
54cd4332
VS
137\wxheading{Converting data}
138
139You may want to store all program data (created documents etc.) in
a663cce7 140the same encoding, let's say {\tt utf-8}. You can use
f70c0443 141\helpref{wxCSConv}{wxcsconv} class to convert data to the encoding used by the
a663cce7
VS
142system your application is running on (see
143\helpref{wxLocale::GetSystemEncoding}{wxlocalegetsystemencoding}).
54cd4332 144
9005a56e
VS
145\wxheading{Help files}
146
147If you're using \helpref{wxHtmlHelpController}{wxhtmlhelpcontroller} there is
f70c0443 148no problem at all. You only need to make sure that all the HTML files contain
f6bcfd97 149the META tag, e.g.
9005a56e
VS
150
151\begin{verbatim}
ea129d33 152<meta http-equiv="Content-Type" content="text/html; charset=iso8859-2">
9005a56e
VS
153\end{verbatim}
154
f6bcfd97 155and that the hhp project file contains one additional line in the {\tt OPTIONS}
9005a56e
VS
156section:
157
158\begin{verbatim}
159Charset=iso8859-2
160\end{verbatim}
161
f6bcfd97 162This additional entry tells the HTML help controller what encoding is used
9005a56e 163in contents and index tables.
457e6c54 164