1 #ifndef CPP3DS_I18N_HPP
2 #define CPP3DS_I18N_HPP
12 #include <cpp3ds/System/String.hpp>
14 #define _(key, ...) (cpp3ds::I18n::getInstance().translate(key, ##__VA_ARGS__))
19 template<
typename ... Args>
20 cpp3ds::String string_format(
const std::string& format, Args ... args )
22 size_t size = snprintf(
nullptr, 0, format.c_str(), args ... ) + 1;
23 std::unique_ptr<char[]> buf(
new char[ size ] );
24 snprintf( buf.get(), size, format.c_str(), args ... );
25 std::string stringUtf8( buf.get(), buf.get() + size - 1 );
26 std::wstring stringUtf32;
53 static I18n& getInstance();
55 static void loadLanguage(Language language);
57 static inline void loadLanguageFile(
const std::string& filename);
59 static Language getLanguage();
61 template<
typename ... Args>
62 const String translate(
const char* key, Args ... args)
const {
64 TranslationMap::const_iterator it = m_content.find(key);
65 if (it == m_content.end())
66 trans = std::string(key);
69 return string_format(trans, args ...);
72 template<
typename ... Args>
73 const String translate(
const std::string& key, Args ... args)
const {
74 return translate(key.c_str(), args ...);
77 const std::string getLangString(
const Language language)
const;
84 bool loadFromFile(
const std::string filename);
86 bool loadFromLanguage(
const Language language);
88 typedef std::map <std::string, std::string> TranslationMap;
89 TranslationMap m_content;
95 #endif // CPP3DS_I18N_HPP
Utility string class that automatically handles conversions between types and encodings.
static Out toUtf32(In begin, In end, Out output)
Convert a UTF-8 characters range to UTF-32.