+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright 1995 Matthias Ettrich
+ * Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
#include <config.h>
#include "language.h"
#include "gettext.h"
+#include "encoding.h"
+#include "lyxrc.h"
+#include "lyxlex.h"
+#include "debug.h"
+
+using std::endl;
Languages languages;
-Language const *default_language;
-Language ignore_lang = {"ignore", "Ignore", false};
+Language const * english_language;
+Language const * default_language;
+Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
Language const * ignore_language = &ignore_lang;
+Language latex_lang("latex", "latex", "Latex", false, 0, "latex", "");
+Language const * latex_language = &latex_lang;
-///
-class LangInit {
-public:
- ///
- LangInit() {
- if (!init) initL();
- init = true;
- }
-private:
- ///
- void newLang(string const & l, string const & d, bool rtl) {
- Language lang;
- lang.lang = l;
- lang.display = d;
- lang.RightToLeft = rtl;
- languages[l] = lang;
- }
- ///
- void initL();
- ///
- static bool init;
-};
+void Languages::setDefaults()
+{
+ // We need to set the encoding of latex_lang
+ latex_lang = Language("latex", "latex", "Latex", false,
+ encodings.getEncoding("iso8859-1"),
+ "latex", "");
+ languagelist["english"] = Language("english", "english", N_("English"),
+ false,
+ encodings.getEncoding("iso8859-1"),
+ "en", "");
+ english_language = default_language = &languagelist["english"];
+}
-void LangInit::initL()
+void Languages::read(string const & filename)
{
- newLang("afrikaans", N_("Afrikaans"), false);
- newLang("american", N_("American"), false);
- newLang("arabic", N_("Arabic"), true);
- newLang("austrian", N_("Austrian"), false);
- newLang("bahasa", N_("Bahasa"), false);
- newLang("brazil", N_("Brazil"), false);
- newLang("breton", N_("Breton"), false);
- newLang("catalan", N_("Catalan"), false);
- newLang("croatian", N_("Croatian"), false);
- newLang("czech", N_("Czech"), false);
- newLang("danish", N_("Danish"), false);
- newLang("dutch", N_("Dutch"), false);
- newLang("english", N_("English"), false);
- newLang("esperanto", N_("Esperanto"), false);
- newLang("estonian", N_("Estonian"), false);
- newLang("finnish", N_("Finnish"), false);
- newLang("francais", N_("Francais"), false);
- newLang("french", N_("French"), false);
- newLang("frenchb", N_("Frenchb"), false);
- newLang("galician", N_("Galician"), false);
- newLang("german", N_("German"), false);
- newLang("greek", N_("Greek"), false);
- newLang("hebrew", N_("Hebrew"), true);
- newLang("hungarian", N_("Hungarian"), false);
- newLang("irish", N_("Irish"), false);
- newLang("italian", N_("Italian"), false);
- newLang("lsorbian", N_("Lsorbian"), false);
- newLang("magyar", N_("Magyar"), false);
- newLang("norsk", N_("Norsk"), false);
- newLang("polish", N_("Polish"), false);
- newLang("portuges", N_("Portuges"), false);
- newLang("romanian", N_("Romanian"), false);
- newLang("russian", N_("Russian"), false);
- newLang("scottish", N_("Scottish"), false);
- newLang("spanish", N_("Spanish"), false);
- newLang("slovak", N_("Slovak"), false);
- newLang("slovene", N_("Slovene"), false);
- newLang("swedish", N_("Swedish"), false);
- newLang("turkish", N_("Turkish"), false);
- newLang("usorbian", N_("Usorbian"), false);
- newLang("welsh", N_("Welsh"), false);
- default_language = &languages["american"];
-}
+ // We need to set the encoding of latex_lang
+ latex_lang = Language("latex", "latex", "Latex", false,
+ encodings.getEncoding("iso8859-1"),
+ "latex", "");
+
+ LyXLex lex(0, 0);
+ lex.setFile(filename);
+ while (lex.isOK()) {
+ string lang;
+ string babel;
+ string display;
+ string encoding_str;
+ string code;
+ string latex_options;
+ bool rtl = false;
+
+ if (lex.next())
+ lang = lex.getString();
+ else
+ break;
+ lyxerr[Debug::INIT] << "Reading language " << lang << endl;
+ if (lex.next())
+ babel = lex.getString();
+ if (lex.next())
+ display = lex.getString();
+ if (lex.next())
+ rtl = lex.getBool();
+ if (lex.next())
+ encoding_str = lex.getString();
+ if (lex.next())
+ code = lex.getString();
+ if (lex.next())
+ latex_options = lex.getString();
-static
-LangInit langinit;
+ Encoding const * encoding = encodings.getEncoding(encoding_str);
+ if (!encoding) {
+ encoding = encodings.getEncoding("iso8859-1");
+ lyxerr << "Unknown encoding " << encoding_str << endl;
+ }
-bool LangInit::init = false;
+ languagelist[lang] = Language(lang, babel, display, rtl,
+ encoding, code, latex_options);
+ }
+
+ default_language = getLanguage(lyxrc.default_language);
+ if (!default_language) {
+ lyxerr << "Default language \"" << lyxrc.default_language
+ << "\" not found!" << endl;
+ default_language = getLanguage("english");
+ if (!default_language)
+ default_language = &(*languagelist.begin()).second;
+ lyxerr << "Using \"" << default_language->lang()
+ << "\" instead!" << endl;
+ }
+ english_language = getLanguage("english");
+ if (!english_language)
+ english_language = default_language;
+}
+
+Language const * Languages::getLanguage(string const & language) const
+{
+ const_iterator it = languagelist.find(language);
+ if (it != languagelist.end())
+ return &it->second;
+ else
+ return 0;
+}