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.
This commit is contained in:
Jean-Marc Lasgouttes 2012-07-19 00:02:56 +02:00
parent 08b3d492fa
commit ed1515ef69
4 changed files with 42 additions and 6 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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")

View File

@ -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(); }