Read the right .gmo files when running in place

With gettext, we have been forced to install .mo files at the right place in order to read them. Now that we have our code, the situation changes.

* Add new method Package::messages_file(code), when returns the right path, depending on whether we are running in place.
* In Messages class use that intead of the existing one.
This commit is contained in:
Jean-Marc Lasgouttes 2013-05-14 16:35:34 +02:00 committed by Vincent van Ravesteijn
parent a3c864102a
commit 149b574b07
4 changed files with 33 additions and 23 deletions

View File

@ -90,11 +90,13 @@ Run ./pocheck.pl -h to see all possible switches.
6) HOW CAN I TEST MY TRANSLATION?
In order to test your translation you need to obtain the LyX sources (from the
SVN repository) and replace the existing .po with yours. Afterwards, you should
compile and install LyX (check the INSTALL file for your OS). If you don't
install LyX it won't work. In order to run LyX with your translation, use the
appropriate LANG variable:
In order to test your translation you need to obtain the LyX sources
(from the git repository) and replace the existing .po with yours.
Afterwards, you should compile and optionally install LyX (check the
INSTALL file for your OS). Note that, as of LyX 2.1, it is not
necessary anymore to install anything. In order to run LyX with your
translation, change the current language in Preferences dialog or use
the appropriate LANG variable:
On Linux: LANG=xx_CC lyx
On Windows, you need to change the lyx.bat file and write: set LANG=xx_CC
@ -102,11 +104,9 @@ appropriate LANG variable:
xx stands for your language code. CC stands for your country code. So to get,
e.g., Czech, the code is "cs_CZ".
The most comfortable way to see your updated translation while editing, is
running (in linux):
1. "make xx.gmo" in the po directory to compile updated xx.po translation
2. "make install" in root lyx tree to copy xx.gmo to the appropriate location
(or do it by hand...)
The most comfortable way to see your updated translation while
editing, is running (in linux) "make xx.gmo" in the po directory to
compile updated xx.po translation and then run LyX.
For advanced users - if you want to remerge your files against current source
files run make update-po.

View File

@ -155,15 +155,6 @@ Messages::Messages(string const & l)
namespace {
string moFile(string const & c)
{
static string const locale_dir
= package().locale_dir().toFilesystemEncoding();
return locale_dir + "/" + c
+ "/LC_MESSAGES/" PACKAGE ".mo";
}
// Find the code we have for a given language code. Return empty if not found.
string realCode(string const & c)
{
@ -171,7 +162,7 @@ string realCode(string const & c)
string code = (c == "C") ? "en" : c;
// this loops at most twice
while (true) {
if (FileName(moFile(code)).isReadableFile())
if (package().messages_file(code).isReadableFile())
return code;
if (contains(code, '_'))
code = token(code, '_', 0);
@ -234,7 +225,7 @@ bool Messages::readMoFile()
return false;
}
string const filen = moFile(code);
string const filen = package().messages_file(code).toSafeFilesystemEncoding();
// get file size
struct stat buf;

View File

@ -119,9 +119,9 @@ Package::Package(string const & command_line_arg0,
lyx_dir_ = FileName(lyx_dir_.realPath());
// Is LyX being run in-place from the build tree?
bool in_build_dir = inBuildDir(abs_binary, build_support_dir_, system_support_dir_);
in_build_dir_ = inBuildDir(abs_binary, build_support_dir_, system_support_dir_);
if (!in_build_dir) {
if (!in_build_dir_) {
system_support_dir_ =
get_system_support_dir(abs_binary,
command_line_system_support_dir);
@ -164,6 +164,18 @@ void Package::set_temp_dir(FileName const & temp_dir) const
temp_dir_ = temp_dir;
}
FileName Package::messages_file(string const & c) const
{
if (in_build_dir_)
return FileName(top_srcdir().absFileName() + "/po/"
+ c + ".gmo");
else
return FileName(locale_dir_.absFileName() + "/" + c
+ "/LC_MESSAGES/" PACKAGE ".mo");
}
// The specification of home_dir_ is fixed for a given OS.
// A typical example on Windows: "C:/Documents and Settings/USERNAME"
// and on a Posix-like machine: "/home/USERNAME".

View File

@ -101,6 +101,12 @@ public:
*/
FileName const & locale_dir() const { return locale_dir_; }
/** The file name that should contain the message file (.mo)
* for language code \param c. Does not check whether the
* file exists. Handles running in place.
*/
FileName messages_file(std::string const & c) const;
/** The default document directory.
* Can be reset by LyXRC.
*/
@ -147,6 +153,7 @@ private:
FileName system_temp_dir_;
std::string configure_command_;
bool explicit_user_support_dir_;
bool in_build_dir_;
};
} // namespace support