2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
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)
8 #define BOOST_LOCALE_SOURCE
9 #if defined(__FreeBSD__)
12 #include <boost/locale/localization_backend.hpp>
13 #include <boost/locale/gnu_gettext.hpp>
14 #include <boost/locale/info.hpp>
15 #include "all_generator.hpp"
16 #include "posix_backend.hpp"
18 #include "../util/locale_data.hpp"
19 #include "../util/gregorian.hpp"
20 #include <boost/locale/util.hpp>
28 namespace impl_posix
{
30 class posix_localization_backend
: public localization_backend
{
32 posix_localization_backend() :
36 posix_localization_backend(posix_localization_backend
const &other
) :
37 localization_backend(),
39 domains_(other
.domains_
),
40 locale_id_(other
.locale_id_
),
44 virtual posix_localization_backend
*clone() const
46 return new posix_localization_backend(*this);
49 void set_option(std::string
const &name
,std::string
const &value
)
54 else if(name
=="message_path")
55 paths_
.push_back(value
);
56 else if(name
=="message_application")
57 domains_
.push_back(value
);
68 static void free_locale_by_ptr(locale_t
*lc
)
80 real_id_
= locale_id_
;
82 real_id_
= util::get_system_locale();
84 locale_t tmp
= newlocale(LC_ALL_MASK
,real_id_
.c_str(),0);
87 tmp
=newlocale(LC_ALL_MASK
,"C",0);
90 throw std::runtime_error("newlocale failed");
96 tmp_p
= new locale_t();
104 lc_
= boost::shared_ptr
<locale_t
>(tmp_p
,free_locale_by_ptr
);
107 virtual std::locale
install(std::locale
const &base
,
108 locale_category_type category
,
109 character_facet_type type
= nochar_facet
)
115 return create_convert(base
,lc_
,type
);
116 case collation_facet
:
117 return create_collate(base
,lc_
,type
);
118 case formatting_facet
:
119 return create_formatting(base
,lc_
,type
);
121 return create_parsing(base
,lc_
,type
);
123 return create_codecvt(base
,nl_langinfo_l(CODESET
,*lc_
),type
);
126 util::locale_data inf
;
128 return util::install_gregorian_calendar(base
,inf
.country
);
132 gnu_gettext::messages_info minf
;
133 util::locale_data inf
;
135 minf
.language
= inf
.language
;
136 minf
.country
= inf
.country
;
137 minf
.variant
= inf
.variant
;
138 minf
.encoding
= inf
.encoding
;
139 std::copy(domains_
.begin(),domains_
.end(),std::back_inserter
<gnu_gettext::messages_info::domains_type
>(minf
.domains
));
143 return std::locale(base
,gnu_gettext::create_messages_facet
<char>(minf
));
145 return std::locale(base
,gnu_gettext::create_messages_facet
<wchar_t>(minf
));
146 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
148 return std::locale(base
,gnu_gettext::create_messages_facet
<char16_t
>(minf
));
150 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
152 return std::locale(base
,gnu_gettext::create_messages_facet
<char32_t
>(minf
));
158 case information_facet
:
159 return util::create_info(base
,real_id_
);
167 std::vector
<std::string
> paths_
;
168 std::vector
<std::string
> domains_
;
169 std::string locale_id_
;
170 std::string real_id_
;
173 boost::shared_ptr
<locale_t
> lc_
;
176 localization_backend
*create_localization_backend()
178 return new posix_localization_backend();
184 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4