]> git.lyx.org Git - features.git/commitdiff
Issue an error message if conflicting languages are used
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 27 Oct 2016 07:59:01 +0000 (09:59 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 31 Oct 2016 09:26:35 +0000 (10:26 +0100)
Some languages are only supported by Babel, some only by Polyglossia.

If these are combined, we issue an error message now.

Fixes: #10456
src/Buffer.cpp
src/LaTeXFeatures.cpp
src/LaTeXFeatures.h
src/Language.cpp
src/Language.h
status.22x

index 2f06f18e376f52cb1b3b7c97d21567ebed5911e6..4d3088458f8868cb7ff393a3bc0f697652d4b40f 100644 (file)
@@ -1876,6 +1876,47 @@ void Buffer::writeLaTeXSource(otexstream & os,
                // Write the preamble
                runparams.use_babel = params().writeLaTeX(os, features,
                                                          d->filename.onlyPath());
+               
+               if (!runparams.dryrun && features.hasPolyglossiaExclusiveLanguages()
+                   && !features.hasOnlyPolyglossiaLanguages()) {
+                       docstring blangs;
+                       docstring plangs;
+                       vector<string> bll = features.getBabelExclusiveLanguages();
+                       vector<string> pll = features.getPolyglossiaExclusiveLanguages();
+                       if (!bll.empty()) {
+                               docstring langs;
+                               for (vector<string>::const_iterator it = bll.begin(); it != bll.end(); ++it) {
+                                       if (!langs.empty())
+                                               langs += ", ";
+                                       langs += _(*it);
+                               }
+                               blangs = bll.size() > 1 ?
+                                           support::bformat(_("The languages %1$s are only supported by Babel."), langs)
+                                         : support::bformat(_("The language %1$s is only supported by Babel."), langs);
+                       }
+                       if (!pll.empty()) {
+                               docstring langs;
+                               for (vector<string>::const_iterator it = pll.begin(); it != pll.end(); ++it) {
+                                       if (!langs.empty())
+                                               langs += ", ";
+                                       langs += _(*it);
+                               }
+                               plangs = pll.size() > 1 ?
+                                           support::bformat(_("The languages %1$s are only supported by Polyglossia."), langs)
+                                         : support::bformat(_("The language %1$s is only supported by Polyglossia."), langs);
+                               if (!blangs.empty())
+                                       plangs += "\n"; 
+                       }
+
+                       frontend::Alert::warning(
+                               _("Incompatible Languages!"),
+                               support::bformat(
+                                 _("You cannot use the following languages "
+                                   "together in one LaTeX document because "
+                                   "they require conflicting language packages:\n"
+                                   "%1$s%2$s"),
+                                 plangs, blangs));
+               }
 
                // Japanese might be required only in some children of a document,
                // but once required, we must keep use_japanese true.
index db2aa74cb765067014f9ccbb4339386a4883afdc..96f0ced7e8a5559f8d2b4ccdf76d15d60b7663e7 100644 (file)
@@ -683,6 +683,42 @@ bool LaTeXFeatures::hasPolyglossiaExclusiveLanguages() const
 }
 
 
+vector<string> LaTeXFeatures::getPolyglossiaExclusiveLanguages() const
+{
+       vector<string> result;
+       // first the main language
+       if (params_.language->isPolyglossiaExclusive())
+               result.push_back(params_.language->display());
+       // now the secondary languages
+       LanguageList::const_iterator const begin = UsedLanguages_.begin();
+       for (LanguageList::const_iterator cit = begin;
+            cit != UsedLanguages_.end();
+            ++cit) {
+               if ((*cit)->isPolyglossiaExclusive())
+                       result.push_back((*cit)->display());
+       }
+       return result;
+}
+
+
+vector<string> LaTeXFeatures::getBabelExclusiveLanguages() const
+{
+       vector<string> result;
+       // first the main language
+       if (params_.language->isBabelExclusive())
+               result.push_back(params_.language->display());
+       // now the secondary languages
+       LanguageList::const_iterator const begin = UsedLanguages_.begin();
+       for (LanguageList::const_iterator cit = begin;
+            cit != UsedLanguages_.end();
+            ++cit) {
+               if ((*cit)->isBabelExclusive())
+                       result.push_back((*cit)->display());
+       }
+       return result;
+}
+
+
 string LaTeXFeatures::getBabelLanguages() const
 {
        ostringstream languages;
index 38273e4fa2f85c42b5c57a80decb9ecac7867f3b..6c3e888b48d6cfa6bf232aad5be11b0e81028df1 100644 (file)
@@ -122,6 +122,10 @@ public:
        bool hasOnlyPolyglossiaLanguages() const;
        /// check if a language is supported only by polyglossia
        bool hasPolyglossiaExclusiveLanguages() const;
+       /// A vector of all used languages supported only by polyglossia
+       std::vector<std::string> getPolyglossiaExclusiveLanguages() const;
+       /// A vector of all used languages supported only by babel
+       std::vector<std::string> getBabelExclusiveLanguages() const;
        ///
        std::string getBabelLanguages() const;
        ///
index dc38bfcf242fb8d50a208a0037a813339faf4ac5..760d7a1ba7650dd777886415cb22e9d1d871d34c 100644 (file)
@@ -44,6 +44,12 @@ bool Language::isPolyglossiaExclusive() const
 }
 
 
+bool Language::isBabelExclusive() const
+{
+       return !babel().empty() && polyglossia().empty() && requires().empty();
+}
+
+
 docstring const Language::translateLayout(string const & m) const
 {
        if (m.empty())
index ed1bd8715efe385cd397d8273fd70b0cb8d91eda..55f4b76f213fa077b758cb589a5f40fa4afc3611 100644 (file)
@@ -44,6 +44,8 @@ public:
        std::string const polyglossiaOpts() const { return polyglossia_opts_; }
        /// Is this language only supported by polyglossia?
        bool isPolyglossiaExclusive() const;
+       /// Is this language only supported by babel?
+       bool isBabelExclusive() const;
        /// quotation marks style
        std::string const quoteStyle() const { return quote_style_; }
        /// requirement (package, function)
index 0a10e6ae285cd34d7a391a07bb4d4a69bdf34e0b..29a63088bb000012069a2a55a50b37b107fb8f80 100644 (file)
@@ -47,6 +47,9 @@ What's new
 - When using Return in an empty paragraph and the depth is reduced,
   the layout of the paragraph is now changed accordingly.
 
+- Issue an error message if incompatible languages (in terms of language package
+  requirements) are used (bug 10456).
+
 
 * DOCUMENTATION AND LOCALIZATION