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
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Pitfalls</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="chapter-internationalization.html" title="Chapter 27. Internationalization and Localization">
<link rel="prev" href="sec-i18n-expecting-utf8.html" title="Expecting UTF8">
<link rel="next" href="sec-i18n-getting-help-with-translations.html" title="Getting help with translations">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Pitfalls</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-i18n-expecting-utf8.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 27. Internationalization and Localization</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-i18n-getting-help-with-translations.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-i18n-pitfalls"></a>Pitfalls</h2></div></div></div>
<p>There are a few common mistakes that you would discover eventually yourself. But this section might help you to avoid them.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="i18n-string-semantics"></a>Same strings, different semantics</h3></div></div></div>
<p>Sometimes two English strings are identical but have different meanings in
different contexts, so they would probably not be identical when translated. Since the English strings are
used as look-up keys, this causes problems.</p>
<p>
In these cases, you should add extra characters to the strings. For instance,
use <code class="literal">"jumps[noun]"</code> and <code class="literal">"jumps[verb]"</code>
instead of just <code class="literal">"jumps"</code> and strip them again outside the
<code class="function">gettext</code> call. If you add extra characters you should also
add a comment for the translators before the <code class="function">gettext</code> call.
Such comments will be shown in the <code class="filename">.po</code> files. For
instance:
</p>
<pre class="programlisting"><code class="code">// note to translators: don't translate the "[noun]" part - it is
// just here to distinguish the string from another "jumps" string
text = strip(gettext("jumps[noun]"), "[noun]");</code></pre>
<p>
If you use <span class="application">Glib</span>'s support macros, it's easier. Use
<code class="function">C_()</code> instead of <code class="function">_()</code>. For instance:
</p>
<pre class="programlisting"><code class="code">GLib::ustring text(C_("noun", "jumps"));</code></pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="i18n-composition"></a>Composition of strings</h3></div></div></div>
<p>
C programmers use <code class="function">sprintf()</code> to compose and concatenate
strings. C++ favors streams, but unfortunately, this approach makes
translation difficult, because each fragment of text is translated separately,
without allowing the translators to rearrange them according to the grammar of
the language.</p>
<p>For instance, this code would be problematic:</p>
<pre class="programlisting"><code class="code">std::cout << _("Current amount: ") << amount
<< _(" Future: ") << future << std::endl;
label.set_text(_("Really delete ") + filename + _(" now?"));</code></pre>
<p>
So you should either avoid this situation or use
<a class="ulink" href="https://gnome.pages.gitlab.gnome.org/glibmm/classGlib_1_1ustring.html" target="_top"><code class="function">Glib::ustring::compose()</code></a>
which supports syntax such as:
</p>
<pre class="programlisting"><code class="code">std::cout << Glib::ustring::compose(
_("Current amount: %1 Future: %2"), amount, future) << std::endl;
label.set_text(Glib::ustring::compose(_("Really delete %1 now?"), filename));</code></pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="i18n-display-size"></a>Assuming the displayed size of strings</h3></div></div></div>
<p>You never know how much space a string will take on screen when translated. It might very possibly be twice the size of the original English string. Luckily, most <span class="application">gtkmm</span> widgets will expand at runtime to the required size.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="i18n-unusual-words"></a>Unusual words</h3></div></div></div>
<p>You should avoid cryptic abbreviations, slang, or jargon.
They are usually difficult to translate, and are often difficult
for even native speakers to understand. For instance, prefer "application" to "app"</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="i18n-non-ascii-characters"></a>Using non-ASCII characters in strings</h3></div></div></div>
<p>
Currently, <span class="application">gettext</span> does not support non-ASCII
characters (i.e. any characters with a code above 127) in source code. For
instance, you cannot use the copyright sign (©).
</p>
<p>To work around this, you could write a comment in the
source code just before the string, telling the translators to
use the special character if it is available in their languages. For English, you could then make an American English
<code class="filename">en_US.po</code> translation which used that special character.</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-i18n-expecting-utf8.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-internationalization.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-i18n-getting-help-with-translations.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Expecting UTF8 </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Getting help with translations</td>
</tr>
</table>
</div>
</body>
</html>
|