+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright 1995 Matthias Ettrich
+ * Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
#include <config.h>
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
#include "language.h"
#include "gettext.h"
+#include "encoding.h"
+#include "lyxrc.h"
+#include "lyx_gui_misc.h"
+#include "lyxlex.h"
+#include "debug.h"
+
+using std::endl;
Languages languages;
+Language const * english_language;
Language const * default_language;
-Language ignore_lang("ignore", "Ignore", false);
+Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
Language const * ignore_language = &ignore_lang;
+Language inherit_lang("inherit", "inherit", "Inherit", false, 0, "inherit", "");
+Language const * inherit_language = &inherit_lang;
-///
-class LangInit {
-public:
- ///
- LangInit() {
- if (!init) initL();
- init = true;
- }
-private:
- ///
- void newLang(char const * l, char const * d, bool rtl) {
- Language lang(l, d, rtl);
- //lang.lang = l;
- //lang.display = d;
- //lang.RightToLeft = rtl;
- languages[l] = lang;
- }
- ///
- void initL();
- ///
- static bool init;
-};
+void Languages::setDefaults()
+{
+ languagelist["english"] = Language("english", "english", N_("English"),
+ false,
+ encodings.getEncoding("iso8859-1"),
+ "en", "");
+ english_language = default_language = &languagelist["english"];
+}
+
+void Languages::read(string const & filename)
+{
+ 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;
-struct lang_item {
- char const * lang;
- char const * display;
- bool rtl;
-};
+ 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();
+ Encoding const * encoding = encodings.getEncoding(encoding_str);
+ if (!encoding) {
+ encoding = encodings.getEncoding("iso8859-1");
+ lyxerr << "Unknown encoding " << encoding_str << endl;
+ }
-void LangInit::initL()
-{
- // Use this style of initialization to lower compilation times.
- // Same method is used in LyXAction.C (Lgb)
-
- lang_item items[] = {
- { "afrikaans", N_("Afrikaans"), false },
- { "american", N_("American"), false },
- { "arabic", N_("Arabic"), true },
- { "austrian", N_("Austrian"), false },
- { "bahasa", N_("Bahasa"), false },
- { "brazil", N_("Brazil"), false },
- { "breton", N_("Breton"), false },
- { "catalan", N_("Catalan"), false },
- { "croatian", N_("Croatian"), false },
- { "czech", N_("Czech"), false },
- { "danish", N_("Danish"), false },
- { "dutch", N_("Dutch"), false },
- { "english", N_("English"), false },
- { "esperanto", N_("Esperanto"), false },
- { "estonian", N_("Estonian"), false },
- { "finnish", N_("Finnish"), false },
- { "francais", N_("Francais"), false },
- { "french", N_("French"), false },
- { "frenchb", N_("Frenchb"), false },
- { "galician", N_("Galician"), false },
- { "german", N_("German"), false },
- { "greek", N_("Greek"), false },
- { "hebrew", N_("Hebrew"), true },
- { "hungarian", N_("Hungarian"), false },
- { "irish", N_("Irish"), false },
- { "italian", N_("Italian"), false },
- { "lsorbian", N_("Lsorbian"), false },
- { "magyar", N_("Magyar"), false },
- { "norsk", N_("Norsk"), false },
- { "polish", N_("Polish"), false },
- { "portuges", N_("Portuges"), false },
- { "romanian", N_("Romanian"), false },
- { "russian", N_("Russian"), false },
- { "scottish", N_("Scottish"), false },
- { "spanish", N_("Spanish"), false },
- { "slovak", N_("Slovak"), false },
- { "slovene", N_("Slovene"), false },
- { "swedish", N_("Swedish"), false },
- { "turkish", N_("Turkish"), false },
- { "usorbian", N_("Usorbian"), false },
- { "welsh", N_("Welsh"), false },
- { 0, 0, false }
- };
+ languagelist[lang] = Language(lang, babel, display, rtl,
+ encoding, code, latex_options);
+ }
- int i = 0;
- while (items[i].lang) {
- newLang(items[i].lang, items[i].display, items[i].rtl);
- ++i;
+ 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;
}
-
- default_language = &languages["american"];
+ english_language = getLanguage("english");
+ if (!english_language)
+ english_language = default_language;
}
-
-static
-LangInit langinit;
-
-bool LangInit::init = false;
+Language const * Languages::getLanguage(string const & language) const
+{
+ const_iterator it = languagelist.find(language);
+ if (it != languagelist.end())
+ return &it->second;
+ else
+ return 0;
+}