Make the installer generate locale files, and use them in language.cpp.

The code is rather experimental, but it is disabled by default: it
requires a configure option. So it isn't a release-stopper. The
autostuff would benefit from some tidying by an expert.
This commit is contained in:
Guillaume Melquiond 2005-04-23 17:09:48 +00:00
parent 4dd107027d
commit f9d37f356b
4 changed files with 43 additions and 9 deletions

View file

@ -32,6 +32,13 @@ if INSTALLDATA
echo " $(install_sh_DATA) '$$d$$p' '$(DESTDIR)$(pkgdatadir)/$$f'"; \
$(install_sh_DATA) "$$d$$p" "$(DESTDIR)$(pkgdatadir)/$$f"; \
done
if DUMMYLOCALES
$(mkdir_p) "$(DESTDIR)$(pkgdatadir)/locales"; \
echo | localedef --force "$(DESTDIR)$(pkgdatadir)/locales/C" 2> /dev/null; \
for loc in `sed -n 's/^.*language_def..\(.._..\).*$$/\1/p' "$(srcdir)/src/language.cpp"`; do \
ln -s C "$(DESTDIR)$(pkgdatadir)/locales/$$loc"; done; \
true
endif
if TINYGUI
(cd $(top_srcdir) && find images images/terrain \( $(findfilterflags) -o -name '*.png' -print \) ) | while read p; do \
$(w_preparefileinstall) \

View file

@ -44,6 +44,9 @@ CVS HEAD:
* Japanese
* Slovenian
* Swedish
* added a ./configure --with-dummy-locales option for Wesnoth to generate
its own set of i18n locale files and use them instead of the potentially
missing system files (highly experimental)
* fixed the missing 'elder-mage-halo7.png' in the Elder Mage
* fixed some OoS errors when chatting while a fight is taking place
* fixed the spurious "statistics verification failed" messages

View file

@ -217,6 +217,11 @@ AC_ARG_ENABLE([wzip],
[wzip=$enableval],
[wzip=no])
AC_ARG_ENABLE([dummy-locales],
AS_HELP_STRING([--enable-dummy-locales], [enable installation of Wesnoth own provate locales]),
[dummylocales=$enableval],
[dummylocales=no])
AM_CONDITIONAL([STATIC], [test x$static = xyes])
AM_CONDITIONAL([GAME], [test x$game = xyes])
AM_CONDITIONAL([SERVER], [test x$server = xyes])
@ -227,6 +232,11 @@ AM_CONDITIONAL([GCC], [test x$GXX = xyes])
AM_CONDITIONAL([WZIP], [test x$wzip = xyes])
AM_CONDITIONAL([INCLUDEDINTL], [test x$nls_cv_use_gnu_gettext = xyes])
AM_CONDITIONAL([INSTALLDATA], [test x$game = xyes || x$editor = xyes])
AM_CONDITIONAL([DUMMYLOCALES], [test x$dummylocales = xyes])
if test x$dummylocales = xyes; then
AC_DEFINE([USE_DUMMYLOCALES],,[Define if the game should not use system locales])
fi
#######################################################################
# Checks for programs. #

View file

@ -16,12 +16,14 @@
#include "config.hpp"
#include "filesystem.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "language.hpp"
#include "preferences.hpp"
#include "util.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "wesconfig.h"
#include <algorithm>
#include <cctype>
@ -118,8 +120,9 @@ std::vector<language_def> get_languages()
return res;
}
char* wesnoth_setlocale(int category, const char *locale)
static void wesnoth_setlocale(int category, std::string const &slocale)
{
char const *locale = slocale.c_str();
#ifdef __BEOS__
if(setenv ("LANG", locale, 1) == -1)
std::cerr << "setenv LANG failed: " << strerror(errno);
@ -134,15 +137,29 @@ char* wesnoth_setlocale(int category, const char *locale)
#endif
#ifdef _WIN32
const std::string env = std::string("LANG=") + locale;
const std::string env = "LANG=" + slocale;
putenv(env.c_str());
#endif
#ifdef USE_DUMMYLOCALES
static enum { UNINIT, NONE, PRESENT } status = UNINIT;
static std::string locpath;
if (status == UNINIT)
if (char const *p = getenv("LOCPATH")) {
locpath = p;
status = PRESENT;
} else status = NONE;
if (slocale.empty())
if (status == NONE)
unsetenv("LOCPATH");
else
setenv("LOCPATH", locpath.c_str(), 1);
else setenv("LOCPATH", (game_config::path + "/locales").c_str(), 1);
#endif
char* res = setlocale (category, locale);
if (res == NULL)
std::cerr << "WARNING: setlocale() failed for "
<< locale << ".\n";
return res;
}
bool set_language(const language_def& locale)
@ -156,7 +173,7 @@ bool set_language(const language_def& locale)
config cfg;
current_language = locale;
wesnoth_setlocale (LC_MESSAGES, locale.localename.c_str());
wesnoth_setlocale(LC_MESSAGES, locale.localename);
known_languages[0].language = gettext("System default language");
// fill string_table (should be moved somwhere else some day)
@ -190,15 +207,12 @@ const language_def& get_locale()
const std::string& prefs_locale = preferences::language();
if(prefs_locale.empty() == false) {
char* setlocaleres = wesnoth_setlocale (LC_MESSAGES, prefs_locale.c_str());
if(setlocaleres == NULL)
std::cerr << "call to setlocale() failed for " << prefs_locale.c_str() << "\n";
wesnoth_setlocale(LC_MESSAGES, prefs_locale);
for(int i = 0; known_languages[i].language[0] != '\0'; i++) {
if (prefs_locale == known_languages[i].localename)
return known_languages[i];
}
std::cerr << "setlocale succeeded but locale not found in known array; defaulting to system locale\n";
std::cerr << "locale not found in known array; defaulting to system locale\n";
return known_languages[0];
}