2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file language.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Dekel Tsur
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2000-03-10 13:52:19 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "language.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
2000-07-04 20:32:37 +00:00
|
|
|
|
#include "encoding.h"
|
2000-10-10 12:36:36 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2000-10-10 12:36:36 +00:00
|
|
|
|
|
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
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;
|
2005-07-16 15:55:36 +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;
|
2005-07-16 15:55:36 +00:00
|
|
|
|
Language latex_lang("latex", "latex", "Latex", false, "", 0, "latex", "");
|
2001-08-11 18:31:14 +00:00
|
|
|
|
Language const * latex_language = &latex_lang;
|
2000-03-10 13:52:19 +00:00
|
|
|
|
|
2005-07-16 12:02:31 +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
|
2005-07-16 15:55:36 +00:00
|
|
|
|
latex_lang = Language("latex", "latex", "Latex", false, "iso8859-1",
|
2002-07-20 13:30:55 +00:00
|
|
|
|
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,
|
2005-07-16 15:55:36 +00:00
|
|
|
|
encoding_str, 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
|
|
|
|
}
|
|
|
|
|
|
2005-07-16 12:02:31 +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);
|
2005-07-16 12:02:31 +00:00
|
|
|
|
return it == languagelist.end() ? 0 : &it->second;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
}
|