Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Localization.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_LOCALE_H_
34#define DVD_LOCALE_H_
35
37
38namespace Divide {
39
40enum class ErrorCode : I8;
41enum class FileUpdateEvent : U8;
42
43namespace Locale {
44constexpr const char* DEFAULT_LANG = "enGB";
45constexpr const char* const g_languageFileExtension = ".ini";
46
48{
49 string _value;
51};
52
54public:
55 using LangCallback = DELEGATE<void, std::string_view/*new language*/>;
56
57 ErrorCode changeLanguage(std::string_view newLanguage);
58
59 const char* get(U64 key, bool appendSection, const char* defaultValue );
61
62private:
68};
69
71
73ErrorCode Init(const char* newLanguage = DEFAULT_LANG);
75void Clear() noexcept;
77void Idle();
80ErrorCode ChangeLanguage(const char* newLanguage);
82void SetChangeLanguageCallback(const DELEGATE<void, std::string_view /*new language*/>& cbk);
84const Str<64>& CurrentLanguage() noexcept;
88const char* Get(U64 key, bool appendSection = true, const char* defaultValue = nullptr);
89
90#ifndef LOCALE_STR
91#define LOCALE_STR(X) Locale::Get(_ID(X))
92#endif //LOCALE_STR
93
94} // namespace Locale
95} // namespace Divide
96
97#endif //DVD_LOCALE_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
void setChangeLanguageCallback(const DELEGATE< void, std::string_view > &cbk)
LangCallback _languageChangeCallback
Definition: Localization.h:67
ErrorCode changeLanguage(std::string_view newLanguage)
hashMap< U64, LanguageEntry > _languageTable
Definition: Localization.h:66
const char * get(U64 key, bool appendSection, const char *defaultValue)
DELEGATE< void, std::string_view > LangCallback
Definition: Localization.h:55
ErrorCode ChangeLanguage(const char *newLanguage)
const char * Get(U64 key, bool appendSection=true, const char *defaultValue=nullptr)
void SetChangeLanguageCallback(const DELEGATE< void, std::string_view > &cbk)
Set a function to be called on each language change.
constexpr const char *const g_languageFileExtension
Definition: Localization.h:45
const Str< 64 > & CurrentLanguage() noexcept
Query the current language code to detect changes.
ErrorCode Init(const char *newLanguage=DEFAULT_LANG)
Reset everything and load the specified language file.
void Clear() noexcept
clear the language table
constexpr const char * DEFAULT_LANG
Definition: Localization.h:44
void Idle()
perform maintenance tasks
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
uint8_t U8
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
uint64_t U64
Definition: Localization.h:48
string _sectionAndValue
Definition: Localization.h:50
string _value
Definition: Localization.h:49