HoverRace  2.0
Locale.h
Go to the documentation of this file.
1 
2 // Locale.h
3 //
4 // Copyright (c) 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <locale>
25 
26 #include "OS.h"
27 
28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
29 # ifdef MR_ENGINE
30 # define MR_DllDeclare __declspec( dllexport )
31 # else
32 # define MR_DllDeclare __declspec( dllimport )
33 # endif
34 #else
35 # define MR_DllDeclare
36 #endif
37 
38 namespace HoverRace {
39  namespace Util {
40  namespace yaml {
41  class Emitter;
42  class MapNode;
43  }
44  }
45 }
46 
47 namespace HoverRace {
48 namespace Util {
49 
54 class Locale
55 {
56 public:
57  Locale(const OS::path_t &path, const std::string &domain);
58 
59 public:
60  static std::string NormalizeId(const std::string &s);
61 
62 public:
63  void RequestPreferredLocale();
64 
65  void RequestLocale(const std::string &id);
66 
73  const boost::optional<std::string> &GetSelectedLocaleId() const { return selectedLocaleId; }
74 
75  const std::string &IdToName(const std::string &id) const;
76 
77 private:
78  using locales_t = std::map<std::string, std::string>;
79 
80  void ScanLocales();
81 
82 public:
83  // STL-like iteration.
84  using iterator = locales_t::iterator;
85  using const_iterator = locales_t::const_iterator;
86  using value_type = locales_t::value_type;
87  const_iterator begin() const { return cbegin(); }
88  const_iterator end() const { return cend(); }
89  const_iterator cbegin() const;
90  const_iterator cend() const;
91 
92 private:
94  std::string domain;
95  boost::optional<std::string> selectedLocaleId;
97 };
98 
99 } // namespace Util
100 } // namespace HoverRace
101 
102 #undef MR_DllDeclare
locales_t availableLocales
Cached list of available locales.
Definition: Locale.h:96
boost::filesystem::path path_t
Definition: OS.h:57
locales_t::value_type value_type
Definition: Locale.h:86
const_iterator begin() const
Definition: Locale.h:87
const_iterator end() const
Definition: Locale.h:88
std::map< std::string, std::string > locales_t
Definition: Locale.h:78
locales_t::iterator iterator
Definition: Locale.h:84
OS::path_t path
Definition: Locale.h:93
locales_t::const_iterator const_iterator
Definition: Locale.h:85
Definition: Announcement.h:24
const boost::optional< std::string > & GetSelectedLocaleId() const
Return the ID of the locale that was selected by RequestLocale().
Definition: Locale.h:73
A library of available locales.
Definition: Locale.h:54
std::string domain
Definition: Locale.h:94
boost::optional< std::string > selectedLocaleId
Definition: Locale.h:95