+
+bool Language::isBabelExclusive() const
+{
+ return !babel().empty() && polyglossia().empty() && requires().empty();
+}
+
+
+docstring const Language::translateLayout(string const & m) const
+{
+ if (m.empty())
+ return docstring();
+
+ if (!isAscii(m)) {
+ lyxerr << "Warning: not translating `" << m
+ << "' because it is not pure ASCII.\n";
+ return from_utf8(m);
+ }
+
+ TranslationMap::const_iterator it = layoutTranslations_.find(m);
+ if (it != layoutTranslations_.end())
+ return it->second;
+
+ docstring t = from_ascii(m);
+ cleanTranslation(t);
+ return t;
+}
+
+
+string Language::fontenc(BufferParams const & params) const
+{
+ // Don't use LaTeX fonts, so just return the language's preferred
+ // (although this is not used with nonTeXFonts anyway).
+ if (params.useNonTeXFonts)
+ return fontenc_.front() == "ASCII" ? "T1" : fontenc_.front();
+
+ // Determine optimal font encoding
+ // We check whether the used rm font supports an encoding our language supports
+ LaTeXFont const & lf =
+ theLaTeXFonts().getLaTeXFont(from_ascii(params.fontsRoman()));
+ vector<string> const lfe = lf.fontencs();
+ for (auto & fe : fontenc_) {
+ // ASCII means: support all T* encodings plus OT1
+ if (fe == "ASCII") {
+ for (auto & afe : lfe) {
+ if (afe == "OT1" || prefixIs(afe, "T"))
+ // we found a suitable one; return that.
+ return afe;
+ }
+ }
+ // For other encodings, just check whether the font supports it
+ if (lf.hasFontenc(fe))
+ return fe;
+ }
+ // We did not find a suitable one; just take the first in the list,
+ // the priorized one (which is "T1" for ASCII).
+ return fontenc_.front() == "ASCII" ? "T1" : fontenc_.front();
+}
+
+
+string Language::dateFormat(size_t i) const
+{
+ if (i > dateformats_.size())
+ return string();
+ return dateformats_.at(i);
+}
+
+
+bool Language::readLanguage(Lexer & lex)
+{
+ enum LanguageTags {
+ LA_BABELNAME = 1,
+ LA_DATEFORMATS,
+ LA_ENCODING,
+ LA_END,
+ LA_FONTENC,
+ LA_GUINAME,
+ LA_HAS_GUI_SUPPORT,
+ LA_INTERNAL_ENC,
+ LA_LANG_CODE,
+ LA_LANG_VARIETY,
+ LA_POLYGLOSSIANAME,
+ LA_POLYGLOSSIAOPTS,
+ LA_POSTBABELPREAMBLE,
+ LA_PREBABELPREAMBLE,
+ LA_PROVIDES,
+ LA_REQUIRES,
+ LA_QUOTESTYLE,
+ LA_RTL
+ };
+
+ // Keep these sorted alphabetically!
+ LexerKeyword languageTags[] = {
+ { "babelname", LA_BABELNAME },
+ { "dateformats", LA_DATEFORMATS },
+ { "encoding", LA_ENCODING },
+ { "end", LA_END },
+ { "fontencoding", LA_FONTENC },
+ { "guiname", LA_GUINAME },
+ { "hasguisupport", LA_HAS_GUI_SUPPORT },
+ { "internalencoding", LA_INTERNAL_ENC },
+ { "langcode", LA_LANG_CODE },
+ { "langvariety", LA_LANG_VARIETY },
+ { "polyglossianame", LA_POLYGLOSSIANAME },
+ { "polyglossiaopts", LA_POLYGLOSSIAOPTS },
+ { "postbabelpreamble", LA_POSTBABELPREAMBLE },
+ { "prebabelpreamble", LA_PREBABELPREAMBLE },
+ { "provides", LA_PROVIDES },
+ { "quotestyle", LA_QUOTESTYLE },
+ { "requires", LA_REQUIRES },
+ { "rtl", LA_RTL }
+ };
+
+ bool error = false;
+ bool finished = false;
+ lex.pushTable(languageTags);
+ // parse style section
+ while (!finished && lex.isOK() && !error) {
+ int le = lex.lex();
+ // See comment in LyXRC.cpp.
+ switch (le) {
+ case Lexer::LEX_FEOF:
+ continue;
+
+ case Lexer::LEX_UNDEF: // parse error
+ lex.printError("Unknown language tag `$$Token'");
+ error = true;
+ continue;
+
+ default:
+ break;
+ }
+ switch (static_cast<LanguageTags>(le)) {
+ case LA_END: // end of structure
+ finished = true;
+ break;
+ case LA_BABELNAME:
+ lex >> babel_;
+ break;
+ case LA_POLYGLOSSIANAME:
+ lex >> polyglossia_name_;
+ break;
+ case LA_POLYGLOSSIAOPTS:
+ lex >> polyglossia_opts_;
+ break;
+ case LA_QUOTESTYLE:
+ lex >> quote_style_;
+ break;
+ case LA_ENCODING:
+ lex >> encodingStr_;
+ break;
+ case LA_FONTENC: {
+ lex.eatLine();
+ vector<string> const fe =
+ getVectorFromString(lex.getString(true), "|");
+ fontenc_.insert(fontenc_.end(), fe.begin(), fe.end());
+ break;
+ }
+ case LA_DATEFORMATS: {
+ lex.eatLine();
+ vector<string> const df =
+ getVectorFromString(trim(lex.getString(true), "\""), "|");
+ dateformats_.insert(dateformats_.end(), df.begin(), df.end());
+ break;
+ }
+ case LA_GUINAME:
+ lex >> display_;
+ break;
+ case LA_HAS_GUI_SUPPORT:
+ lex >> has_gui_support_;
+ break;
+ case LA_INTERNAL_ENC:
+ lex >> internal_enc_;
+ break;
+ case LA_LANG_CODE:
+ lex >> code_;
+ break;
+ case LA_LANG_VARIETY:
+ lex >> variety_;
+ break;
+ case LA_POSTBABELPREAMBLE:
+ babel_postsettings_ =
+ lex.getLongString(from_ascii("EndPostBabelPreamble"));
+ break;
+ case LA_PREBABELPREAMBLE:
+ babel_presettings_ =
+ lex.getLongString(from_ascii("EndPreBabelPreamble"));
+ break;
+ case LA_REQUIRES:
+ lex >> requires_;
+ break;
+ case LA_PROVIDES:
+ lex >> provides_;
+ break;
+ case LA_RTL:
+ lex >> rightToLeft_;
+ break;
+ }
+ }
+ lex.popTable();
+ return finished && !error;
+}