mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Second Locale patch.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10275 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9745fb8187
commit
baa6723a40
@ -23,6 +23,7 @@
|
||||
|
||||
#include <map>
|
||||
#include "support/lstrings.h"
|
||||
#include "support/environment.h"
|
||||
#include "encoding.h"
|
||||
#include "language.h"
|
||||
|
||||
@ -30,6 +31,7 @@ using std::endl;
|
||||
using std::string;
|
||||
using std::map;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::getEnv;
|
||||
|
||||
|
||||
namespace {
|
||||
@ -70,9 +72,21 @@ char const encode(string const & encoding, QString const & str)
|
||||
|
||||
void initEncodings()
|
||||
{
|
||||
const char * c = QTextCodec::locale();
|
||||
string s = c;
|
||||
if (contains(c, "UTF") || contains(c, "utf"))
|
||||
//const char * c = QTextCodec::locale();
|
||||
//string s = c ? c : "";
|
||||
// In this order, see support/filetools.C
|
||||
string s = getEnv("LC_ALL");
|
||||
if (s.empty()) {
|
||||
s = getEnv("LC_MESSAGES");
|
||||
if (s.empty()) {
|
||||
s = getEnv("LANG");
|
||||
if (s.empty())
|
||||
s = "C";
|
||||
}
|
||||
}
|
||||
|
||||
if (s.find("UTF") != string::npos || s.find("utf") != string::npos)
|
||||
//if (contains(c, "UTF") || contains(c, "utf"))
|
||||
lyxerr << "Warning: this system's locale uses Unicode." << endl;
|
||||
|
||||
// strip off any encoding suffix
|
||||
@ -101,8 +115,9 @@ void initEncodings()
|
||||
|
||||
// when no document open
|
||||
// use the appropriate encoding for the system language
|
||||
lyxerr << "Language code:" << s << endl;
|
||||
for (Languages::const_iterator it=languages.begin(); it != languages.end(); ++it) {
|
||||
lyxerr << it->second.code() << ":" << it->second.encodingStr() << ":" << it->second.encoding() << endl;
|
||||
//lyxerr << it->second.code() << ":" << it->second.encodingStr() << ":" << it->second.encoding() << endl;
|
||||
if (it->second.code() == s)
|
||||
{
|
||||
s = it->second.encodingStr();
|
||||
|
@ -13,13 +13,14 @@
|
||||
|
||||
#include "gettext.h"
|
||||
#include "messages.h"
|
||||
|
||||
#include "support/environment.h"
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
using lyx::support::setEnv;
|
||||
|
||||
|
||||
namespace {
|
||||
@ -44,6 +45,8 @@ string const _(string const & str)
|
||||
|
||||
void locale_init()
|
||||
{
|
||||
// Disable, as otherwise it overrides everything else incl. the doc language
|
||||
setEnv("LANGUAGE", "");
|
||||
# ifdef HAVE_LC_MESSAGES
|
||||
setlocale(LC_MESSAGES, "");
|
||||
# endif
|
||||
|
@ -12,11 +12,14 @@
|
||||
#include "debug.h"
|
||||
#include "messages.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/environment.h"
|
||||
#include "support/package.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
using lyx::support::package;
|
||||
using lyx::support::getEnv;
|
||||
using lyx::support::setEnv;
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -85,10 +88,10 @@ public:
|
||||
{
|
||||
if ( lang_.empty() )
|
||||
lang_ = setlocale(LC_MESSAGES, NULL);
|
||||
lyxerr << "Messages: language(" << lang_
|
||||
// << ") in dir(" << dir
|
||||
<< ")" << std::endl;
|
||||
|
||||
// strip off any encoding suffix, i.e., assume 8-bit po files
|
||||
string::size_type i = lang_.find(".");
|
||||
lang_ = lang_.substr(0, i);
|
||||
lyxerr << "Messages: language(" << lang_ << ")" << std::endl;
|
||||
}
|
||||
|
||||
~Pimpl() {}
|
||||
@ -98,12 +101,31 @@ public:
|
||||
if (m.empty())
|
||||
return m;
|
||||
|
||||
string oldMSG = setlocale(LC_MESSAGES, NULL);
|
||||
bool works = setlocale(LC_MESSAGES, lang_.c_str());
|
||||
//string oldMSG = setlocale(LC_MESSAGES, NULL);
|
||||
// In this order, see support/filetools.C:
|
||||
string lang = getEnv("LC_ALL");
|
||||
if (lang.empty()) {
|
||||
lang = getEnv("LC_MESSAGES");
|
||||
if (lang.empty()) {
|
||||
lang = getEnv("LANG");
|
||||
if (lang.empty())
|
||||
lang = "C";
|
||||
}
|
||||
}
|
||||
|
||||
char const * works = setlocale(LC_MESSAGES, lang_.c_str());
|
||||
// CTYPE controls what getmessage thinks what encoding the po file uses
|
||||
string oldCTYPE = setlocale(LC_CTYPE, NULL);
|
||||
setlocale(LC_CTYPE, lang_.c_str());
|
||||
bindtextdomain(PACKAGE, package().locale_dir().c_str());
|
||||
errno = 0;
|
||||
char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
|
||||
int e = errno;
|
||||
if (e) {
|
||||
lyxerr << "Error code: " << errno << std::endl;
|
||||
lyxerr << "Lang, mess: " << lang_ << " " << m << std::endl;
|
||||
lyxerr << "Directory: " << package().locale_dir() << std::endl;
|
||||
lyxerr << "Rtn value: " << c << std::endl;
|
||||
}
|
||||
textdomain(PACKAGE);
|
||||
const char* msg = gettext(m.c_str());
|
||||
string translated(works ? msg : m);
|
||||
@ -121,7 +143,7 @@ public:
|
||||
boost::smatch sub;
|
||||
if (regex_match(translated, sub, reg))
|
||||
translated = sub.str(1);
|
||||
setlocale(LC_MESSAGES, oldMSG.c_str());
|
||||
setlocale(LC_MESSAGES, lang.c_str());
|
||||
setlocale(LC_CTYPE, oldCTYPE.c_str());
|
||||
return translated;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user