using_localization_backends.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 filetype=cpp.doxygen
  9. /*!
  10. \page using_localization_backends Using Localization Backends
  11. By default, Boost.Locale uses ICU for all localization and text manipulation tasks.
  12. This is the most powerful library available, but sometimes we don't need
  13. the full power of this library or we want to reduce dependencies from third-party
  14. libraries, and ICU is by no means a small library.
  15. Boost.Locale provides an option to use non-ICU based localization
  16. backends. Although usually less powerful, these often provide all you need:
  17. message formatting, currency, date, time, number formatting, basic collation and
  18. case manipulation. They are implemented using the standard OS API or a C or C++ library.
  19. \section when_to_use_non_icu_backends When to use non-ICU backends
  20. There are situations when using non-ICU based localization is appropriate:
  21. - Embedded systems, where the ICU library is very hefty.
  22. - Applications where only basic features like message, date, and time formatting and
  23. basic collation are required, and using a third-party library like ICU would be too
  24. complicated.
  25. - Performance. ICU is a very powerful library, but it is generally slower than the standard
  26. library. Sometimes it's better to use a simpler but faster localization backend.
  27. \section non_icu_backends Non-ICU Backends
  28. All of the alternate backends have these limitations:
  29. - Only the Gregorian calendar is supported and it is based
  30. on capabilites of mktime functionality (including dates range)
  31. - No boundary analysis.
  32. - Case handling is very simple and based on single codepoint conversions,
  33. though they still handle UTF-8 better than the standard library.
  34. - Time zone specification is very limited: either local time or a time zone
  35. in the format "GMT+HH:MM".
  36. - No percent formatting, no spellout or ordinal number formatting.
  37. - Collation, with exception of the \c winapi backend, is limited to a single level,
  38. similar to what is done by \c strcoll.
  39. \subsection std_backend std - The standard C++ library backend
  40. This localization backend is based on the standard C++ library.
  41. It is supported on all platforms, but is only actually useful on platforms where
  42. the standard library supports locales besides "C" and "POSIX": on Linux with GCC
  43. or Intel compilers, and under the MSVC compiler.
  44. It works around some common standard library bugs like invalid UTF-8 generation for numeric
  45. formatting, and it gives otherwise-absent POSIX locales names and UTF-8 support under MSVC.
  46. It is very useful when the compiler and the library actually give fine localization
  47. support, like GCC under Linux or MSVC under Windows.
  48. \subsection posix_backend posix - POSIX 2008 C library
  49. This backend is based on the latest POSIX 2008 standards, and uses POSIX api functions like
  50. \c newlocale, \c freelocale, \c strftime_l etc. It is available on the Linux and Mac OS X
  51. platforms.
  52. It gives you simple and ready-made localization support, most notably under Mac OS X where
  53. GCC's \c libstdc++ does not support locales.
  54. \note The POSIX backend only supports UTF-8, single-byte, and double-byte encodings.
  55. \subsection winapi_backend winapi - Win32 API.
  56. The Win32API-based localization backend provides decent UTF-8/UTF-16 locale support.
  57. It is based on Windows API functions like \c GetLocaleInfoW, \c LCMapStringW, \c GetDateFormatW etc and
  58. provides good localization support even on the MinGW and Cygwin platforms, which normally have
  59. problems with this.
  60. \note
  61. - If you using GCC compiler under Windows you need GCC-4.x series to use it, GCC-3.4 is not supported
  62. - Only UTF-8 as narrow locale encoding and UTF-16 as wide encoding are supported.
  63. \section supported_features_by_backends Supported Features
  64. <table border="1" sellpadding="5" sellspacing="3">
  65. <tr>
  66. <th>Backend</th>
  67. <th>icu</th><th>posix</th><th>winapi</th><th>std</th>
  68. </tr>
  69. <tr>
  70. <th>Message Formatting</th>
  71. <td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td>
  72. </tr>
  73. <tr>
  74. <th>Non UTF-8 encodings</th>
  75. <td>Yes</td><td>Yes</td><td>No</td><td>Yes</td>
  76. </tr>
  77. <tr>
  78. <th>Date/Time Formatting/Parsing</th>
  79. <td>Yes</td><td>Formatting Only</td><td>Formatting Only</td><td>Formatting Only</td>
  80. </tr>
  81. <tr>
  82. <th>Monetary Formatting/Parsing</th>
  83. <td>Yes</td><td>Formatting Only</td><td>Formatting Only</td><td>Yes</td>
  84. </tr>
  85. <tr>
  86. <th>Number Formatting/Parsing</th>
  87. <td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td>
  88. </tr>
  89. <tr>
  90. <th>Numbers as Percent, Spelled Out</th>
  91. <td>Yes</td><td>No</td><td>No</td><td>No</td>
  92. </tr>
  93. <tr>
  94. <th>Case Manipulation</th>
  95. <td>Yes</td><td>Basic</td><td>Basic</td><td>Basic</td>
  96. </tr>
  97. <tr>
  98. <th>Collation</th>
  99. <td>Full</td><td>Linux - 1 level<br>Mac OS X - broken</td><td>3 levels</td><td>1 level</td>
  100. </tr>
  101. <tr>
  102. <th>Calendar</th>
  103. <td>Yes</td><td>Gregorian Only</td><td>Gregorian Only</td><td>Gregorian Only</td>
  104. </tr>
  105. <tr>
  106. <th>Boundary Analysis</th>
  107. <td>Yes</td><td>No</td><td>No</td><td>No</td>
  108. </tr>
  109. <tr>
  110. <th>Unicode Normalization</th>
  111. <td>Yes</td><td>No</td><td>Vista and above</td><td>No</td>
  112. </tr>
  113. <tr>
  114. <th>C++0x characters</th>
  115. <td>Yes</td><td>No</td><td>No</td><td>Yes</td>
  116. </tr>
  117. <tr>
  118. <th>OS Support</th>
  119. <td>Any</td><td>Linux, Mac OS X</td><td>Windows, Cygwin</td><td>Any</td>
  120. </tr>
  121. <tr>
  122. <th>Useful on</th>
  123. <td>Any Platform</td><td>Linux and Mac OS X</td><td>Windows/MinGW/Cygwin</td><td>Linux with GCC or Intel<br>Windows with MSVC</td>
  124. </tr>
  125. </table>
  126. \section using_localization_backends Using Localization Backends
  127. Accessing a localization backend is done via the boost::locale::localization_backend_manager class.
  128. You can create your own boost::locale::localization_backend_manager by starting with a global backend
  129. via the boost::locale::localization_backend_manager::global static member function and modifying it.
  130. For example:
  131. \code
  132. localization_backend_manager my = localization_backend_manager::global();
  133. // Get global backend
  134. my.select("std");
  135. // select std backend as default
  136. generator gen(my);
  137. // create a generator that uses this backend.
  138. localization_backend_manager::global(my);
  139. // set this backend globally
  140. generator gen2();
  141. // now this one would use the new global backend.
  142. \endcode
  143. You can also create a mixture of several backends, using
  144. for example \c icu for one kind of operation and \c std
  145. for all others:
  146. \code
  147. localization_backend_manager my = localization_backend_manager::global();
  148. // Get global backend
  149. my.select("std");
  150. // select std backend as default for all categories
  151. my.select("icu",boundary_facet);
  152. // select icu backend for boundary analysis (since it is not supported by \c std)
  153. \endcode
  154. */