whello.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <boost/locale.hpp>
  9. #include <iostream>
  10. #include <ctime>
  11. int main()
  12. {
  13. using namespace boost::locale;
  14. using namespace std;
  15. // Create system default locale
  16. generator gen;
  17. locale loc=gen("");
  18. locale::global(loc);
  19. wcout.imbue(loc);
  20. // This is needed to prevent C library to
  21. // convert strings to narrow
  22. // instead of C++ on some platforms
  23. std::ios_base::sync_with_stdio(false);
  24. wcout <<wformat(L"Today {1,date} at {1,time} we had run our first localization example") % time(0)
  25. <<endl;
  26. wcout<<L"This is how we show numbers in this locale "<<as::number << 103.34 <<endl;
  27. wcout<<L"This is how we show currency in this locale "<<as::currency << 103.34 <<endl;
  28. wcout<<L"This is typical date in the locale "<<as::date << std::time(0) <<endl;
  29. wcout<<L"This is typical time in the locale "<<as::time << std::time(0) <<endl;
  30. wcout<<L"This is upper case "<<to_upper(L"Hello World!")<<endl;
  31. wcout<<L"This is lower case "<<to_lower(L"Hello World!")<<endl;
  32. wcout<<L"This is title case "<<to_title(L"Hello World!")<<endl;
  33. wcout<<L"This is fold case "<<fold_case(L"Hello World!")<<endl;
  34. }
  35. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4