commit 07c82e9f840afbf9b1b391e4de2312284c6cfd4d
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Oct 27 09:59:01 2016 +0200

    Issue an error message if conflicting languages are used
    
    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        |   41 +++++++++++++++++++++++++++++++++++++++++
 src/LaTeXFeatures.cpp |   36 ++++++++++++++++++++++++++++++++++++
 src/LaTeXFeatures.h   |    4 ++++
 src/Language.cpp      |    6 ++++++
 src/Language.h        |    2 ++
 5 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index df3ae9f..f2dbb88 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1874,6 +1874,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.
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 0650da1..78e31eb 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -736,6 +736,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;
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index b136f86..9fbc134 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -124,6 +124,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;
        ///
diff --git a/src/Language.cpp b/src/Language.cpp
index 9801668..902eab3 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -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())
diff --git a/src/Language.h b/src/Language.h
index c26a77d..594a324 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -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)

Reply via email to