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