]> git.lyx.org Git - lyx.git/blob - src/language.C
do not define boost::throw_exceptions if we are compiling with exceptions
[lyx.git] / src / language.C
1 /**
2  * \file language.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Dekel Tsur
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "language.h"
16
17 #include "debug.h"
18 #include "encoding.h"
19 #include "lyxlex.h"
20 #include "lyxrc.h"
21
22 using std::endl;
23 using std::string;
24
25
26 Languages languages;
27 Language const * english_language;
28 Language const * default_language;
29 Language ignore_lang("ignore", "ignore", "Ignore", false, "", 0, "ignore", "");
30 Language const * ignore_language = &ignore_lang;
31 Language latex_lang("latex", "latex", "Latex", false, "", 0, "latex", "");
32 Language const * latex_language = &latex_lang;
33
34
35 void Languages::read(string const & filename)
36 {
37         // We need to set the encoding of latex_lang
38         latex_lang = Language("latex", "latex", "Latex", false, "iso8859-1",
39                               encodings.getEncoding("iso8859-1"),
40                               "latex", "");
41
42         LyXLex lex(0, 0);
43         lex.setFile(filename);
44         while (lex.isOK()) {
45                 string lang;
46                 string babel;
47                 string display;
48                 string encoding_str;
49                 string code;
50                 string latex_options;
51                 bool rtl = false;
52
53                 if (lex.next())
54                         lang = lex.getString();
55                 else
56                         break;
57                 lyxerr[Debug::INIT] << "Reading language " << lang << endl;
58
59                 if (lex.next())
60                         babel = lex.getString();
61                 if (lex.next())
62                         display = lex.getString();
63                 if (lex.next())
64                         rtl = lex.getBool();
65                 if (lex.next())
66                         encoding_str = lex.getString();
67                 if (lex.next())
68                         code = lex.getString();
69                 if (lex.next())
70                         latex_options = lex.getString();
71
72                 Encoding const * encoding = encodings.getEncoding(encoding_str);
73                 if (!encoding) {
74                         encoding = encodings.getEncoding("iso8859-1");
75                         lyxerr << "Unknown encoding " << encoding_str << endl;
76                 }
77
78                 languagelist[lang] = Language(lang, babel, display, rtl,
79                                               encoding_str, encoding, code, latex_options);
80         }
81
82         default_language = getLanguage(lyxrc.default_language);
83         if (!default_language) {
84                 lyxerr << "Default language \"" << lyxrc.default_language
85                        << "\" not found!" << endl;
86                 default_language = getLanguage("english");
87                 if (!default_language)
88                         default_language = &(*languagelist.begin()).second;
89                 lyxerr << "Using \"" << default_language->lang()
90                        << "\" instead!" << endl;
91         }
92         english_language = getLanguage("english");
93         if (!english_language)
94                 english_language = default_language;
95 }
96
97
98 Language const * Languages::getLanguage(string const & language) const
99 {
100         const_iterator it = languagelist.find(language);
101         return it == languagelist.end() ? 0 : &it->second;
102 }