Messages:

- cache_: new cache for gettext translated string.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16662 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-01-13 09:31:47 +00:00
parent b65a2f2b7b
commit d0515ddc43
2 changed files with 22 additions and 8 deletions

View File

@ -21,7 +21,10 @@
#include <boost/regex.hpp>
#include <cerrno>
#include <map>
using std::endl;
using std::string;
namespace lyx {
@ -29,9 +32,6 @@ using support::package;
using support::getEnv;
using support::setEnv;
using std::string;
using std::endl;
static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
@ -114,10 +114,17 @@ public:
~Pimpl() {}
docstring const get(string const & m) const
docstring const & get(string const & m) const
{
static docstring empty_string;
if (m.empty())
return from_ascii(m);
return empty_string;
// Look for the translated string in the cache.
CacheType::iterator it = cache_.find(m);
if (it != cache_.end())
return it->second;
// The string was not found, use gettext to generate it:
// In this order, see support/filetools.C:
string lang = getEnv("LC_ALL");
@ -206,11 +213,18 @@ public:
setlocale(LC_MESSAGES, lang.c_str());
#endif
setlocale(LC_CTYPE, oldCTYPE.c_str());
return translated;
it = cache_.insert(std::make_pair(m, translated)).first;
return it->second;
}
private:
///
string lang_;
typedef std::map<string, docstring> CacheType;
/// Internal cache for gettext translated strings.
/// This is needed for performance reason within \c updateLabels()
/// under Windows.
mutable CacheType cache_;
};
#endif
@ -250,7 +264,7 @@ Messages::~Messages()
{}
docstring const Messages::get(string const & msg) const
docstring const & Messages::get(string const & msg) const
{
return pimpl_->get(msg);
}

View File

@ -29,7 +29,7 @@ public:
///
~Messages();
///
docstring const get(std::string const & msg) const;
docstring const & get(std::string const & msg) const;
private:
class Pimpl;
boost::scoped_ptr<Pimpl> pimpl_;