mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
Rework language package detection
This puts the diverse use[LangPack] function into one (less error-prone) function and differentiates the custom package from the babel case
This commit is contained in:
parent
508dd27e44
commit
6c1326cdeb
@ -1923,6 +1923,15 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
|
||||
}
|
||||
}
|
||||
|
||||
// Load custom language package here
|
||||
if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
|
||||
if (lang_package == "default")
|
||||
lyxpreamble += from_utf8(lyxrc.language_custom_package);
|
||||
else
|
||||
lyxpreamble += from_utf8(lang_package);
|
||||
lyxpreamble += '\n';
|
||||
}
|
||||
|
||||
docstring const i18npreamble =
|
||||
features.getTClassI18nPreamble(use_babel, use_polyglossia);
|
||||
if (!i18npreamble.empty())
|
||||
@ -2645,12 +2654,6 @@ string const BufferParams::font_encoding() const
|
||||
|
||||
string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
|
||||
{
|
||||
if (lang_package != "auto" && lang_package != "babel"
|
||||
&& lang_package != "default" && lang_package != "none")
|
||||
return lang_package;
|
||||
if (lang_package == "default"
|
||||
&& lyxrc.language_package_selection == LyXRC::LP_CUSTOM)
|
||||
return lyxrc.language_custom_package;
|
||||
// suppress the babel call if there is no BabelName defined
|
||||
// for the document language in the lib/languages file and if no
|
||||
// other languages are used (lang_opts is then empty)
|
||||
|
@ -290,33 +290,69 @@ LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
|
||||
{}
|
||||
|
||||
|
||||
bool LaTeXFeatures::useBabel() const
|
||||
LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
|
||||
{
|
||||
if (usePolyglossia()
|
||||
|| bufferParams().lang_package == "none"
|
||||
|| (bufferParams().lang_package == "default"
|
||||
&& lyxrc.language_package_selection == LyXRC::LP_NONE))
|
||||
return false;
|
||||
string const local_lp = bufferParams().lang_package;
|
||||
|
||||
return (bufferParams().language->lang() != lyxrc.default_language
|
||||
&& !bufferParams().language->babel().empty())
|
||||
|| this->hasLanguages();
|
||||
}
|
||||
// Locally, custom is just stored as a string
|
||||
// in bufferParams().lang_package.
|
||||
if (local_lp != "auto"
|
||||
&& local_lp != "babel"
|
||||
&& local_lp != "default"
|
||||
&& local_lp != "none")
|
||||
return LANG_PACK_CUSTOM;
|
||||
|
||||
if (local_lp == "none")
|
||||
return LANG_PACK_NONE;
|
||||
|
||||
bool LaTeXFeatures::usePolyglossia() const
|
||||
{
|
||||
if (bufferParams().lang_package == "default")
|
||||
return (lyxrc.language_package_selection == LyXRC::LP_AUTO)
|
||||
&& isRequired("polyglossia")
|
||||
&& isAvailable("polyglossia")
|
||||
&& !params_.documentClass().provides("babel")
|
||||
&& this->hasOnlyPolyglossiaLanguages();
|
||||
return (bufferParams().lang_package == "auto")
|
||||
&& isRequired("polyglossia")
|
||||
/* If "auto" is selected, we load polyglossia if required,
|
||||
* else we select babel.
|
||||
* If babel is selected (either directly or via the "auto"
|
||||
* mechanism), we really do only require it if we have
|
||||
* a language that needs it.
|
||||
*/
|
||||
bool const polyglossia_required =
|
||||
isRequired("polyglossia")
|
||||
&& isAvailable("polyglossia")
|
||||
&& !params_.documentClass().provides("babel")
|
||||
&& this->hasOnlyPolyglossiaLanguages();
|
||||
bool const babel_required =
|
||||
(bufferParams().language->lang() != lyxrc.default_language
|
||||
&& !bufferParams().language->babel().empty())
|
||||
|| !this->getBabelLanguages().empty();
|
||||
|
||||
if (local_lp == "auto") {
|
||||
// polyglossia requirement has priority over babel
|
||||
if (polyglossia_required)
|
||||
return LANG_PACK_POLYGLOSSIA;
|
||||
else if (babel_required)
|
||||
return LANG_PACK_BABEL;
|
||||
}
|
||||
|
||||
if (local_lp == "babel") {
|
||||
if (babel_required)
|
||||
return LANG_PACK_BABEL;
|
||||
}
|
||||
|
||||
if (local_lp == "default") {
|
||||
switch (lyxrc.language_package_selection) {
|
||||
case LyXRC::LP_AUTO:
|
||||
// polyglossia requirement has priority over babel
|
||||
if (polyglossia_required)
|
||||
return LANG_PACK_POLYGLOSSIA;
|
||||
else if (babel_required)
|
||||
return LANG_PACK_BABEL;
|
||||
case LyXRC::LP_BABEL:
|
||||
if (babel_required)
|
||||
return LANG_PACK_BABEL;
|
||||
case LyXRC::LP_CUSTOM:
|
||||
return LANG_PACK_CUSTOM;
|
||||
case LyXRC::LP_NONE:
|
||||
return LANG_PACK_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
return LANG_PACK_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,6 +43,13 @@ class Language;
|
||||
*/
|
||||
class LaTeXFeatures {
|
||||
public:
|
||||
/// Which Language package do we use?
|
||||
enum LangPackage {
|
||||
LANG_PACK_NONE,
|
||||
LANG_PACK_BABEL,
|
||||
LANG_PACK_POLYGLOSSIA,
|
||||
LANG_PACK_CUSTOM
|
||||
};
|
||||
///
|
||||
LaTeXFeatures(Buffer const &, BufferParams const &,
|
||||
OutputParams const &);
|
||||
@ -125,10 +132,12 @@ public:
|
||||
void setBuffer(Buffer const &);
|
||||
///
|
||||
BufferParams const & bufferParams() const;
|
||||
/// the return value is dependent upon both LyXRC and LaTeXFeatures.
|
||||
bool useBabel() const;
|
||||
///
|
||||
bool usePolyglossia() const;
|
||||
/// Which language package do we need?
|
||||
LangPackage langPackage() const;
|
||||
/// Convenience function to test if we use babel
|
||||
bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
|
||||
/// Convenience function to test if we use polyglossia
|
||||
bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
|
||||
/// are we in a float?
|
||||
bool inFloat() const { return in_float_; }
|
||||
/// are we in a float?
|
||||
|
Loading…
Reference in New Issue
Block a user