From 0f6f0a1525ce3dd9b1ea472b1eb3f5026944b661 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sun, 18 May 2008 09:34:19 +0000 Subject: [PATCH] Added a new experimental feature in the new widget library. This feature disables languages not available on the system. It has only been tested on Linux and it can use more testing on other platforms. (bug #11212) --- RELEASE_NOTES | 5 +++ changelog | 4 ++ src/gui/dialogs/language_selection.cpp | 2 + src/language.cpp | 55 ++++++++++++++++++++++++++ src/language.hpp | 7 ++++ 5 files changed, 73 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index ae94f7c6412..c7ae8cfe4af 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -10,3 +10,8 @@ is making sure that spelling/grammer/whatever is usable and that you are using The release team should empty this file after each release. + +There is a new experimental function to gray out not available languages in the +language selection dialog. This feature is available when Wesnoth is started +with the --new-widgets parameter. Packagers of various platforms are encouraged +to test this feature and report bugs when found. diff --git a/changelog b/changelog index 18f6b07a7ac..5de24a1efbc 100644 --- a/changelog +++ b/changelog @@ -17,10 +17,14 @@ Version 1.5.0+svn: * graphics: * new ford graphics from Syntax_Error * added a sea serpent portrait by Pic + * various improvements to the new widget library * language and i18n: * new translations: Friulian, Macedonian * updated translations: Chinese, Czech, Danish, Finnish, French, German, Italian, Polish, Russian, Slovak, Spanish, Turkish + * the new widget library supports disabling of rows in a listbox, this is + used to deactivate not available languages. This feature is experimental + and only available when started with --new-widgets (bug #11212) * multiplayer: * revised maps: Den of Onis * Python AI: diff --git a/src/gui/dialogs/language_selection.cpp b/src/gui/dialogs/language_selection.cpp index f5a404e9620..c93dc825a1e 100644 --- a/src/gui/dialogs/language_selection.cpp +++ b/src/gui/dialogs/language_selection.cpp @@ -51,6 +51,8 @@ void tlanguage_selection::show(CVideo& video) std::cerr << "select row " << list->get_item_count() - 1 << ".\n"; list->select_row(list->get_item_count() - 1); } + + list->set_row_active(list->get_item_count() - 1, lang.available()); } window.recalculate_size(); diff --git a/src/language.cpp b/src/language.cpp index 64b8bfc76e5..68bfd64f8aa 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -17,6 +17,7 @@ #include "config.hpp" #include "filesystem.hpp" +#include "foreach.hpp" #include "game_config.hpp" #include "gettext.hpp" #include "language.hpp" @@ -35,6 +36,41 @@ #include #include #include +#include + +/** Tests one locale to be available. */ +static bool has_locale(const char* s) { + try { + // The way to find out whether a locale is available is to set it and + // hope not runtime error gets thrown. + std::locale dummy(s); + std::cerr << "Locale : " << s << " found.\n"; + return true; + } catch (std::runtime_error&) { + std::cerr << "Locale : " << s << " not found.\n"; + return false; + } +} + +/** Test the locale for a language and it's utf-8 variations. */ +static bool has_language(const std::string& language) +{ + if(has_locale(language.c_str())) { + return true; + } + + std::string utf = language + ".utf-8"; + if(has_locale(utf.c_str())) { + return true; + } + + utf = language + ".UTF-8"; + if(has_locale(utf.c_str())) { + return true; + } + + return false; +} namespace { language_def current_language; @@ -58,6 +94,25 @@ bool language_def::operator== (const language_def& a) const return ((language == a.language) /* && (localename == a.localename) */ ); } +bool language_def::available() const +{ +#ifdef USE_DUMMYLOCALES + // Dummy has every language available. + return true; +#else + if(has_language(localename)) { + return true; + } else { + foreach(const std::string& lang, alternates) { + if(has_language(lang)) { + return true; + } + } + } + return false; +#endif +} + symbol_table string_table; const t_string& symbol_table::operator[](const std::string& key) const diff --git a/src/language.hpp b/src/language.hpp index 1275deae4a1..0a89c68aaed 100644 --- a/src/language.hpp +++ b/src/language.hpp @@ -50,6 +50,13 @@ struct language_def t_string language; bool rtl; // A right to left language? (e.g: Hebrew) bool operator== (const language_def&) const; + + /** + * Is the locale available on the system? + * + * If the dummy locales are selected we always return true. + */ + bool available() const; }; std::string languagedef_name (const language_def& def);