// french.cpp ----------------------------------------------------------// // Copyright 2010 Howard Hinnant // Copyright 2011 Vicente J. Botet Escriba // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt // Adapted to Boost from the original Hawards's code #include #include #include #include #include #include #if BOOST_CHRONO_VERSION==2 #include using namespace boost; using namespace boost::chrono; template class duration_units_fr: public duration_units_default { public: typedef CharT char_type; explicit duration_units_fr(size_t refs = 0) : duration_units_default(refs) { } protected: using duration_units_default::do_get_unit; std::size_t do_get_plural_form(boost::int_least64_t value) const { return (value == -1 || value == 0 || value == 1) ? 0 : 1; } std::basic_string do_get_unit(duration_style style, ratio<1> , std::size_t pf) const { static const CharT t[] = { 's' }; static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); static const CharT u[] = { 's', 'e', 'c', 'o', 'n', 'd', 'e' }; static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); static const CharT v[] = { 's', 'e', 'c', 'o', 'n', 'd', 'e', 's' }; static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); if (style == duration_style::symbol) return symbol; if (pf == 0) return singular; if (pf == 1) return plural; // assert //throw "exception"; return ""; } std::basic_string do_get_unit(duration_style style, ratio<60> , std::size_t pf) const { static const CharT t[] = { 'm', 'i', 'n' }; static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); static const CharT u[] = { 'm', 'i', 'n', 'u', 't', 'e' }; static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); static const CharT v[] = { 'm', 'i', 'n', 'u', 't', 'e', 's' }; static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); if (style == duration_style::symbol) return symbol; if (pf == 0) return singular; if (pf == 1) return plural; // assert //throw "exception"; return ""; } std::basic_string do_get_unit(duration_style style, ratio<3600> , std::size_t pf) const { static const CharT t[] = { 'h' }; static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); static const CharT u[] = { 'h', 'e', 'u', 'r', 'e' }; static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); static const CharT v[] = { 'h', 'e', 'u', 'r', 'e', 's' }; static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); if (style == duration_style::symbol) return symbol; if (pf == 0) return singular; if (pf == 1) return plural; // assert //throw "exception"; return ""; } }; #endif int main() { using std::cout; using std::locale; using namespace boost; using namespace boost::chrono; #if BOOST_CHRONO_VERSION==2 cout.imbue(locale(locale(), new duration_units_fr<>())); #else cout.imbue(locale(locale(), new duration_punct ( duration_punct::use_long, "secondes", "minutes", "heures", "s", "m", "h" ))); #endif hours h(5); minutes m(45); seconds s(15); milliseconds ms(763); cout << h << ", " << m << ", " << s << " et " << ms << '\n'; cout << hours(0) << ", " << minutes(0) << ", " << s << " et " << ms << '\n'; return 0; }