From: Abdelrazak Younes Date: Sat, 13 Jan 2007 17:10:39 +0000 (+0000) Subject: - rename CacheType X-Git-Tag: 1.6.10~11208 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e17b39d4538fb9f2f8d51e5563188953f9d576b6;p=features.git - rename CacheType - replace static string with private member - test the success of the cache insertion git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16668 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/messages.C b/src/messages.C index 13098b8730..a8b2421f13 100644 --- a/src/messages.C +++ b/src/messages.C @@ -116,12 +116,13 @@ public: docstring const & get(string const & m) const { - static docstring empty_string; - if (m.empty()) - return empty_string; + if (m.empty()) { + dummy_string_.clear(); + return dummy_string_; + } // Look for the translated string in the cache. - CacheType::iterator it = cache_.find(m); + TranslationCache::iterator it = cache_.find(m); if (it != cache_.end()) return it->second; // The string was not found, use gettext to generate it: @@ -214,17 +215,26 @@ public: #endif setlocale(LC_CTYPE, oldCTYPE.c_str()); + if (!cache_.insert(std::make_pair(m, translated)).second) { + lyxerr << "WARNING: cannot fill-in gettext cache in Messages::get()!" << endl; + dummy_string_ = translated; + return dummy_string_; + } + it = cache_.insert(std::make_pair(m, translated)).first; return it->second; } private: /// string lang_; - typedef std::map CacheType; + typedef std::map TranslationCache; /// Internal cache for gettext translated strings. /// This is needed for performance reason within \c updateLabels() /// under Windows. - mutable CacheType cache_; + mutable TranslationCache cache_; + /// Dummy string which serves as a storage place if something goes + /// wrong with the translation cache. + mutable docstring dummy_string_; }; #endif