2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* Languages.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Languages
|
|
|
|
{
|
|
|
|
|
2023-11-10 16:10:01 +02:00
|
|
|
enum class EPluralForms
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
VI_1, // Single plural form, (Vietnamese)
|
|
|
|
EN_2, // Two forms, singular used for one only (English)
|
|
|
|
FR_2, // Two forms, singular used for zero and one (French)
|
|
|
|
UK_3, // Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4] (Ukrainian)
|
|
|
|
CZ_3, // Three forms, special cases for 1 and 2, 3, 4 (Czech)
|
|
|
|
PL_3, // Three forms, special case for one and some numbers ending in 2, 3, or 4 (Polish)
|
|
|
|
};
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
enum class ELanguages
|
|
|
|
{
|
|
|
|
CZECH,
|
|
|
|
CHINESE,
|
|
|
|
ENGLISH,
|
|
|
|
FINNISH,
|
|
|
|
FRENCH,
|
|
|
|
GERMAN,
|
|
|
|
HUNGARIAN,
|
|
|
|
ITALIAN,
|
|
|
|
KOREAN,
|
|
|
|
POLISH,
|
|
|
|
PORTUGUESE,
|
|
|
|
RUSSIAN,
|
|
|
|
SPANISH,
|
|
|
|
SWEDISH,
|
|
|
|
TURKISH,
|
|
|
|
UKRAINIAN,
|
|
|
|
VIETNAMESE,
|
|
|
|
|
|
|
|
COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Options
|
|
|
|
{
|
|
|
|
/// string identifier (ascii, lower-case), e.g. "english"
|
|
|
|
std::string identifier;
|
|
|
|
|
|
|
|
/// human-readable name of language in English
|
|
|
|
std::string nameEnglish;
|
|
|
|
|
|
|
|
/// human-readable name of language in its own language
|
|
|
|
std::string nameNative;
|
|
|
|
|
|
|
|
/// encoding that is used by H3 for this language
|
|
|
|
std::string encoding;
|
|
|
|
|
|
|
|
/// primary IETF language tag
|
|
|
|
std::string tagIETF;
|
|
|
|
|
2024-05-30 20:02:50 +02:00
|
|
|
/// ISO 639-2 (B) language code
|
|
|
|
std::string tagISO2;
|
|
|
|
|
2023-12-16 15:27:18 +02:00
|
|
|
/// DateTime format
|
|
|
|
std::string dateTimeFormat;
|
|
|
|
|
2023-11-10 16:10:01 +02:00
|
|
|
/// Ruleset for plural forms in this language
|
|
|
|
EPluralForms pluralForms = EPluralForms::NONE;
|
2023-10-19 16:19:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline const auto & getLanguageList()
|
|
|
|
{
|
2024-05-07 15:37:39 +02:00
|
|
|
static const std::array<Options, 17> languages
|
2023-10-19 16:19:09 +02:00
|
|
|
{ {
|
2024-11-17 01:02:13 +02:00
|
|
|
{ "czech", "Czech", "Čeština", "CP1250", "cs", "cze", "%d.%m.%Y %H:%M:%S", EPluralForms::CZ_3 },
|
|
|
|
{ "chinese", "Chinese", "简体中文", "GBK", "zh", "chi", "%Y-%m-%d %H:%M:%S", EPluralForms::VI_1 }, // Note: actually Simplified Chinese
|
|
|
|
{ "english", "English", "English", "CP1252", "en", "eng", "%Y-%m-%d %H:%M:%S", EPluralForms::EN_2 }, // English uses international date/time format here
|
|
|
|
{ "finnish", "Finnish", "Suomi", "CP1252", "fi", "fin", "%d.%m.%Y %H:%M:%S", EPluralForms::EN_2, },
|
|
|
|
{ "french", "French", "Français", "CP1252", "fr", "fre", "%d/%m/%Y %H:%M:%S", EPluralForms::FR_2, },
|
|
|
|
{ "german", "German", "Deutsch", "CP1252", "de", "ger", "%d.%m.%Y %H:%M:%S", EPluralForms::EN_2, },
|
|
|
|
{ "hungarian", "Hungarian", "Magyar", "CP1250", "hu", "hun", "%Y. %m. %d. %H:%M:%S", EPluralForms::EN_2 },
|
|
|
|
{ "italian", "Italian", "Italiano", "CP1250", "it", "ita", "%d/%m/%Y %H:%M:%S", EPluralForms::EN_2 },
|
|
|
|
{ "korean", "Korean", "한국어", "CP949", "ko", "kor", "%Y-%m-%d %H:%M:%S", EPluralForms::VI_1 },
|
|
|
|
{ "polish", "Polish", "Polski", "CP1250", "pl", "pol", "%d.%m.%Y %H:%M:%S", EPluralForms::PL_3 },
|
|
|
|
{ "portuguese", "Portuguese", "Português", "CP1252", "pt", "por", "%d/%m/%Y %H:%M:%S", EPluralForms::EN_2 }, // Note: actually Brazilian Portuguese
|
|
|
|
{ "russian", "Russian", "Русский", "CP1251", "ru", "rus", "%d.%m.%Y %H:%M:%S", EPluralForms::UK_3 },
|
|
|
|
{ "spanish", "Spanish", "Español", "CP1252", "es", "spa", "%d/%m/%Y %H:%M:%S", EPluralForms::EN_2 },
|
|
|
|
{ "swedish", "Swedish", "Svenska", "CP1252", "sv", "swe", "%Y-%m-%d %H:%M:%S", EPluralForms::EN_2 },
|
|
|
|
{ "turkish", "Turkish", "Türkçe", "CP1254", "tr", "tur", "%d.%m.%Y %H:%M:%S", EPluralForms::EN_2 },
|
|
|
|
{ "ukrainian", "Ukrainian", "Українська", "CP1251", "uk", "ukr", "%d.%m.%Y %H:%M:%S", EPluralForms::UK_3 },
|
|
|
|
{ "vietnamese", "Vietnamese", "Tiếng Việt", "UTF-8", "vi", "vie", "%d/%m/%Y %H:%M:%S", EPluralForms::VI_1 }, // Fan translation uses special encoding
|
2023-10-19 16:19:09 +02:00
|
|
|
} };
|
|
|
|
static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
|
|
|
|
|
|
|
|
return languages;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Options & getLanguageOptions(ELanguages language)
|
|
|
|
{
|
2024-03-13 23:02:53 +02:00
|
|
|
return getLanguageList().at(static_cast<size_t>(language));
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const Options & getLanguageOptions(const std::string & language)
|
|
|
|
{
|
|
|
|
for(const auto & entry : getLanguageList())
|
|
|
|
if(entry.identifier == language)
|
|
|
|
return entry;
|
|
|
|
|
2024-03-27 13:08:41 +02:00
|
|
|
throw std::out_of_range("Language " + language + " does not exists!");
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 16:10:01 +02:00
|
|
|
template<typename Numeric>
|
|
|
|
inline constexpr int getPluralFormIndex(EPluralForms form, Numeric value)
|
|
|
|
{
|
|
|
|
// Based on https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html
|
|
|
|
switch(form)
|
|
|
|
{
|
|
|
|
case EPluralForms::NONE:
|
|
|
|
case EPluralForms::VI_1:
|
|
|
|
return 0;
|
|
|
|
case EPluralForms::EN_2:
|
|
|
|
if (value == 1)
|
|
|
|
return 1;
|
|
|
|
return 2;
|
|
|
|
case EPluralForms::FR_2:
|
|
|
|
if (value == 1 || value == 0)
|
|
|
|
return 1;
|
|
|
|
return 2;
|
|
|
|
case EPluralForms::UK_3:
|
|
|
|
if (value % 10 == 1 && value % 100 != 11)
|
|
|
|
return 1;
|
|
|
|
if (value%10>=2 && value%10<=4 && (value%100<10 || value%100>=20))
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
case EPluralForms::CZ_3:
|
|
|
|
if (value == 1)
|
|
|
|
return 1;
|
|
|
|
if (value>=2 && value<=4)
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
case EPluralForms::PL_3:
|
|
|
|
if (value == 1)
|
|
|
|
return 1;
|
|
|
|
if (value%10>=2 && value%10<=4 && (value%100<10 || value%100>=20))
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
throw std::runtime_error("Invalid plural form enumeration received!");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Numeric>
|
|
|
|
inline std::string getPluralFormTextID(std::string languageName, Numeric value, std::string textID)
|
|
|
|
{
|
|
|
|
int formIndex = getPluralFormIndex(getLanguageOptions(languageName).pluralForms, value);
|
|
|
|
return textID + '.' + std::to_string(formIndex);
|
|
|
|
}
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|