| <!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: Working with multiple locales</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 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('working_with_multiple_locales.html',''); |
| </script> |
| <div id="doc-content"> |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">Working with multiple locales </div> </div> |
| </div><!--header--> |
| <div class="contents"> |
| <div class="textblock"><p>Boost.Locale allows you to work safely with multiple locales in the same process. As we mentioned before, the locale generation process is not a cheap one. Thus, when we work with multiple locales and need to switch between them, we recommend that you create all the locales you need when the program starts.</p> |
| <p>To simplify this process, the <a class="el" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">boost::locale::generator</a> class has an option to cache all generated locales. With this option, when you create a locale that was previously generated, it would be fetched from the existing locale set instead. This operation is thread safe.</p> |
| <p>This option must be explicitly enabled by calling the <a class="el" href="classboost_1_1locale_1_1generator.html#ac2d152e2803cd96f4acc646943f2df51">locale_cache_enabled</a> member function of <a class="el" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">boost::locale::generator</a> with <code>true</code> as the parameter.</p> |
| <p>For example:</p> |
| <div class="fragment"><pre class="fragment"> generator gen; |
| gen.<a class="code" href="classboost_1_1locale_1_1generator.html#ac2d152e2803cd96f4acc646943f2df51">locale_cache_enabled</a>(<span class="keyword">true</span>); |
| gen(<span class="stringliteral">"en_US.UTF-8"</span>); |
| gen(<span class="stringliteral">"de_DE.UTF-8"</span>); |
| gen(<span class="stringliteral">"ja_JP.UTF-8"</span>); |
| <span class="comment">// Create all locales</span> |
| |
| std::locale en=gen(<span class="stringliteral">"en_US.UTF-8"</span>); |
| <span class="comment">// Fetch an existing locale from the cache</span> |
| std::locale ar=gen(<span class="stringliteral">"ar_EG.UTF-8"</span>); |
| <span class="comment">// Because ar_EG not in the cache, a new locale is generated (and cached)</span> |
| </pre></div><p>Then these locales can be imbued to <code>iostreams</code> or used directly as parameters to various functions. </p> |
| </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"> |
| © 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> |