]> git.lyx.org Git - lyx.git/blob - src/Language.cpp
Move debug.{cpp,h}, Messages.{cpp,h} and gettext.{cpp,h} to support/.
[lyx.git] / src / Language.cpp
1 /**
2  * \file Language.cpp
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 "support/debug.h"
18 #include "Encoding.h"
19 #include "Lexer.h"
20 #include "LyXRC.h"
21
22 #include "support/FileName.h"
23
24 #include <ostream>
25
26 using std::endl;
27 using std::string;
28
29
30 namespace lyx {
31
32
33 Languages languages;
34 Language const * english_language;
35 Language const * default_language;
36 Language ignore_lang("ignore", "ignore", "Ignore", false, "", 0, "ignore", "");
37 Language const * ignore_language = &ignore_lang;
38 Language latex_lang("latex", "", "Latex", false, "", 0, "latex", "");
39 Language const * latex_language = &latex_lang;
40
41
42 void Languages::read(support::FileName const & filename)
43 {
44         // We need to set the encoding of latex_lang
45         latex_lang = Language("latex", "", "Latex", false, "iso8859-1",
46                               encodings.getFromLyXName("iso8859-1"),
47                               "latex", "");
48
49         Lexer lex(0, 0);
50         lex.setFile(filename);
51         while (lex.isOK()) {
52                 string lang;
53                 string babel;
54                 string display;
55                 string encoding_str;
56                 string code;
57                 string latex_options;
58                 bool rtl = false;
59
60                 if (lex.next())
61                         lang = lex.getString();
62                 else
63                         break;
64                 LYXERR(Debug::INFO, "Reading language " << lang);
65
66                 if (lex.next())
67                         babel = lex.getString();
68                 if (lex.next())
69                         display = lex.getString();
70                 if (lex.next())
71                         rtl = lex.getBool();
72                 if (lex.next())
73                         encoding_str = lex.getString();
74                 if (lex.next())
75                         code = lex.getString();
76                 if (lex.next())
77                         latex_options = lex.getString();
78
79                 Encoding const * encoding = encodings.getFromLyXName(encoding_str);
80                 if (!encoding) {
81                         encoding = encodings.getFromLyXName("iso8859-1");
82                         lyxerr << "Unknown encoding " << encoding_str << endl;
83                 }
84
85                 languagelist[lang] = Language(lang, babel, display, rtl,
86                                               encoding_str, encoding, code, latex_options);
87         }
88
89         default_language = getLanguage(lyxrc.default_language);
90         if (!default_language) {
91                 lyxerr << "Default language \"" << lyxrc.default_language
92                        << "\" not found!" << endl;
93                 default_language = getLanguage("english");
94                 if (!default_language)
95                         default_language = &(*languagelist.begin()).second;
96                 lyxerr << "Using \"" << default_language->lang()
97                        << "\" instead!" << endl;
98         }
99         english_language = getLanguage("english");
100         if (!english_language)
101                 english_language = default_language;
102 }
103
104
105 Language const * Languages::getLanguage(string const & language) const
106 {
107         const_iterator it = languagelist.find(language);
108         return it == languagelist.end() ? 0 : &it->second;
109 }
110
111
112 } // namespace lyx