Simplified language list.
This commit is contained in:
parent
339021a11b
commit
17c059b6f7
|
@ -4,32 +4,59 @@
|
|||
|
||||
|
||||
lang translations::current_language = lang::English;
|
||||
|
||||
const languageInfo* translations::get_languages(size_t* languages_number) {
|
||||
if(languages_number) {
|
||||
*languages_number = languages.size();
|
||||
}
|
||||
return languages.data();
|
||||
}
|
||||
const languageInfo translations::Languages[static_cast<int>(lang::Max)] =
|
||||
{
|
||||
{ lang::Arabic, "ar", "Arabic" },
|
||||
{ lang::Czech, "cs", "Czech" },
|
||||
{ lang::Danish, "da", "Danish" },
|
||||
{ lang::German, "de", "German" },
|
||||
{ lang::Greek, "el", "Greek" },
|
||||
{ lang::English, "en", "English" },
|
||||
{ lang::Spanish, "es", "Spanish" },
|
||||
{ lang::Finnish, "fi", "Finnish" },
|
||||
{ lang::French, "fr", "French" },
|
||||
{ lang::Hebrew, "he", "Hebrew" },
|
||||
{ lang::Hungarian, "hu", "Hungarian" },
|
||||
{ lang::Italian, "it", "Italian" },
|
||||
{ lang::Japanese, "ja", "Japanese" },
|
||||
{ lang::Korean, "ko", "Korean" },
|
||||
{ lang::Norwegian, "nb", "Norwegian" },
|
||||
{ lang::Dutch, "nl", "Dutch" },
|
||||
{ lang::Polish, "pl", "Polish" },
|
||||
{ lang::BrazilianPortuguese, "pt_BR", "Brazilian Portuguese" },
|
||||
{ lang::Portuguese, "pt_PT", "Portuguese" },
|
||||
{ lang::Russian, "ru", "Russian" },
|
||||
{ lang::Swedish, "sv", "Swedish" },
|
||||
{ lang::Turkish, "tr", "Turkish" },
|
||||
{ lang::SimplifiedChinese, "zh_CN", "Simplified Chinese" },
|
||||
{ lang::TraditionalChinese, "zh_TW", "Traditional Chinese" },
|
||||
};
|
||||
|
||||
void translations::set_current_language(const char* short_name)
|
||||
{
|
||||
for(int i = 0; i < (int)lang::Max; i++) {
|
||||
if(!strcmp(short_name, languages[(lang)i].short_name)) {
|
||||
current_language = (lang) i;
|
||||
for (const auto& langInfo : Languages)
|
||||
{
|
||||
if (!strcmp(short_name, langInfo.short_name))
|
||||
{
|
||||
current_language = langInfo.Language;
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unknown language \"%s\"\n", short_name);
|
||||
|
||||
assertm(false, "Unknown language");
|
||||
}
|
||||
|
||||
const languageInfo* translations::get_current_language()
|
||||
{
|
||||
if(!TextArray::contains(current_language))
|
||||
for (const auto& langInfo : Languages)
|
||||
{
|
||||
current_language = lang::English;
|
||||
if (langInfo.Language == current_language)
|
||||
{
|
||||
return &langInfo;
|
||||
}
|
||||
return &languages[current_language];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* translations::get_translation(Msg id)
|
||||
|
@ -65,38 +92,6 @@ void translations::get_glyph_range(ImVector<ImWchar>* ranges)
|
|||
builder.BuildRanges(ranges);
|
||||
}
|
||||
|
||||
const InitializedArray<
|
||||
lang,
|
||||
languageInfo,
|
||||
(int)lang::Max
|
||||
> translations::languages =
|
||||
{
|
||||
{ lang::Arabic, {"ar", "Arabic" } },
|
||||
{ lang::Czech, {"cs", "Czech" } },
|
||||
{ lang::Danish, {"da", "Danish" } },
|
||||
{ lang::German, {"de", "German" } },
|
||||
{ lang::Greek, {"el", "Greek" } },
|
||||
{ lang::English, {"en", "English" } },
|
||||
{ lang::Spanish, {"es", "Spanish" } },
|
||||
{ lang::Finnish, {"fi", "Finnish" } },
|
||||
{ lang::French, {"fr", "French" } },
|
||||
{ lang::Hebrew, {"he", "Hebrew" } },
|
||||
{ lang::Hungarian, {"hu", "Hungarian" } },
|
||||
{ lang::Italian, {"it", "Italian" } },
|
||||
{ lang::Japanese, {"ja", "Japanese" } },
|
||||
{ lang::Korean, {"ko", "Korean" } },
|
||||
{ lang::Norwegian, {"nb", "Norwegian" } },
|
||||
{ lang::Dutch, {"nl", "Dutch" } },
|
||||
{ lang::Polish, {"pl", "Polish" } },
|
||||
{ lang::BrazilianPortuguese, {"pt_BR", "Brazilian Portuguese" } },
|
||||
{ lang::Portuguese, {"pt_PT", "Portuguese" } },
|
||||
{ lang::Russian, {"ru", "Russian" } },
|
||||
{ lang::Swedish, {"sv", "Swedish" } },
|
||||
{ lang::Turkish, {"tr", "Turkish" } },
|
||||
{ lang::SimplifiedChinese, {"zh_CN", "Simplified Chinese" } },
|
||||
{ lang::TraditionalChinese, {"zh_TW", "Traditional Chinese" } },
|
||||
};
|
||||
|
||||
const TextArray translations::Translations =
|
||||
{
|
||||
{
|
||||
|
|
|
@ -288,45 +288,6 @@ enum class lang : int
|
|||
Max
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename Value, int N>
|
||||
struct InitializedArray
|
||||
{
|
||||
static_assert(std::is_enum<Key>::value, "Key is not an enum");
|
||||
|
||||
InitializedArray(const std::initializer_list<std::pair<Key, Value>>& iList)
|
||||
{
|
||||
for (const auto& pair : iList)
|
||||
{
|
||||
auto index = static_cast<int>(pair.first);
|
||||
Store[index] = pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
const Value& operator[](Key index) const
|
||||
{
|
||||
return Store[static_cast<int>(index)];
|
||||
}
|
||||
|
||||
const Value* data() const
|
||||
{
|
||||
return Store;
|
||||
}
|
||||
|
||||
static bool contains(Key index)
|
||||
{
|
||||
return N >= 0 && N > static_cast<int>(index);
|
||||
}
|
||||
|
||||
static size_t size()
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
private:
|
||||
Value Store[N]{};
|
||||
};
|
||||
|
||||
struct TextArray
|
||||
{
|
||||
TextArray(const std::initializer_list<std::pair<Msg, std::initializer_list<std::pair<lang, LPCSTR>>>>& iList)
|
||||
|
@ -376,6 +337,7 @@ private:
|
|||
|
||||
struct languageInfo
|
||||
{
|
||||
const lang Language;
|
||||
const char* short_name;
|
||||
const char* display_name;
|
||||
};
|
||||
|
@ -383,7 +345,8 @@ struct languageInfo
|
|||
class translations
|
||||
{
|
||||
public:
|
||||
static const languageInfo* get_languages(size_t* languages_number);
|
||||
static const languageInfo Languages[static_cast<int>(lang::Max)];
|
||||
|
||||
static const char* get_translation(Msg id);
|
||||
static void set_current_language(const char* short_name);
|
||||
static const languageInfo* get_current_language();
|
||||
|
@ -391,10 +354,5 @@ public:
|
|||
|
||||
private:
|
||||
static const TextArray Translations;
|
||||
static const InitializedArray<
|
||||
lang,
|
||||
languageInfo,
|
||||
static_cast<int>(lang::Max)
|
||||
> languages;
|
||||
static lang current_language;
|
||||
};
|
||||
|
|
|
@ -469,16 +469,12 @@ void winmain::RenderUi()
|
|||
}
|
||||
if (ImGui::BeginMenu("Language"))
|
||||
{
|
||||
std::string current_language = translations::get_current_language()->short_name;
|
||||
size_t language_number;
|
||||
const languageInfo* languages = translations::get_languages(&language_number);
|
||||
|
||||
for(size_t i = 0; i < language_number; i++)
|
||||
auto currentLanguage = translations::get_current_language();
|
||||
for (auto &item : translations::Languages)
|
||||
{
|
||||
const languageInfo* item = &languages[i];
|
||||
if (ImGui::MenuItem(item->display_name, nullptr, current_language == item->short_name))
|
||||
if (ImGui::MenuItem(item.display_name, nullptr, currentLanguage->Language == item.Language))
|
||||
{
|
||||
translations::set_current_language(item->short_name);
|
||||
translations::set_current_language(item.short_name);
|
||||
winmain::Restart();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue