2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
2000-03-10 13:52:19 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
#include "language.h"
|
|
|
|
#include "gettext.h"
|
2000-07-04 20:32:37 +00:00
|
|
|
#include "encoding.h"
|
2000-09-27 15:23:24 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
2000-10-10 12:36:36 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using std::endl;
|
2000-03-10 13:52:19 +00:00
|
|
|
|
|
|
|
Languages languages;
|
2000-10-30 21:53:29 +00:00
|
|
|
Language const * english_language;
|
2000-05-19 19:46:23 +00:00
|
|
|
Language const * default_language;
|
2001-01-20 14:16:01 +00:00
|
|
|
Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
|
2000-03-17 10:14:46 +00:00
|
|
|
Language const * ignore_language = &ignore_lang;
|
2001-07-27 12:03:36 +00:00
|
|
|
Language inherit_lang("inherit", "inherit", "Inherit", false, 0, "inherit", "");
|
|
|
|
Language const * inherit_language = &inherit_lang;
|
2000-03-10 13:52:19 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
void Languages::setDefaults()
|
|
|
|
{
|
|
|
|
languagelist["english"] = Language("english", "english", N_("English"),
|
|
|
|
false,
|
|
|
|
encodings.getEncoding("iso8859-1"),
|
2001-01-20 14:16:01 +00:00
|
|
|
"en", "");
|
2000-10-30 21:53:29 +00:00
|
|
|
english_language = default_language = &languagelist["english"];
|
2000-10-10 12:36:36 +00:00
|
|
|
}
|
2000-04-04 00:19:15 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
void Languages::read(string const & filename)
|
|
|
|
{
|
|
|
|
LyXLex lex(0, 0);
|
|
|
|
lex.setFile(filename);
|
|
|
|
while (lex.IsOK()) {
|
2001-01-20 14:16:01 +00:00
|
|
|
string lang, babel, display, encoding_str, code, latex_options;
|
2000-10-10 12:36:36 +00:00
|
|
|
bool rtl = false;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
if (lex.next())
|
|
|
|
lang = lex.GetString();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
lyxerr[Debug::INIT] << "Reading language " << lang << endl;
|
2000-05-21 18:40:10 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
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();
|
2001-01-20 14:16:01 +00:00
|
|
|
if (lex.next())
|
|
|
|
latex_options = lex.GetString();
|
2000-05-21 18:40:10 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
Encoding const * encoding = encodings.getEncoding(encoding_str);
|
|
|
|
if (!encoding) {
|
|
|
|
encoding = encodings.getEncoding("iso8859-1");
|
|
|
|
lyxerr << "Unknown encoding " << encoding_str << endl;
|
|
|
|
}
|
|
|
|
|
2001-01-20 14:16:01 +00:00
|
|
|
languagelist[lang] = Language(lang, babel, display, rtl,
|
|
|
|
encoding, code, latex_options);
|
2000-10-10 12:36:36 +00:00
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
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;
|
2000-05-21 18:40:10 +00:00
|
|
|
}
|
2000-10-30 21:53:29 +00:00
|
|
|
english_language = getLanguage("english");
|
|
|
|
if (!english_language)
|
|
|
|
english_language = default_language;
|
2000-04-04 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
Language const * Languages::getLanguage(string const & language) const
|
|
|
|
{
|
|
|
|
const_iterator it = languagelist.find(language);
|
|
|
|
if (it != languagelist.end())
|
2001-07-12 11:11:10 +00:00
|
|
|
return &it->second;
|
2000-10-10 12:36:36 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|