i18n: Convert POSIX/Win32 locale table file into a map
This removes the need for the separate file and the giant if chain by using a std::map instead.
This commit is contained in:
parent
3028a83cb6
commit
48e6b821b0
9 changed files with 65 additions and 123 deletions
|
@ -797,7 +797,6 @@
|
|||
<Unit filename="../../src/key.hpp" />
|
||||
<Unit filename="../../src/language.cpp" />
|
||||
<Unit filename="../../src/language.hpp" />
|
||||
<Unit filename="../../src/language_win32.ii" />
|
||||
<Unit filename="../../src/lexical_cast.hpp" />
|
||||
<Unit filename="../../src/libc_error.hpp" />
|
||||
<Unit filename="../../src/log.cpp" />
|
||||
|
|
|
@ -848,7 +848,6 @@
|
|||
<Unit filename="../../src/key.hpp" />
|
||||
<Unit filename="../../src/language.cpp" />
|
||||
<Unit filename="../../src/language.hpp" />
|
||||
<Unit filename="../../src/language_win32.ii" />
|
||||
<Unit filename="../../src/lexical_cast.hpp" />
|
||||
<Unit filename="../../src/libc_error.hpp" />
|
||||
<Unit filename="../../src/log.cpp" />
|
||||
|
|
|
@ -846,7 +846,6 @@
|
|||
<Unit filename="../../src/key.hpp" />
|
||||
<Unit filename="../../src/language.cpp" />
|
||||
<Unit filename="../../src/language.hpp" />
|
||||
<Unit filename="../../src/language_win32.ii" />
|
||||
<Unit filename="../../src/lexical_cast.hpp" />
|
||||
<Unit filename="../../src/libc_error.hpp" />
|
||||
<Unit filename="../../src/log.cpp" />
|
||||
|
|
|
@ -316,7 +316,6 @@
|
|||
<ItemGroup>
|
||||
<None Include="..\..\src\animated.tpp" />
|
||||
<None Include="..\..\src\filesystem_win32.ii" />
|
||||
<None Include="..\..\src\language_win32.ii" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\about.cpp" />
|
||||
|
|
|
@ -174,9 +174,6 @@
|
|||
<None Include="..\..\src\filesystem_win32.ii">
|
||||
<Filter>Others</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\language_win32.ii">
|
||||
<Filter>Others</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\addon\client.cpp">
|
||||
|
@ -3046,4 +3043,4 @@
|
|||
<Filter>Tests\Utils</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -327,7 +327,6 @@
|
|||
<ItemGroup>
|
||||
<None Include="..\..\src\animated.tpp" />
|
||||
<None Include="..\..\src\filesystem_win32.ii" />
|
||||
<None Include="..\..\src\language_win32.ii" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\about.cpp" />
|
||||
|
|
|
@ -180,9 +180,6 @@
|
|||
<None Include="..\..\src\filesystem_win32.ii">
|
||||
<Filter>Others</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\language_win32.ii">
|
||||
<Filter>Others</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\addon\client.cpp">
|
||||
|
@ -3067,4 +3064,4 @@
|
|||
<Filter>Tests\Utils</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -133,6 +133,67 @@ void set_min_translation_percent(int percent) {
|
|||
min_translation_percent = percent;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Simplified translation table from unix locale symbols to win32 locale strings
|
||||
static const std::map<std::string, std::string> win32_locales_map = {
|
||||
{ "af", "Afrikaans" },
|
||||
{ "ang", "C" },
|
||||
{ "ar", "Arabic" },
|
||||
{ "bg", "Bulgarian" },
|
||||
{ "ca", "Catalan" },
|
||||
{ "cs", "Czech" },
|
||||
{ "da", "Danish" },
|
||||
{ "de", "German" },
|
||||
{ "el", "Greek" },
|
||||
{ "en", "English" },
|
||||
{ "eo", "C" },
|
||||
{ "es", "Spanish" },
|
||||
{ "et", "Estonian" },
|
||||
{ "eu", "Basque" },
|
||||
{ "fi", "Finnish" },
|
||||
{ "fr", "French" },
|
||||
{ "fur", "C" },
|
||||
{ "ga", "Irish_Ireland" }, // Yes, "Irish" alone does not work
|
||||
{ "gl", "Galician" },
|
||||
{ "he", "Hebrew" },
|
||||
{ "hr", "Croatian" },
|
||||
{ "hu", "Hungarian" },
|
||||
{ "id", "Indonesian" },
|
||||
{ "is", "Icelandic" },
|
||||
{ "it", "Italian" },
|
||||
{ "ja", "Japanese" },
|
||||
{ "ko", "Korean" },
|
||||
{ "la", "C" },
|
||||
{ "lt", "Lithuanian" },
|
||||
{ "lv", "Latvian" },
|
||||
{ "mk", "Macedonian" },
|
||||
{ "mr", "C" },
|
||||
{ "nb", "Norwegian" },
|
||||
{ "nl", "Dutch" },
|
||||
{ "pl", "Polish" },
|
||||
{ "pt", "Portuguese" },
|
||||
{ "racv", "C" },
|
||||
{ "ro", "Romanian" },
|
||||
{ "ru", "Russian" },
|
||||
{ "sk", "Slovak" },
|
||||
{ "sl", "Slovenian" },
|
||||
{ "sr", "Serbian" },
|
||||
{ "sv", "Swedish" },
|
||||
{ "tl", "Filipino" },
|
||||
{ "tr", "Turkish" },
|
||||
{ "uk", "Ukrainian" },
|
||||
{ "vi", "Vietnamese" },
|
||||
{ "zh", "Chinese" },
|
||||
};
|
||||
|
||||
static const std::string& posix_locale_to_win32(const std::string& posix)
|
||||
{
|
||||
auto it = win32_locales_map.find(posix);
|
||||
return it != win32_locales_map.end() ? it->second : posix;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void wesnoth_setlocale(int category, const std::string& slocale,
|
||||
std::vector<std::string> const *alternates)
|
||||
{
|
||||
|
@ -156,14 +217,7 @@ static void wesnoth_setlocale(int category, const std::string& slocale,
|
|||
|
||||
#ifdef _WIN32
|
||||
std::string win_locale(locale, 0, 2);
|
||||
#include "language_win32.ii"
|
||||
//if(category == LC_MESSAGES) {
|
||||
// SetEnvironmentVariableA("LANG", win_locale.c_str());
|
||||
// std::string env = "LANGUAGE=" + locale;
|
||||
// _putenv(env.c_str());
|
||||
// return;
|
||||
//}
|
||||
locale = win_locale;
|
||||
locale = posix_locale_to_win32(win_locale);
|
||||
#endif
|
||||
|
||||
char *res = nullptr;
|
||||
|
@ -281,9 +335,7 @@ const language_def& get_locale()
|
|||
#if 0
|
||||
const char* const locale = getenv("LANG");
|
||||
#ifdef _WIN32
|
||||
std::string win_locale = locale
|
||||
#include "language_win32.ii"
|
||||
return win_locale;
|
||||
return posix_locale_to_win32(locale);
|
||||
#endif
|
||||
if(locale != nullptr && strlen(locale) >= 2) {
|
||||
//we can't pass pointers into the string to the std::string
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
// Simplified translation table from unix locale symbols to win32 locale strings
|
||||
|
||||
if(win_locale=="af")
|
||||
win_locale = "Afrikaans";
|
||||
if(win_locale=="ang")
|
||||
win_locale = "C";
|
||||
if(win_locale=="ar")
|
||||
win_locale = "Arabic";
|
||||
if(win_locale=="bg")
|
||||
win_locale = "Bulgarian";
|
||||
if(win_locale=="ca")
|
||||
win_locale = "Catalan";
|
||||
if(win_locale=="cs")
|
||||
win_locale = "Czech";
|
||||
if(win_locale=="da")
|
||||
win_locale = "Danish";
|
||||
if(win_locale=="de")
|
||||
win_locale = "German";
|
||||
if(win_locale=="el")
|
||||
win_locale = "Greek";
|
||||
if(win_locale=="en")
|
||||
win_locale = "English";
|
||||
if(win_locale=="eo")
|
||||
win_locale = "C";
|
||||
if(win_locale=="es")
|
||||
win_locale = "Spanish";
|
||||
if(win_locale=="et")
|
||||
win_locale = "Estonian";
|
||||
if(win_locale=="eu")
|
||||
win_locale = "Basque";
|
||||
if(win_locale=="fi")
|
||||
win_locale = "Finnish";
|
||||
if(win_locale=="fr")
|
||||
win_locale = "French";
|
||||
if(win_locale=="fur")
|
||||
win_locale = "C";
|
||||
if(win_locale=="ga")
|
||||
// Yes, "Irish" alone does not work
|
||||
win_locale = "Irish_Ireland";
|
||||
if(win_locale=="gl")
|
||||
win_locale = "Galician";
|
||||
if(win_locale=="he")
|
||||
win_locale = "Hebrew";
|
||||
if(win_locale=="hr")
|
||||
win_locale = "Croatian";
|
||||
if(win_locale=="hu")
|
||||
win_locale = "Hungarian";
|
||||
if(win_locale=="id")
|
||||
win_locale = "Indonesian";
|
||||
if(win_locale=="is")
|
||||
win_locale = "Icelandic";
|
||||
if(win_locale=="it")
|
||||
win_locale = "Italian";
|
||||
if(win_locale=="ja")
|
||||
win_locale = "Japanese";
|
||||
if(win_locale=="ko")
|
||||
win_locale = "Korean";
|
||||
if(win_locale=="la")
|
||||
win_locale = "C";
|
||||
if(win_locale=="lt")
|
||||
win_locale = "Lithuanian";
|
||||
if(win_locale=="lv")
|
||||
win_locale = "Latvian";
|
||||
if(win_locale=="mk")
|
||||
win_locale = "Macedonian";
|
||||
if(win_locale=="mr")
|
||||
win_locale = "C";
|
||||
if(win_locale=="nb")
|
||||
win_locale = "Norwegian";
|
||||
if(win_locale=="nl")
|
||||
win_locale = "Dutch";
|
||||
if(win_locale=="pl")
|
||||
win_locale = "Polish";
|
||||
if(win_locale=="pt")
|
||||
win_locale = "Portuguese";
|
||||
if(win_locale=="racv")
|
||||
win_locale = "C";
|
||||
if(win_locale=="ro")
|
||||
win_locale = "Romanian";
|
||||
if(win_locale=="ru")
|
||||
win_locale = "Russian";
|
||||
if(win_locale=="sk")
|
||||
win_locale = "Slovak";
|
||||
if(win_locale=="sl")
|
||||
win_locale = "Slovenian";
|
||||
if(win_locale=="sr")
|
||||
win_locale = "Serbian";
|
||||
if(win_locale=="sv")
|
||||
win_locale = "Swedish";
|
||||
if(win_locale=="tl")
|
||||
win_locale = "Filipino";
|
||||
if(win_locale=="tr")
|
||||
win_locale = "Turkish";
|
||||
if(win_locale=="uk")
|
||||
win_locale = "Ukrainian";
|
||||
if(win_locale=="vi")
|
||||
win_locale = "Vietnamese";
|
||||
if(win_locale=="zh")
|
||||
win_locale = "Chinese";
|
Loading…
Add table
Reference in a new issue