mail[Wesnoth-commits] r36916 - in /trunk/src: config.cpp config.hpp game.cpp language.cpp tstring.cpp tstring.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on July 15, 2009 - 22:17:
Author: silene
Date: Wed Jul 15 22:17:33 2009
New Revision: 36916

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36916&view=rev
Log:
Fixed hotkey dialog not being refreshed on language change. (In fact, 
definitely fixed all the issues related to language changes by removing the 
code responsible for resetting translations.)

Modified:
    trunk/src/config.cpp
    trunk/src/config.hpp
    trunk/src/game.cpp
    trunk/src/language.cpp
    trunk/src/tstring.cpp
    trunk/src/tstring.hpp

Modified: trunk/src/config.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.cpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/config.cpp (original)
+++ trunk/src/config.cpp Wed Jul 15 22:17:33 2009
@@ -839,22 +839,6 @@
        }
 }
 
-void config::reset_translation() const
-{
-       check_valid();
-
-       for(string_map::const_iterator val = values.begin(); val != 
values.end(); ++val) {
-               val->second.reset_translation();
-       }
-
-       for(child_map::const_iterator list = children.begin(); list != 
children.end(); ++list) {
-               for(child_list::const_iterator child = list->second.begin();
-                               child != list->second.end(); ++child) {
-                       (*child)->reset_translation();
-               }
-       }
-}
-
 std::string config::debug() const
 {
        check_valid();

Modified: trunk/src/config.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.hpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/config.hpp (original)
+++ trunk/src/config.hpp Wed Jul 15 22:17:33 2009
@@ -341,9 +341,6 @@
         */
        void merge_children(const std::string& key);
 
-       /** Resets the translated values of all strings contained in this 
object */
-       void reset_translation() const;
-
        //this is a cheap O(1) operation
        void swap(config& cfg);
 

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Wed Jul 15 22:17:33 2009
@@ -170,7 +170,6 @@
        void operator=(const game_controller&);
 
        void load_game_cfg(const bool force=false);
-       void reset_translations();
        void set_unit_data();
 
        bool detect_video_settings(); // FIXME
@@ -1359,7 +1358,7 @@
                        SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
                }
 
-               reset_translations();
+               t_string::reset_translations();
        }
 
        return true;
@@ -1386,26 +1385,6 @@
        if (config &units = game_config_.child("units")) {
                unit_type_data::types().set_config(units);
        }
-}
-
-void game_controller::reset_translations()
-{
-       cursor::setter cur(cursor::WAIT);
-
-       try {
-               game_config_.reset_translation();
-               // we may have translatable strings in [game_config]
-               // e.g. team color names are defined there
-               config &cfg = game_config_.child("game_config");
-               game_config::load_config(cfg ? &cfg : NULL);
-               set_unit_data();
-       } catch(game::error& e) {
-               ERR_CONFIG << "Error loading game configuration files\n";
-               gui2::show_error_message(disp().video(), _("Error loading 
game configuration files: '") +
-                       e.message + _("' (The game will now exit)"));
-               throw;
-       }
-
 }
 
 void game_controller::load_game_cfg(const bool force)

Modified: trunk/src/language.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/language.cpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/language.cpp (original)
+++ trunk/src/language.cpp Wed Jul 15 22:17:33 2009
@@ -309,13 +309,6 @@
                strings_[j.first] = j.second;
        }
        // end of string_table fill
-
-       // Reset translations for the name of current languages
-       for (language_list::iterator itor = known_languages.begin();
-                       itor != known_languages.end(); ++itor) {
-
-               itor->language.reset_translation();
-       }
 
        return true;
 }

Modified: trunk/src/tstring.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tstring.cpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/tstring.cpp (original)
+++ trunk/src/tstring.cpp Wed Jul 15 22:17:33 2009
@@ -31,6 +31,8 @@
 static lg::log_domain log_config("config");
 #define LOG_CF LOG_STREAM(info, log_config)
 #define ERR_CF LOG_STREAM(err, log_config)
+
+static unsigned language_counter = 0;
 
 namespace {
        const char TRANSLATABLE_PART = 0x01;
@@ -165,6 +167,7 @@
 t_string_base::t_string_base() :
        value_(),
        translated_value_(),
+       translation_timestamp_(0),
        translatable_(false),
        last_untranslatable_(false)
 {
@@ -173,6 +176,7 @@
 t_string_base::t_string_base(const t_string_base& string) :
        value_(string.value_),
        translated_value_(string.translated_value_),
+       translation_timestamp_(string.translation_timestamp_),
        translatable_(string.translatable_),
        last_untranslatable_(string.last_untranslatable_)
 {
@@ -181,6 +185,7 @@
 t_string_base::t_string_base(const std::string& string) :
        value_(string),
        translated_value_(),
+       translation_timestamp_(0),
        translatable_(false),
        last_untranslatable_(false)
 {
@@ -189,6 +194,7 @@
 t_string_base::t_string_base(const std::string& string, const std::string& 
textdomain) :
        value_(1, ID_TRANSLATABLE_PART),
        translated_value_(),
+       translation_timestamp_(0),
        translatable_(true),
        last_untranslatable_(false)
 {
@@ -211,6 +217,7 @@
 t_string_base::t_string_base(const char* string) :
        value_(string),
        translated_value_(),
+       translation_timestamp_(0),
        translatable_(false),
        last_untranslatable_(false)
 {
@@ -411,8 +418,10 @@
        if(!translatable_)
                return value_;
 
-       if(translatable_ && !translated_value_.empty())
+       if (translatable_ && !translated_value_.empty() && 
translation_timestamp_ == language_counter)
                return translated_value_;
+
+       translated_value_.clear();
 
        for(walker w(*this); !w.eos(); w.next()) {
                std::string part(w.begin(), w.end());
@@ -424,11 +433,12 @@
                }
        }
 
+       translation_timestamp_ = language_counter;
        return translated_value_;
 }
 
 
-void t_string_base::add_textdomain(const std::string& name, const 
std::string& path)
+void t_string::add_textdomain(const std::string &name, const std::string 
&path)
 {
        LOG_CF << "Binding textdomain " << name << " to path " << path << 
"\n";
 
@@ -437,6 +447,11 @@
        bind_textdomain_codeset(name.c_str(), "UTF-8");
 }
 
+void t_string::reset_translations()
+{
+       ++language_counter;
+}
+
 std::ostream& operator<<(std::ostream& stream, const t_string_base& string)
 {
        stream << string.str();

Modified: trunk/src/tstring.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tstring.hpp?rev=36916&r1=36915&r2=36916&view=diff
==============================================================================
--- trunk/src/tstring.hpp (original)
+++ trunk/src/tstring.hpp Wed Jul 15 22:17:33 2009
@@ -21,9 +21,6 @@
 
 /**
  * Helper class for translatable strings.
- *
- * NOTE don't use static t_string_base objects since they don't change when 
the
- * language changes.
  */
 class t_string;
 class t_string_base
@@ -96,14 +93,11 @@
        const std::string& value() const                 { return value_; }
        std::string base_str() const;
 
-       void reset_translation() const                   { translated_value_ 
= ""; }
-
-       static void add_textdomain(const std::string& name, const 
std::string& path);
-
        size_t hash_value() const;
 private:
        std::string value_;
        mutable std::string translated_value_;
+       mutable unsigned translation_timestamp_;
        bool translatable_, last_untranslatable_;
 };
 
@@ -158,11 +152,8 @@
        const std::string& value() const { return get().value(); }
        std::string base_str() const { return get().base_str(); }
 
-       void reset_translation() const { get().reset_translation(); }
-
-       static void add_textdomain(const std::string& name, const 
std::string& path) {
-               base::add_textdomain(name, path);
-       }
+       static void add_textdomain(const std::string &name, const std::string 
&path);
+       static void reset_translations();
 
        const t_string_base& get() const { return super::get(); }
 };




Related Messages


Powered by MHonArc, Updated Wed Jul 15 23:00:53 2009