2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* 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>
|
|
|
|
|
|
|
|
#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"
|
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-08-11 18:31:14 +00:00
|
|
|
Language latex_lang("latex", "latex", "Latex", false, 0, "latex", "");
|
|
|
|
Language const * latex_language = &latex_lang;
|
2000-03-10 13:52:19 +00:00
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
void Languages::setDefaults()
|
|
|
|
{
|
2002-07-20 13:30:55 +00:00
|
|
|
// We need to set the encoding of latex_lang
|
|
|
|
latex_lang = Language("latex", "latex", "Latex", false,
|
|
|
|
encodings.getEncoding("iso8859-1"),
|
|
|
|
"latex", "");
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
languagelist["english"] = Language("english", "english", N_("English"),
|
2002-03-21 17:27:08 +00:00
|
|
|
false,
|
2000-10-10 12:36:36 +00:00
|
|
|
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)
|
|
|
|
{
|
2002-07-20 13:30:55 +00:00
|
|
|
// We need to set the encoding of latex_lang
|
|
|
|
latex_lang = Language("latex", "latex", "Latex", false,
|
|
|
|
encodings.getEncoding("iso8859-1"),
|
|
|
|
"latex", "");
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
LyXLex lex(0, 0);
|
|
|
|
lex.setFile(filename);
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lex.isOK()) {
|
|
|
|
string lang;
|
|
|
|
string babel;
|
|
|
|
string display;
|
|
|
|
string encoding_str;
|
|
|
|
string code;
|
|
|
|
string 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())
|
2001-08-06 19:12:46 +00:00
|
|
|
lang = lex.getString();
|
2000-10-10 12:36:36 +00:00
|
|
|
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())
|
2001-08-06 19:12:46 +00:00
|
|
|
babel = lex.getString();
|
2000-10-10 12:36:36 +00:00
|
|
|
if (lex.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
display = lex.getString();
|
2000-10-10 12:36:36 +00:00
|
|
|
if (lex.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
rtl = lex.getBool();
|
2000-10-10 12:36:36 +00:00
|
|
|
if (lex.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
encoding_str = lex.getString();
|
2000-10-10 12:36:36 +00:00
|
|
|
if (lex.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
code = lex.getString();
|
2001-01-20 14:16:01 +00:00
|
|
|
if (lex.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
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");
|
2002-03-21 17:27:08 +00:00
|
|
|
lyxerr << "Unknown encoding " << encoding_str << endl;
|
2000-10-10 12:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
languagelist[lang] = Language(lang, babel, display, rtl,
|
2001-01-20 14:16:01 +00:00
|
|
|
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
|
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
const_iterator it = languagelist.find(language);
|
2000-10-10 12:36:36 +00:00
|
|
|
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;
|
|
|
|
}
|