UNPKG

boost-react-native-bundle

Version:

Boost library as in https://sourceforge.net/projects/boost/files/boost/1.57.0/

147 lines (128 loc) 9.01 kB
<!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>Boost.Locale: Locale Generation</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td> <td style="padding-left: 0.5em;"> <div id="projectname">Boost.Locale </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.6.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main&#160;Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('locale_gen.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <div class="title">Locale Generation </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><p>Each locale is defined by a specific locale identifier, which contains a mandatory part (Language) and several optional parts (Country, Variant, keywords and character encoding of <code>std::string</code>). Boost.Locale uses the POSIX naming convention for locales, i.e. a locale is defined as <code>language[_COUNTRY][.encoding][@variant]</code>, where lang is ISO-639 language name like "en" or "ru", COUNTRY is the ISO-3166 country identifier like "US" or "DE", encoding is the eight-bit character encoding like <code>UTF-8</code> or <code>ISO-8859-1</code>, and variant is additional options for specializing the locale, like <code>euro</code> or <code>calendar=hebrew</code>, see <a class="el" href="locale_gen.html#locale_gen_variant">Variant</a>.</p> <p>Note that each locale should include the encoding in order to handle <code>char</code> based strings correctly.</p> <h2><a class="anchor" id="locale_gen_basics"></a> Basics</h2> <p>The class <a class="el" href="classboost_1_1locale_1_1generator.html">generator</a> provides tools to generate the locales we need. The simplest way to use <code>generator</code> is to create a locale and set it as the global one:</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;boost/locale.hpp&gt;</span> <span class="keyword">using namespace </span>boost::locale; <span class="keywordtype">int</span> main() { <a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">generator</a> gen; <span class="comment">// Create locale generator </span> std::locale::global(gen(<span class="stringliteral">&quot;&quot;</span>)); <span class="comment">// &quot;&quot; - the system default locale, set</span> <span class="comment">// it globally</span> } </pre></div><p>Of course we can also specify the locale manually</p> <div class="fragment"><pre class="fragment"> std::locale loc = gen(<span class="stringliteral">&quot;en_US.UTF-8&quot;</span>); <span class="comment">// Use English, United States locale</span> </pre></div><dl class="note"><dt><b>Note:</b></dt><dd></dd></dl> <ul> <li>Even if your application uses wide strings everywhere, you should specify the 8-bit encoding to use for 8-bit stream IO operations like <code>cout</code> or <code>fstream</code>. <br/> </li> <li>The default locale is defined by the environment variables <code>LC_CTYPE</code> , <code>LC_ALL</code> , and <code>LANG</code> in that order (i.e. <code>LC_CTYPE</code> first and <code>LANG</code> last). On Windows, the library also queries the <code>LOCALE_USER_DEFAULT</code> option in the Win32 API when these variables are not set.</li> </ul> <p><b>Tip:</b> Prefer using UTF-8 Unicode encoding over 8-bit encodings like the ISO-8859-X ones.</p> <p>By default the generated locales include all supported categories and character types. However, if your application uses only 8-bit encodings, only wide-character encodings, or only specific facets, you can limit the facet generation to specific categories and character types by calling the <a class="el" href="classboost_1_1locale_1_1generator.html#ae3c095f074329954eb90bb80488c7f76">categories</a> and <a class="el" href="classboost_1_1locale_1_1generator.html#ad5e01c555aa43b438f688dbc29725ab8">characters</a> member functions of the <a class="el" href="classboost_1_1locale_1_1generator.html">generator</a> class.</p> <p>For example:</p> <div class="fragment"><pre class="fragment"> generator gen; gen.<a class="code" href="classboost_1_1locale_1_1generator.html#ad5e01c555aa43b438f688dbc29725ab8">characters</a>(wchar_t_facet); gen.categories(collation_facet | formatting_facet); std::locale::global(gen(<span class="stringliteral">&quot;de_DE.UTF-8&quot;</span>)); </pre></div><h2><a class="anchor" id="locale_gen_variant"></a> Variant</h2> <p>The variant part of the locale (the part that comes after @ symbol) is localization <a class="el" href="using_localization_backends.html">back-end</a> dependent.</p> <h3><a class="anchor" id="locale_gen_variant_non_icu"></a> Non ICU Backends</h3> <p><a class="el" href="using_localization_backends.html#posix_backend">POSIX</a> and <a class="el" href="using_localization_backends.html#std_backend">std</a> back-ends use their own OS specific naming conventions and depend on the current OS configuration. For example typical Linux distribution provides <code>euro</code> for currency selection, <code>cyrillic</code> and <code>latin</code> for specification of language script.</p> <p><a class="el" href="using_localization_backends.html#winapi_backend">winapi</a> back-end does not support any variants.</p> <h3><a class="anchor" id="locale_gen_variant_icu"></a> ICU Backend</h3> <p>ICU provides wide range of locale variant options. For detailed instructions read <a href="http://userguide.icu-project.org/locale">this</a> ICU manual pages.</p> <p>However in general it is represented as set of key=value pairs separated with a semicolon ";" For example: "@collation=phonebook;calendar=islamic-civil".</p> <p>Currently ICU supports following keys:</p> <ul> <li><code>calendar</code> - the calendar used for the current locale. For example: <code>gregorian</code>, <code>japanese</code>, <code>buddhist</code>, <code>islamic</code>, <code>hebrew</code>, <code>chinese</code>, <code>islamic-civil</code>.</li> <li><code>collation</code> - the collation order used for this locales, for example <code>phonebook</code>, <code>pinyin</code>, <code>traditional</code>, <code>stroke</code>, <code>direct</code>, <code>posix</code>.</li> <li><code>currency</code> - the currency used in this locale, the standard 3 letter code like USD or JPY.</li> <li><code>numbers</code> - the numbering system used, for example: <code>latn</code>, <code>arab</code>, <code>thai</code>.</li> </ul> <p>Please refer to CLDR and ICU documentation for exact list of keys and values:</p> <ul> <li><a href="http://userguide.icu-project.org/locale#TOC-Keywords">ICU User Guide/Locale/Keywords</a></li> <li><a href="http://www.unicode.org/reports/tr35/">Unicode Locale Data Markup Language</a> </li> </ul> </div></div><!-- contents --> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="index.html">Boost.Locale</a> </li> <li class="navelem"><a class="el" href="using_boost_locale.html">Using Boost.Locale</a> </li> <li class="footer"> &copy; Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0. </li> </ul> </div> </body> </html>