]> git.lyx.org Git - lyx.git/blob - src/Language.cpp
* src/Language{.cpp,h}:
[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 "Encoding.h"
18 #include "Lexer.h"
19 #include "LyXRC.h"
20
21 #include "support/debug.h"
22 #include "support/FileName.h"
23
24 using namespace std;
25 using namespace lyx::support;
26
27
28 namespace lyx {
29
30 Languages languages;
31 Language ignore_lang;
32 Language latex_lang;
33 Language const * default_language;
34 Language const * ignore_language = &ignore_lang;
35 Language const * latex_language = &latex_lang;
36 Language const * reset_language = 0;
37
38
39 bool Language::read(Lexer & lex)
40 {
41         encoding_ = 0;
42         lex >> lang_;
43         lex >> babel_;
44         lex >> display_;
45         lex >> rightToLeft_;
46         lex >> encodingStr_;
47         lex >> code_;
48         lex >> latex_options_;
49         if (!lex)
50                 return false;
51
52         encoding_ = encodings.fromLyXName(encodingStr_);
53         if (!encoding_ && !encodingStr_.empty()) {
54                 encoding_ = encodings.fromLyXName("iso8859-1");
55                 LYXERR0("Unknown encoding " << encodingStr_);
56         }
57         return true;
58 }
59
60 bool Language::internalFontEncoding() const
61 {
62         // FIXME: list incomplete
63         // FIXME: instead of hardcoding, this
64         // should go to the languages file
65         return lang_ == "hebrew"
66                 || lang_ == "greek"
67                 || lang_ == "polutonikogreek";
68 }
69
70
71 void Languages::read(FileName const & filename)
72 {
73         Lexer lex;
74         lex.setFile(filename);
75         lex.setContext("Languages::read");
76         while (1) {
77                 Language l;
78                 l.read(lex);
79                 if (!lex)
80                         break;
81                 LYXERR(Debug::INFO, "Reading language " << l.lang());
82                 if (l.lang() == "latex")
83                         latex_lang = l;
84                 else if (l.lang() == "ignore")
85                         ignore_lang = l;
86                 else
87                         languagelist[l.lang()] = l;
88         }
89
90         default_language = getLanguage(lyxrc.default_language);
91         if (!default_language) {
92                 LYXERR0("Default language \"" << lyxrc.default_language
93                        << "\" not found!");
94                 default_language = getLanguage("english");
95                 if (!default_language)
96                         default_language = &(*languagelist.begin()).second;
97                 LYXERR0("Using \"" << default_language->lang() << "\" instead!");
98         }
99 }
100
101
102 Language const * Languages::getLanguage(string const & language) const
103 {
104         if (language == "reset")
105                 return reset_language;
106         if (language == "ignore")
107                 return ignore_language;
108         const_iterator it = languagelist.find(language);
109         return it == languagelist.end() ? reset_language : &it->second;
110 }
111
112
113 } // namespace lyx