Ticket #7266: formats.patch
File formats.patch, 6.7 KB (added by , 10 years ago) |
---|
-
boost/locale/gnu_gettext.hpp
diff --git a/boost/locale/gnu_gettext.hpp b/boost/locale/gnu_gettext.hpp index cc8844f..d0c6b33 100644
a b namespace gnu_gettext { 126 126 127 127 }; 128 128 129 /// 130 /// Create a message_format facet using GNU Gettext catalogs. It uses \a info structure to get 131 /// information about where to read them from and uses it for character set conversion (if needed) 132 /// 129 /// \cond INTERNAL 133 130 131 struct facetData 132 { 133 facetData(messages_info const& newInfo, std::vector<std::string> const& newFormats) 134 : info(newInfo), formats(newFormats) 135 { 136 } 137 138 messages_info const& info; 139 std::vector<std::string> const& formats; 140 }; 141 134 142 template<typename CharType> 135 message_format<CharType> *create_messages_facet(messages_info const &info); 136 137 /// \cond INTERNAL 143 message_format<CharType> *create_messages_facet(facetData const& data); 138 144 139 145 template<> 140 BOOST_LOCALE_DECL message_format<char> *create_messages_facet( messages_info const &info);146 BOOST_LOCALE_DECL message_format<char> *create_messages_facet(facetData const& data); 141 147 142 148 template<> 143 BOOST_LOCALE_DECL message_format<wchar_t> *create_messages_facet( messages_info const &info);144 149 BOOST_LOCALE_DECL message_format<wchar_t> *create_messages_facet(facetData const& data); 150 145 151 #ifdef BOOST_HAS_CHAR16_T 146 152 template<> 147 BOOST_LOCALE_DECL message_format<char16_t> *create_messages_facet( messages_info const &info);153 BOOST_LOCALE_DECL message_format<char16_t> *create_messages_facet(facetData const& data); 148 154 #endif 149 155 150 156 #ifdef BOOST_HAS_CHAR32_T 151 157 template<> 152 BOOST_LOCALE_DECL message_format<char32_t> *create_messages_facet( messages_info const &info);158 BOOST_LOCALE_DECL message_format<char32_t> *create_messages_facet(facetData const& data); 153 159 #endif 154 160 155 161 /// \endcond 156 162 163 /// 164 /// Create a message_format facet using GNU Gettext catalogs. It uses \a info structure to get 165 /// information about where to read them from and uses it for character set conversion (if needed) 166 /// 167 168 template<typename CharType> 169 message_format<CharType> *create_messages_facet(messages_info const &info) 170 { 171 // Default argument for formats is to use the Gettext hierarchy. 172 std::vector<std::string> formats; 173 formats.push_back("{1}/{2}/{3}/{4}.mo"); 174 175 return create_messages_facet<CharType>(facetData(info, formats)); 176 } 177 178 /// 179 /// Creates a messages facet with special path formats 180 /// 181 /// Formats are the same syntax as the Boost format functions, but 182 /// use the following variables: 183 /// 184 /// \li {1} A path to search for catalogs in. 185 /// \li {2} The locale's name. 186 /// \li {3} The locale's category. 187 /// \li {4} The Gettext domain. 188 /// 189 /// For example, \c {1}/{2}/{3}/{4}.mo is the standard Gettext layout. 190 /// Using something like \c {1}/{2}.mo would compact the folder hierarchy. 191 /// 192 193 template<typename CharType> 194 message_format<CharType> *create_messages_facet(messages_info const &info, 195 std::vector<std::string> const &path_formats) 196 { 197 return create_messages_facet<CharType>(facetData(info, path_formats)); 198 } 199 157 200 } // gnu_gettext 158 201 159 202 /// @} -
libs/locale/src/shared/message.cpp
diff --git a/libs/locale/src/shared/message.cpp b/libs/locale/src/shared/message.cpp index 56a4fdc..ce4b97c 100644
a b 9 9 #include <boost/config.hpp> 10 10 #include <boost/locale/message.hpp> 11 11 #include <boost/locale/gnu_gettext.hpp> 12 #include <boost/locale/format.hpp> 12 13 #include <boost/shared_ptr.hpp> 13 14 #include <boost/locale/encoding.hpp> 14 15 #ifdef BOOST_MSVC … … namespace boost { 533 534 return p->second; 534 535 } 535 536 536 mo_message( messages_info const &inf)537 mo_message(facetData const& data) 537 538 { 539 messages_info inf = data.info; 540 std::vector<std::string> const& formats = data.formats; 541 538 542 std::string language = inf.language; 539 543 std::string variant = inf.variant; 540 544 std::string country = inf.country; … … namespace boost { 574 578 bool found=false; 575 579 for(unsigned j=0;!found && j<paths.size();j++) { 576 580 for(unsigned i=0;!found && i<search_paths.size();i++) { 577 std::string full_path = search_paths[i]+"/"+paths[j]+"/" + lc_cat + "/"+domain+".mo"; 578 found = load_file(full_path,encoding,key_encoding,id,inf.callback); 581 for(unsigned k=0;!found && k<formats.size();k++) { 582 std::string full_path = (format(formats[k]) % search_paths[i] % paths[j] % lc_cat % domain).str(std::locale::classic()); 583 found = load_file(full_path,encoding,key_encoding,id,inf.callback); 584 } 579 585 } 580 586 } 581 587 } … … namespace boost { 744 750 }; 745 751 746 752 template<> 747 message_format<char> *create_messages_facet( messages_info const &info)753 message_format<char> *create_messages_facet(facetData const& data) 748 754 { 749 return new mo_message<char>( info);755 return new mo_message<char>(data); 750 756 } 751 757 752 758 template<> 753 message_format<wchar_t> *create_messages_facet( messages_info const &info)759 message_format<wchar_t> *create_messages_facet(facetData const& data) 754 760 { 755 return new mo_message<wchar_t>( info);761 return new mo_message<wchar_t>(data); 756 762 } 757 763 758 764 #ifdef BOOST_HAS_CHAR16_T 759 765 760 766 template<> 761 message_format<char16_t> *create_messages_facet( messages_info const &info)767 message_format<char16_t> *create_messages_facet(facetData const& data) 762 768 { 763 return new mo_message<char16_t>( info);769 return new mo_message<char16_t>(data); 764 770 } 765 771 #endif 766 772 767 773 #ifdef BOOST_HAS_CHAR32_T 768 774 769 775 template<> 770 message_format<char32_t> *create_messages_facet( messages_info const &info)776 message_format<char32_t> *create_messages_facet(facetData const& data) 771 777 { 772 return new mo_message<char32_t>( info);778 return new mo_message<char32_t>(data); 773 779 } 774 780 #endif 775 776 777 781 } /// gnu_gettext 778 782 779 783 } // locale