#include "Language.h"
#include "Encoding.h"
+#include "LaTeXFonts.h"
#include "Lexer.h"
#include "LyXRC.h"
Language const * reset_language = 0;
+bool Language::isPolyglossiaExclusive() const
+{
+ return babel().empty() && !polyglossia().empty() && requires().empty();
+}
+
+
+bool Language::isBabelExclusive() const
+{
+ return !babel().empty() && polyglossia().empty() && requires().empty();
+}
+
+
docstring const Language::translateLayout(string const & m) const
{
if (m.empty())
}
+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_AS_BABELOPTS = 1,
LA_BABELNAME,
+ 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_QUOTESTYLE,
LA_PREBABELPREAMBLE,
+ LA_PROVIDES,
LA_REQUIRES,
+ LA_QUOTESTYLE,
LA_RTL
};
LexerKeyword languageTags[] = {
{ "asbabeloptions", LA_AS_BABELOPTS },
{ "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 },
{ "polyglossiaopts", LA_POLYGLOSSIAOPTS },
{ "postbabelpreamble", LA_POSTBABELPREAMBLE },
{ "prebabelpreamble", LA_PREBABELPREAMBLE },
+ { "provides", LA_PROVIDES },
{ "quotestyle", LA_QUOTESTYLE },
{ "requires", LA_REQUIRES },
{ "rtl", LA_RTL }
error = true;
continue;
- default:
+ default:
break;
}
switch (static_cast<LanguageTags>(le)) {
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;
break;
case LA_POSTBABELPREAMBLE:
babel_postsettings_ =
- lex.getLongString("EndPostBabelPreamble");
+ lex.getLongString(from_ascii("EndPostBabelPreamble"));
break;
case LA_PREBABELPREAMBLE:
babel_presettings_ =
- lex.getLongString("EndPreBabelPreamble");
+ lex.getLongString(from_ascii("EndPreBabelPreamble"));
break;
case LA_REQUIRES:
lex >> requires_;
break;
+ case LA_PROVIDES:
+ lex >> provides_;
+ break;
case LA_RTL:
lex >> rightToLeft_;
break;
encoding_ = encodings.fromLyXName("iso8859-1");
LYXERR0("Unknown encoding " << encodingStr_);
}
+ if (fontenc_.empty())
+ fontenc_.push_back("ASCII");
+ if (dateformats_.empty()) {
+ dateformats_.push_back("MMMM dd, yyyy");
+ dateformats_.push_back("MMM dd, yyyy");
+ dateformats_.push_back("M/d/yyyy");
+ }
return true;
}
languagelist[l.lang()] = l;
}
- default_language = getLanguage(lyxrc.default_language);
+ default_language = getLanguage("english");
if (!default_language) {
- LYXERR0("Default language \"" << lyxrc.default_language
- << "\" not found!");
- default_language = getLanguage("english");
- if (!default_language)
- default_language = &(*languagelist.begin()).second;
+ LYXERR0("Default language \"english\" not found!");
+ default_language = &(*languagelist.begin()).second;
LYXERR0("Using \"" << default_language->lang() << "\" instead!");
}
// Read layout translations
- FileName path = libFileSearch(string(), "layouttranslations");
+ FileName const path = libFileSearch(string(), "layouttranslations");
readLayoutTranslations(path);
-
- // Read installed translations
- path = libFileSearch(string(), "installed_translations");
- readInstalledTranslations(path);
}
return NoMatch;
}
+} // namespace
+
+
+
+Language const * Languages::getFromCode(string const & code) const
+{
+ LanguageList::const_iterator const lbeg = languagelist.begin();
+ LanguageList::const_iterator const lend = languagelist.end();
+ // Try for exact match first
+ for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
+ if (match(code, lit->second) == ExactMatch)
+ return &lit->second;
+ }
+ // If not found, look for lang prefix (without country) instead
+ for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
+ if (match(code, lit->second) == ApproximateMatch)
+ return &lit->second;
+ }
+ LYXERR0("Unknown language `" + code + "'");
+ return 0;
}
if (!lex.next(true))
break;
string const code = lex.getString();
- bool found = false;
- for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
- if (match(code, lit->second) != NoMatch) {
- found = true;
- break;
- }
- }
+ bool found = getFromCode(code);
if (!found) {
lex.printError("Unknown language `" + code + "'");
break;
}
-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")