* qt_helpers.cpp:
[lyx.git] / src / Language.cpp
blob2093bc373cd028b963ce77b86fa68c6234695906
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.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Dekel Tsur
10 * Full author contact details are available in file CREDITS.
13 #include <config.h>
15 #include "Language.h"
17 #include "Encoding.h"
18 #include "Lexer.h"
19 #include "LyXRC.h"
21 #include "support/debug.h"
22 #include "support/FileName.h"
24 using namespace std;
25 using namespace lyx::support;
28 namespace lyx {
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;
39 bool Language::read(Lexer & lex)
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;
52 encoding_ = encodings.fromLyXName(encodingStr_);
53 if (!encoding_ && !encodingStr_.empty()) {
54 encoding_ = encodings.fromLyXName("iso8859-1");
55 LYXERR0("Unknown encoding " << encodingStr_);
57 return true;
60 bool Language::internalFontEncoding() const
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";
71 void Languages::read(FileName const & filename)
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;
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!");
102 Language const * Languages::getLanguage(string const & language) const
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;
113 } // namespace lyx