Languages.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Languages.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. namespace Languages
  12. {
  13. enum class ELanguages
  14. {
  15. CZECH,
  16. CHINESE,
  17. ENGLISH,
  18. FINNISH,
  19. FRENCH,
  20. GERMAN,
  21. HUNGARIAN,
  22. ITALIAN,
  23. KOREAN,
  24. POLISH,
  25. PORTUGUESE,
  26. RUSSIAN,
  27. SPANISH,
  28. SWEDISH,
  29. TURKISH,
  30. UKRAINIAN,
  31. VIETNAMESE,
  32. // Pseudo-languages, that have no translations but can define H3 encoding to use
  33. OTHER_CP1250,
  34. OTHER_CP1251,
  35. OTHER_CP1252,
  36. COUNT
  37. };
  38. struct Options
  39. {
  40. /// string identifier (ascii, lower-case), e.g. "english"
  41. std::string identifier;
  42. /// human-readable name of language in English
  43. std::string nameEnglish;
  44. /// human-readable name of language in its own language
  45. std::string nameNative;
  46. /// encoding that is used by H3 for this language
  47. std::string encoding;
  48. /// primary IETF language tag
  49. std::string tagIETF;
  50. /// POSIX locale
  51. std::string locale;
  52. /// VCMI supports translations into this language
  53. bool hasTranslation = false;
  54. };
  55. inline const auto & getLanguageList()
  56. {
  57. static const std::array<Options, 20> languages
  58. { {
  59. { "czech", "Czech", "Čeština", "CP1250", "cs", "cs_CZ.UTF-8", true },
  60. { "chinese", "Chinese", "简体中文", "GBK", "zh", "zh_CN.UTF-8", true }, // Note: actually Simplified Chinese
  61. { "english", "English", "English", "CP1252", "en", "en_US.UTF-8", true },
  62. { "finnish", "Finnish", "Suomi", "CP1252", "fi", "fi_FI.UTF-8", true },
  63. { "french", "French", "Français", "CP1252", "fr", "fr_FR.UTF-8", true },
  64. { "german", "German", "Deutsch", "CP1252", "de", "de_DE.UTF-8", true },
  65. { "hungarian", "Hungarian", "Magyar", "CP1250", "hu", "hu_HU.UTF-8", true },
  66. { "italian", "Italian", "Italiano", "CP1250", "it", "it_IT.UTF-8", true },
  67. { "korean", "Korean", "한국어", "CP949", "ko", "ko_KR.UTF-8", true },
  68. { "polish", "Polish", "Polski", "CP1250", "pl", "pl_PL.UTF-8", true },
  69. { "portuguese", "Portuguese", "Português", "CP1252", "pt", "pt_BR.UTF-8", true }, // Note: actually Brazilian Portuguese
  70. { "russian", "Russian", "Русский", "CP1251", "ru", "ru_RU.UTF-8", true },
  71. { "spanish", "Spanish", "Español", "CP1252", "es", "es_ES.UTF-8", true },
  72. { "swedish", "Swedish", "Svenska", "CP1252", "sv", "sv_SE.UTF-8", true },
  73. { "turkish", "Turkish", "Türkçe", "CP1254", "tr", "tr_TR.UTF-8", true },
  74. { "ukrainian", "Ukrainian", "Українська", "CP1251", "uk", "uk_UA.UTF-8", true },
  75. { "vietnamese", "Vietnamese", "Tiếng Việt", "UTF-8", "vi", "vi_VN.UTF-8", true }, // Fan translation uses special encoding
  76. { "other_cp1250", "Other (East European)", "", "CP1250", "", "", false },
  77. { "other_cp1251", "Other (Cyrillic Script)", "", "CP1251", "", "", false },
  78. { "other_cp1252", "Other (West European)", "", "CP1252", "", "", false }
  79. } };
  80. static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
  81. return languages;
  82. }
  83. inline const Options & getLanguageOptions(ELanguages language)
  84. {
  85. assert(language < ELanguages::COUNT);
  86. return getLanguageList()[static_cast<size_t>(language)];
  87. }
  88. inline const Options & getLanguageOptions(const std::string & language)
  89. {
  90. for(const auto & entry : getLanguageList())
  91. if(entry.identifier == language)
  92. return entry;
  93. static const Options emptyValue;
  94. assert(0);
  95. return emptyValue;
  96. }
  97. }