Get rid of namespace, use header instead.
This commit is contained in:
parent
a489c7d897
commit
dae4b1bf20
|
@ -2,97 +2,8 @@
|
|||
#include "translations.h"
|
||||
#include "options.h"
|
||||
|
||||
template <typename Key, typename Value, int N>
|
||||
struct InitializedArray
|
||||
{
|
||||
|
||||
InitializedArray() : Store{}
|
||||
{
|
||||
}
|
||||
|
||||
InitializedArray(const std::initializer_list<std::pair<Key, Value>>& iList)
|
||||
{
|
||||
Store.reserve(iList.size());
|
||||
for (const auto& pair : iList)
|
||||
{
|
||||
size_t index = static_cast<int>(pair.first);
|
||||
if(Store.size() <= index)
|
||||
Store.resize(index + 1);
|
||||
Store[index] = pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
bool contains(Key index) const
|
||||
{
|
||||
return Store.size() > static_cast<int>(index);
|
||||
}
|
||||
|
||||
const Value& operator[](Key index) const
|
||||
{
|
||||
return Store[static_cast<int>(index)];
|
||||
}
|
||||
|
||||
const Value* data() const
|
||||
{
|
||||
return Store.data();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return Store.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Value> Store;
|
||||
};
|
||||
|
||||
enum class lang {
|
||||
Arabic,
|
||||
Czech,
|
||||
Danish,
|
||||
German,
|
||||
Greek,
|
||||
English,
|
||||
Spanish,
|
||||
Finnish,
|
||||
French,
|
||||
Hebrew,
|
||||
Hungarian,
|
||||
Italian,
|
||||
Japanese,
|
||||
Korean,
|
||||
Norwegian,
|
||||
Dutch,
|
||||
Polish,
|
||||
BrazilianPortuguese,
|
||||
Portuguese,
|
||||
Russian,
|
||||
Swedish,
|
||||
Turkish,
|
||||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
NUMBER
|
||||
};
|
||||
|
||||
namespace {
|
||||
// Use anonymous namespace instead of static to be able to forward declare translated_strings
|
||||
extern const InitializedArray<
|
||||
lang,
|
||||
languageInfo,
|
||||
(int)lang::NUMBER
|
||||
> languages;
|
||||
|
||||
extern const InitializedArray<
|
||||
Msg,
|
||||
InitializedArray<
|
||||
lang,
|
||||
const char*,
|
||||
(int)lang::NUMBER
|
||||
>,
|
||||
(int)Msg::NUMBER
|
||||
> translated_strings;
|
||||
|
||||
lang current_language = lang::English;
|
||||
}
|
||||
lang translations::current_language = lang::English;
|
||||
|
||||
const languageInfo* translations::get_languages(size_t* languages_number) {
|
||||
if(languages_number) {
|
||||
|
@ -164,12 +75,11 @@ void translations::get_glyph_range(ImVector<ImWchar>* ranges)
|
|||
builder.BuildRanges(ranges);
|
||||
}
|
||||
|
||||
namespace {
|
||||
const InitializedArray<
|
||||
lang,
|
||||
languageInfo,
|
||||
(int)lang::NUMBER
|
||||
> languages =
|
||||
> translations::languages =
|
||||
{
|
||||
{ lang::Arabic, {"ar", "Arabic" } },
|
||||
{ lang::Czech, {"cs", "Czech" } },
|
||||
|
@ -205,7 +115,7 @@ const InitializedArray<
|
|||
(int)lang::NUMBER
|
||||
>,
|
||||
(int)Msg::NUMBER
|
||||
> translated_strings =
|
||||
> translations::translated_strings =
|
||||
{
|
||||
{
|
||||
Msg::STRING101,
|
||||
|
@ -7371,5 +7281,3 @@ const InitializedArray<
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
} /* namespace */
|
||||
|
|
|
@ -257,17 +257,109 @@ enum class Msg
|
|||
NUMBER,
|
||||
};
|
||||
|
||||
enum class lang
|
||||
{
|
||||
Arabic,
|
||||
Czech,
|
||||
Danish,
|
||||
German,
|
||||
Greek,
|
||||
English,
|
||||
Spanish,
|
||||
Finnish,
|
||||
French,
|
||||
Hebrew,
|
||||
Hungarian,
|
||||
Italian,
|
||||
Japanese,
|
||||
Korean,
|
||||
Norwegian,
|
||||
Dutch,
|
||||
Polish,
|
||||
BrazilianPortuguese,
|
||||
Portuguese,
|
||||
Russian,
|
||||
Swedish,
|
||||
Turkish,
|
||||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
NUMBER
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename Value, int N>
|
||||
struct InitializedArray
|
||||
{
|
||||
static_assert(std::is_enum<Key>::value, "Key is not an enum");
|
||||
InitializedArray() : Store{}
|
||||
{
|
||||
}
|
||||
|
||||
InitializedArray(const std::initializer_list<std::pair<Key, Value>>& iList)
|
||||
{
|
||||
Store.reserve(iList.size());
|
||||
for (const auto& pair : iList)
|
||||
{
|
||||
size_t index = static_cast<int>(pair.first);
|
||||
if (Store.size() <= index)
|
||||
Store.resize(index + 1);
|
||||
Store[index] = pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
bool contains(Key index) const
|
||||
{
|
||||
return Store.size() > static_cast<int>(index);
|
||||
}
|
||||
|
||||
const Value& operator[](Key index) const
|
||||
{
|
||||
return Store[static_cast<int>(index)];
|
||||
}
|
||||
|
||||
const Value* data() const
|
||||
{
|
||||
return Store.data();
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return Store.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Value> Store;
|
||||
};
|
||||
|
||||
struct languageInfo
|
||||
{
|
||||
const char* short_name;
|
||||
const char* display_name;
|
||||
};
|
||||
|
||||
class translations {
|
||||
class translations
|
||||
{
|
||||
public:
|
||||
static const languageInfo* get_languages(size_t* languages_number);
|
||||
static const char* get_translation(Msg id);
|
||||
static void set_current_language(const char* short_name);
|
||||
static const languageInfo* get_current_language();
|
||||
static void get_glyph_range(ImVector<ImWchar>* ranges);
|
||||
|
||||
private:
|
||||
static const InitializedArray<
|
||||
Msg,
|
||||
InitializedArray<
|
||||
lang,
|
||||
const char*,
|
||||
static_cast<int>(lang::NUMBER)
|
||||
>,
|
||||
static_cast<int>(Msg::NUMBER)
|
||||
> translated_strings;
|
||||
static const InitializedArray<
|
||||
lang,
|
||||
languageInfo,
|
||||
(int)lang::NUMBER
|
||||
> languages;
|
||||
static lang current_language;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue