The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit ed1515ef69d0381e9b0657cf1966f9d86e0cb25f
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Thu Jul 19 00:02:56 2012 +0200

    Read list of translated languages from a file
    
    The previous scheme of loading all possible translations and checking 
whether the work
    is a bit too much "brute force" and causes problems on Mac OS X (documents 
loaded
    with the wrong language).
    
    In the new scheme, autotools install a file lib/installed_translations that 
contains a list of installed languages (the .gmo files that got installed). 
This file is read
    in Languages::readInstalledTranslations and allows to set the translated() 
property
    of each language.

diff --git a/configure.ac b/configure.ac
index acfa663..71a4b1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,6 +180,10 @@ m4_defun([AC_GNU_SOURCE],[])
 AM_GNU_GETTEXT([no-libtool])
 AM_GNU_GETTEXT_VERSION([0.16.1])
 AC_LANG_POP(C)
+AC_CONFIG_COMMANDS([lib/installed_translation], [
+  rm -f lib/installed_translations
+  echo $CATALOGS | sed 's/\.gmo//g' > lib/installed_translations
+])
 
 # some standard header files
 AC_HEADER_MAJOR
@@ -371,7 +375,7 @@ AC_CONFIG_FILES([Makefile \
       development/cygwin/lyxrc.dist \
       development/lyx.spec \
       intl/Makefile \
-      lib/lyx.desktop-temp:lib/lyx.desktop.in
+      lib/lyx.desktop-temp:lib/lyx.desktop.in \
       lib/Makefile \
       lib/doc/Makefile \
       lib/lyx2lyx/lyx2lyx_version.py \
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8ac88f1..2111dfb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,6 +8,8 @@ dist_pkgdata_DATA = CREDITS autocorrect chkconfig.ltx 
external_templates \
        encodings layouttranslations languages symbols syntax.default \
        unicodesymbols
 
+nodist_pkgdata_DATA = installed_translations
+
 # We use DATA now instead of PYTHON because automake 1.11.2 complains.
 # Note that we "chmod 755" manually this file in install-data-hook.
 dist_pkgdata_DATA += configure.py 
diff --git a/src/Language.cpp b/src/Language.cpp
index 8c891fb..9f8c57e 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -196,10 +196,6 @@ bool Language::read(Lexer & lex)
                encoding_ = encodings.fromLyXName("iso8859-1");
                LYXERR0("Unknown encoding " << encodingStr_);
        }
-       // cache translation status. Calling getMessages() directly in
-       // PrefLanguage::PrefLanguage() did only work if the gui language
-       // was set to auto (otherwise all languages would be marked as 
available).
-       translated_ = getMessages(code()).available();
        return true;
 }
 
@@ -262,8 +258,12 @@ void Languages::read(FileName const & filename)
        }
 
        // Read layout translations
-       FileName const path = libFileSearch(string(), "layouttranslations");
+       FileName path = libFileSearch(string(), "layouttranslations");
        readLayoutTranslations(path);
+
+       // Read installed translations
+       path = libFileSearch(string(), "installed_translations");
+       readInstalledTranslations(path);
 }
 
 
@@ -372,6 +372,32 @@ void Languages::readLayoutTranslations(support::FileName 
const & filename)
 }
 
 
+void Languages::readInstalledTranslations(support::FileName const & filename)
+{
+       Lexer lex;
+       lex.setFile(filename);
+       lex.setContext("Languages::read");
+
+       // 1) read all installed gmo files names
+       set<string> installed_translations;
+       string lang_code;
+       while (lex.isOK()) {
+               lex >> lang_code;
+               installed_translations.insert(lang_code);
+       }
+
+       // 2) mark all corresponding languages as translated.
+       LanguageList::iterator lit = languagelist.begin();
+       LanguageList::iterator const lend = languagelist.end();
+       for ( ; lit != lend ; ++lit) {
+               if (installed_translations.count(lit->second.code())
+                   || installed_translations.count(token(lit->second.code(), 
'_', 0)))
+                       lit->second.translated(true);
+       }
+
+}
+
+
 Language const * Languages::getLanguage(string const & language) const
 {
        if (language == "reset")
diff --git a/src/Language.h b/src/Language.h
index 71b6777..fb1158b 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -50,6 +50,8 @@ public:
        bool rightToLeft() const { return rightToLeft_; }
        /// Is an (at least partial) translation of this language available?
        bool translated() const { return translated_; }
+       /// Is an (at least partial) translation of this language available?
+       void translated(bool trans) { translated_ = trans; }
        /**
         * Translate a string from the layout files that appears in the output.
         * It takes the translations from lib/layouttranslations instead of
@@ -147,6 +149,8 @@ public:
        ///
        void readLayoutTranslations(support::FileName const & filename);
        ///
+       void readInstalledTranslations(support::FileName const & filename);
+       ///
        Language const * getLanguage(std::string const & language) const;
        ///
        size_type size() const { return languagelist.size(); }

-----------------------------------------------------------------------

Summary of changes:
 configure.ac     |    6 +++++-
 lib/Makefile.am  |    2 ++
 src/Language.cpp |   36 +++++++++++++++++++++++++++++++-----
 src/Language.h   |    4 ++++
 4 files changed, 42 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to