Commit initial version of simple win32 language support.
*Fixes a number of setlocale() warnings *Adds a simple translation table for locale codes *Replaces unrecognized LC_MESSAGES category with LC_ALL in windows calls.
This commit is contained in:
parent
79d16c9c40
commit
98c2a14b4e
4 changed files with 113 additions and 35 deletions
|
@ -38,9 +38,9 @@
|
|||
#include <assert.h>
|
||||
#include <clocale>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "locale.h"
|
||||
#endif
|
||||
//#ifdef _WIN32
|
||||
//#include "locale.h"
|
||||
//#endif
|
||||
|
||||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
#define LOG_DP LOG_STREAM(info, display)
|
||||
|
@ -486,11 +486,7 @@ void save_preview_pane::draw_contents()
|
|||
SDL_BlitSurface(map_surf,NULL,screen,&map_rect);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
char* old_locale = std::setlocale(LC_TIME, get_locale().localename.c_str());
|
||||
#else
|
||||
char* old_locale = ::setlocale(LC_TIME, get_locale().localename.c_str());
|
||||
#endif
|
||||
char time_buf[256] = {0};
|
||||
const save_info& save = (*info_)[index_];
|
||||
tm* tm_l = localtime(&save.time_modified);
|
||||
|
@ -504,11 +500,7 @@ void save_preview_pane::draw_contents()
|
|||
}
|
||||
|
||||
if(old_locale) {
|
||||
#ifndef _WIN32
|
||||
std::setlocale(LC_TIME, old_locale);
|
||||
#else
|
||||
::setlocale(LC_TIME, old_locale);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::stringstream str;
|
||||
|
|
19
src/game.cpp
19
src/game.cpp
|
@ -62,9 +62,9 @@
|
|||
#include "serialization/string_utils.hpp"
|
||||
#include "sha1.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "locale.h"
|
||||
#endif
|
||||
//#ifdef _WIN32
|
||||
//#include "locale.h"
|
||||
//#endif
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
#include "ai_python.hpp"
|
||||
|
@ -2571,13 +2571,12 @@ static int play_game(int argc, char** argv)
|
|||
// initialized to have get_intl_dir() to work. Note: this
|
||||
// setlocale() but this does not take GUI language setting
|
||||
// into account.
|
||||
#ifndef _WIN32
|
||||
std::setlocale(LC_ALL, "C");
|
||||
std::setlocale(LC_MESSAGES, "");
|
||||
#else
|
||||
::setlocale(LC_ALL, "C");
|
||||
::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
std::setlocale(LC_ALL, "English");
|
||||
#else
|
||||
std::setlocale(LC_ALL, "C");
|
||||
std::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
const std::string& intl_dir = get_intl_dir();
|
||||
bindtextdomain (PACKAGE, intl_dir.c_str());
|
||||
bind_textdomain_codeset (PACKAGE, "UTF-8");
|
||||
|
|
|
@ -198,8 +198,17 @@ static void wesnoth_setlocale(int category, std::string const &slocale,
|
|||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
const std::string env = "LANG=" + slocale;
|
||||
std::string env = "LANG=" + slocale;
|
||||
_putenv(env.c_str());
|
||||
env = "LC_ALL=" + slocale;
|
||||
_putenv(env.c_str());
|
||||
std::string win_locale = locale;
|
||||
win_locale = win_locale.substr(0,2);
|
||||
#include "language_win32.ii"
|
||||
SetEnvironmentVariable("LANG", win_locale.c_str());
|
||||
SetEnvironmentVariable("LC_ALL", win_locale.c_str());
|
||||
if(category == LC_MESSAGES)
|
||||
category = LC_ALL;
|
||||
#endif
|
||||
|
||||
#ifdef USE_DUMMYLOCALES
|
||||
|
@ -226,31 +235,23 @@ static void wesnoth_setlocale(int category, std::string const &slocale,
|
|||
#endif
|
||||
|
||||
char *res = NULL;
|
||||
char const *try_loc = locale;
|
||||
#ifdef _WIN32
|
||||
char const *try_loc = win_locale.c_str();
|
||||
#else
|
||||
char const *try_loc = locale;
|
||||
#endif
|
||||
std::vector<std::string>::const_iterator i;
|
||||
if (alternates) i = alternates->begin();
|
||||
while (true) {
|
||||
// #ifndef _WIN32
|
||||
res = std::setlocale(category, try_loc);
|
||||
// #else
|
||||
// res = ::setlocale(category, try_loc);
|
||||
// #endif
|
||||
if (res) break;
|
||||
|
||||
std::string utf8 = std::string(try_loc) + std::string(".utf-8");
|
||||
// #ifndef _WIN32
|
||||
res = std::setlocale(category, utf8.c_str());
|
||||
// #else
|
||||
// res = ::setlocale(category, try_loc);
|
||||
// #endif
|
||||
if (res) break;
|
||||
|
||||
utf8 = std::string(try_loc) + std::string(".UTF-8");
|
||||
// #ifndef _WIN32
|
||||
res = std::setlocale(category, utf8.c_str());
|
||||
/// #else
|
||||
// res = ::setlocale(category, utf8.c_str());
|
||||
// #endif
|
||||
if (res) break;
|
||||
|
||||
if (!alternates) break;
|
||||
|
@ -332,6 +333,11 @@ 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;
|
||||
#endif
|
||||
if(locale != NULL && strlen(locale) >= 2) {
|
||||
//we can't pass pointers into the string to the std::string
|
||||
//constructor because some STL implementations don't support
|
||||
|
|
81
src/language_win32.ii
Normal file
81
src/language_win32.ii
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Simplified translation table from unix locale symbols to win32 locale strings
|
||||
|
||||
if(win_locale=="af")
|
||||
win_locale = "Afrikaans";
|
||||
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=="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=="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=="mk")
|
||||
win_locale = "Macedonian";
|
||||
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=="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 = "C";
|
||||
if(win_locale=="tr")
|
||||
win_locale = "Urdu";
|
||||
if(win_locale=="zh")
|
||||
win_locale = "Chinese";
|
||||
|
Loading…
Add table
Reference in a new issue