]> git.lyx.org Git - lyx.git/commitdiff
Read the right .gmo files when running in place
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 14 May 2013 14:35:34 +0000 (16:35 +0200)
committerVincent van Ravesteijn <vfr@lyx.org>
Thu, 30 May 2013 20:10:01 +0000 (22:10 +0200)
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.

README.localization
src/support/Messages.cpp
src/support/Package.cpp
src/support/Package.h

index 2f77eec4307d7915ae81c6412d18b0203b20ea36..081fff7a8cab0092e6b8062981182f6769e512c7 100644 (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. 
index 0ce9d552a10663cf6f5a5af7471db01d74b4aa90..ca41d6a13dbcacd5046c80227044fc0a6614fac9 100644 (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;
index 845553f4b8e09aef2a75acfafc3a490a92517aa9..24cf8ca96bfdc02c29a3a4e60d1594ac1d4b87d9 100644 (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".
index d6e76fb56b99aa892a6edb0bfafb37a443a9af4a..064f662e4e37577d2a1da284818bb3a2c67d3e86 100644 (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