]> git.lyx.org Git - features.git/commitdiff
- rename CacheType
authorAbdelrazak Younes <younes@lyx.org>
Sat, 13 Jan 2007 17:10:39 +0000 (17:10 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 13 Jan 2007 17:10:39 +0000 (17:10 +0000)
- 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

src/messages.C

index 13098b87301d059f0d977b63d693b051a848f873..a8b2421f134ab80833c7c93db2e7db373e03743b 100644 (file)
@@ -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<string, docstring> CacheType;
+       typedef std::map<string, docstring> 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