1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Writing Non-English Applications</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Categories</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Writing Non-English Applications </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_nonenglish_locales">Locales</a></li>
<li class="level1"><a href="#overview_nonenglish_strings">Non-English Strings or 8-bit Characters in Source</a></li>
<li class="level1"><a href="#overview_nonenglish_fontmapping">Font Mapping</a></li>
<li class="level1"><a href="#overview_nonenglish_converting">Converting Data</a></li>
<li class="level1"><a href="#overview_nonenglish_help">Help Files</a></li>
</ul>
</div>
<div class="textblock"><p>This article describes how to write applications that communicate with the user in a language other than English.</p>
<p>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.</p>
<p>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.</p>
<p>Please read the <a class="el" href="overview_i18n.html">Internationalization</a> which describes the locales concept.</p>
<p>In the following text, wherever <em>iso8859-2</em> and <em>windows-1250</em> are used, any encodings are meant and any encodings may be substituted there.</p>
<h1><a class="anchor" id="overview_nonenglish_locales"></a>
Locales</h1>
<p>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 <a class="el" href="overview_i18n.html">Internationalization</a>).</p>
<p>A standard .po file begins with a header like this:</p>
<div class="fragment"><div class="line"><span class="preprocessor"># SOME DESCRIPTIVE TITLE.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor"># Copyright (C) YEAR Free Software Foundation, Inc.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor"># FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#</span></div>
<div class="line"><span class="preprocessor"></span>msgid <span class="stringliteral">""</span></div>
<div class="line">msgstr <span class="stringliteral">""</span></div>
<div class="line"><span class="stringliteral">"Project-Id-Version: PACKAGE VERSION\n"</span></div>
<div class="line"><span class="stringliteral">"POT-Creation-Date: 1999-02-19 16:03+0100\n"</span></div>
<div class="line"><span class="stringliteral">"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"</span></div>
<div class="line"><span class="stringliteral">"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"</span></div>
<div class="line"><span class="stringliteral">"Language-Team: LANGUAGE <LL@li.org>\n"</span></div>
<div class="line"><span class="stringliteral">"MIME-Version: 1.0\n"</span></div>
<div class="line"><span class="stringliteral">"Content-Type: text/plain; charset=CHARSET\n"</span></div>
<div class="line"><span class="stringliteral">"Content-Transfer-Encoding: ENCODING\n"</span></div>
</div><!-- fragment --><p>Note this particular line:</p>
<div class="fragment"><div class="line"><span class="stringliteral">"Content-Type: text/plain; charset=CHARSET\n"</span></div>
</div><!-- fragment --><p>It specifies the charset used by the catalog. All strings in the catalog are encoded using this charset.</p>
<p>You have to fill in proper charset information. Your .po file may look like this after doing so:</p>
<div class="fragment"><div class="line"><span class="preprocessor"># SOME DESCRIPTIVE TITLE.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor"># Copyright (C) YEAR Free Software Foundation, Inc.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor"># FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#</span></div>
<div class="line"><span class="preprocessor"></span>msgid <span class="stringliteral">""</span></div>
<div class="line">msgstr <span class="stringliteral">""</span></div>
<div class="line"><span class="stringliteral">"Project-Id-Version: PACKAGE VERSION\n"</span></div>
<div class="line"><span class="stringliteral">"POT-Creation-Date: 1999-02-19 16:03+0100\n"</span></div>
<div class="line"><span class="stringliteral">"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"</span></div>
<div class="line"><span class="stringliteral">"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"</span></div>
<div class="line"><span class="stringliteral">"Language-Team: LANGUAGE <LL@li.org>\n"</span></div>
<div class="line"><span class="stringliteral">"MIME-Version: 1.0\n"</span></div>
<div class="line"><span class="stringliteral">"Content-Type: text/plain; charset=iso8859-2\n"</span></div>
<div class="line"><span class="stringliteral">"Content-Transfer-Encoding: 8bit\n"</span></div>
</div><!-- fragment --><p>(Make sure that the header is <b>not</b> marked as <em>fuzzy</em>.)</p>
<p>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).</p>
<p>How is this done? When you tell the <a class="el" href="classwx_locale.html" title="wxLocale class encapsulates all language-dependent settings and is a generalization of the C locale c...">wxLocale</a> 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 <a class="el" href="classwx_locale.html#aa807dd0db36c3bd6556c2a37014239d6" title="Tries to detect the user's default font encoding.">wxLocale::GetSystemEncoding</a> and <a class="el" href="classwx_locale.html#a301032f2ecdf0be5321fab2281c71206" title="Tries to detect the name of the user's default font encoding.">wxLocale::GetSystemEncodingName</a>) by the user's operating system.</p>
<h1><a class="anchor" id="overview_nonenglish_strings"></a>
Non-English Strings or 8-bit Characters in Source</h1>
<p>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.</p>
<p>If you port software to wxWidgets, 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:</p>
<ul>
<li>If you use the program <code>xgettext</code> to extract the strings from the source code, specify the option <code>–from-code=<source code charset></code>. </li>
<li>Specify the source code language and charset as arguments to <a class="el" href="classwx_locale.html#a1e9eb6387646a94c65d1493b5be7641c" title="Calls wxTranslations::AddCatalog(const wxString&).">wxLocale::AddCatalog</a>. For example: <div class="fragment"><div class="line">locale.AddCatalog(<a class="code" href="group__group__funcmacro__string.html#ga437ea6ba615b75dac8603e96ec864160" title="This macro can be used with character and string literals (in other words, 'x' or "foo") to automatic...">wxT</a>(<span class="stringliteral">"myapp"</span>), <a class="code" href="language_8h.html#a7d1c74ce43b2fb7acf7a6fa438c0ee86a8fc3d592c6f1ac6c9bdfb3a006cec1dd">wxLANGUAGE_GERMAN</a>, <a class="code" href="group__group__funcmacro__string.html#ga437ea6ba615b75dac8603e96ec864160" title="This macro can be used with character and string literals (in other words, 'x' or "foo") to automatic...">wxT</a>(<span class="stringliteral">"iso-8859-1"</span>));</div>
</div><!-- fragment --></li>
</ul>
<h1><a class="anchor" id="overview_nonenglish_fontmapping"></a>
Font Mapping</h1>
<p>You can use <a class="el" href="overview_mbconv.html">wxMBConv Overview</a> and <a class="el" href="classwx_font_mapper.html" title="wxFontMapper manages user-definable correspondence between logical font names and the fonts present o...">wxFontMapper</a> to display text:</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> (!<a class="code" href="classwx_font_mapper.html#a2bd9e7f8c2c6808c4508ed05e9f1cfe5" title="Get the current font mapper object.">wxFontMapper::Get</a>()->IsEncodingAvailable(enc, facename))</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="interface_2wx_2font_8h.html#a09016a7497d1ec6defdf13fd6439acca" title="Font encodings.">wxFontEncoding</a> alternative;</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="classwx_font_mapper.html#a2bd9e7f8c2c6808c4508ed05e9f1cfe5" title="Get the current font mapper object.">wxFontMapper::Get</a>()->GetAltForEncoding(enc, &alternative,</div>
<div class="line"> facename, <span class="keyword">false</span>))</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="classwx_c_s_conv.html" title="This class converts between any character set supported by the system and Unicode.">wxCSConv</a> convFrom(<a class="code" href="classwx_font_mapper.html#a2bd9e7f8c2c6808c4508ed05e9f1cfe5" title="Get the current font mapper object.">wxFontMapper::Get</a>()->GetEncodingName(enc));</div>
<div class="line"> <a class="code" href="classwx_c_s_conv.html" title="This class converts between any character set supported by the system and Unicode.">wxCSConv</a> convTo(<a class="code" href="classwx_font_mapper.html#a2bd9e7f8c2c6808c4508ed05e9f1cfe5" title="Get the current font mapper object.">wxFontMapper::Get</a>()->GetEncodingName(alternative));</div>
<div class="line"> text = <a class="code" href="classwx_string.html" title="String class for passing textual data to or receiving it from wxWidgets.">wxString</a>(text.<a class="code" href="classwx_string.html#adcfd12e6d0765b1d74bccc3d63d02e98" title="Returns the multibyte (C string) representation of the string using conv's wxMBConv::cWC2MB method an...">mb_str</a>(convFrom), convTo);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> ...failure (or we may <span class="keywordflow">try</span> iso8859-1/7bit ASCII)...</div>
<div class="line">}</div>
<div class="line">...display text...</div>
</div><!-- fragment --><h1><a class="anchor" id="overview_nonenglish_converting"></a>
Converting Data</h1>
<p>You may want to store all program data (created documents etc.) in the same encoding, let's say <code>utf-8</code>. You can use <a class="el" href="classwx_c_s_conv.html" title="This class converts between any character set supported by the system and Unicode.">wxCSConv</a> to convert data to the encoding used by the system your application is running on (see <a class="el" href="classwx_locale.html#aa807dd0db36c3bd6556c2a37014239d6" title="Tries to detect the user's default font encoding.">wxLocale::GetSystemEncoding</a>).</p>
<h1><a class="anchor" id="overview_nonenglish_help"></a>
Help Files</h1>
<p>If you're using <a class="el" href="classwx_html_help_controller.html" title="This help controller provides an easy way of displaying HTML help in your application (see HTML Sampl...">wxHtmlHelpController</a> there is no problem at all. You only need to make sure that all the HTML files contain the META tag:</p>
<div class="fragment"><div class="line"><meta http-equiv=<span class="stringliteral">"Content-Type"</span> content=<span class="stringliteral">"text/html; charset=iso8859-2"</span>></div>
</div><!-- fragment --><p>Also, the hhp project file needs one additional line in the <code>OPTIONS</code> section:</p>
<div class="fragment"><div class="line">Charset=iso8859-2</div>
</div><!-- fragment --><p>This additional entry tells the HTML help controller what encoding is used in contents and index tables. </p>
</div></div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|