Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are doing is very similar to Localization (AKA L10N).</p> <p>There are a couple of questions on this: <a href="https://stackoverflow.com/q/185291/14065">Best way to design for localization of strings</a></p> <p>But there are several packages that already deal with this.<br> These are basically designed to take all the strings from your application and package them in a separate resource (the correct resource (depending usually on locale) is selected at runtime). But they usually use the "English" (or should I say original text for non English programers) as the look-up text to find the correct resource string (thus the code is still readable to the developer) and the user gets a language specific string displayed.</p> <p>Of course boost also has one</p> <ul> <li><a href="http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/" rel="nofollow noreferrer">boost::localization</a></li> </ul> <p>But there are others (A quick google finds)</p> <ul> <li>GNU <a href="http://www.gnu.org/software/gettext/" rel="nofollow noreferrer">gettext</a></li> <li>GNU <a href="http://www.gnu.org/software/libiconv/" rel="nofollow noreferrer">libiconv</a></li> </ul> <p>Othere resources:</p> <ul> <li><a href="http://en.wikipedia.org/wiki/GNU_gettext" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/GNU_gettext</a></li> <li><a href="http://site.icu-project.org/" rel="nofollow noreferrer">http://site.icu-project.org/</a></li> </ul> <p>But getting the correct string is only half the battle. Then you need to correctly swap run-time values with place holders in the string. Personally this is where I think <a href="http://www.boost.org/doc/libs/1_49_0/libs/format/" rel="nofollow noreferrer">boost::format</a> really shines.</p> <p>Example:</p> <pre><code>sprintf("The time is %s in %s.", time, country); </code></pre> <p>The trouble is the order of nouns and verbs differ across languages. For example if we translate</p> <blockquote> <p>"The time is 12:00 in Germany."</p> </blockquote> <p>into Azerbaijani</p> <blockquote> <p>"Saat Almaniya saat 12:00 deyil."</p> </blockquote> <p>You will notice that the word for "Germany" (Almaniya) swaps places with the time. Thus the simple task of replacing items in a specific order does not work. What you need are indexed placeholders. (boost::format to the rescue).</p> <pre><code>std::cout &lt;&lt; boost::formt("The time is %1 in %2.") &lt;&lt; time &lt;&lt; country; // Notice the place holders are number '%1' means the first bound argument // But the format string allows you to place them in any order in the string // So your localized resource will look like this: std::cout &lt;&lt; boost::formt("Saat %2 saat %1 deyil.") % time % country; </code></pre> <p>Or more likely:</p> <pre><code>std::cout &lt;&lt; boost::formt(I10N.get("The time is %1 in %2.")) % time % country; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload