]> git.lyx.org Git - lyx.git/blob - src/Language.h
Introduce a new Language option "AsBabelOptions" that specifies whether a language...
[lyx.git] / src / Language.h
1 // -*- C++ -*-
2 /**
3  * \file Language.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Dekel Tsur
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LANGUAGE_H
16 #define LANGUAGE_H
17
18 #include <map>
19 #include <string>
20
21
22 namespace lyx {
23
24 namespace support { class FileName; }
25
26 class Encoding;
27 class Lexer;
28
29 ///
30 class Language {
31 public:
32         ///
33         Language() : rightToLeft_(false) {}
34         ///
35         std::string const & lang() const { return lang_; }
36         ///
37         std::string const & babel() const { return babel_; }
38         ///
39         std::string const & display() const { return display_; }
40         ///
41         bool rightToLeft() const { return rightToLeft_; }
42         ///
43         Encoding const * encoding() const { return encoding_; }
44         ///
45         std::string const & encodingStr() const { return encodingStr_; }
46         ///
47         std::string const & code() const { return code_; }
48         /// set code (needed for rc.spellchecker_alt_lang)
49         void setCode(std::string const c) { code_ = c; }
50         ///
51         std::string const & variety() const { return variety_; }
52         /// set variety (needed for rc.spellchecker_alt_lang)
53         void setVariety(std::string const v) { variety_ = v; }
54         ///
55         std::string const & babel_postsettings() const { return babel_postsettings_; }
56         ///
57         std::string const & babel_presettings() const { return babel_presettings_; }
58         /// This language internally sets a font encoding
59         bool internalFontEncoding() const { return internal_enc_; }
60         /// This language needs to be passed to babel itself (not the class)
61         bool asBabelOptions() const { return as_babel_options_; }
62         ///
63         bool read(Lexer & lex);
64         ///
65         bool readLanguage(Lexer & lex);
66         // for the use in std::map
67         friend bool operator<(Language const & p, Language const & q);
68 private:
69         ///
70         std::string lang_;
71         ///
72         std::string babel_;
73         ///
74         std::string display_;
75         ///
76         bool rightToLeft_;
77         ///
78         std::string encodingStr_;
79         ///
80         Encoding const * encoding_;
81         ///
82         std::string code_;
83         ///
84         std::string variety_;
85         ///
86         std::string babel_postsettings_;
87         ///
88         std::string babel_presettings_;
89         ///
90         bool internal_enc_;
91         ///
92         bool as_babel_options_;
93 };
94
95
96 inline bool operator<(Language const & p, Language const & q)
97 {
98         return q.lang() > p.lang();
99 }
100
101
102 class Languages
103 {
104 public:
105         ///
106         typedef std::map<std::string, Language> LanguageList;
107         ///
108         typedef LanguageList::const_iterator const_iterator;
109         ///
110         typedef LanguageList::size_type size_type;
111         ///
112         void read(support::FileName const & filename);
113         ///
114         Language const * getLanguage(std::string const & language) const;
115         ///
116         size_type size() const { return languagelist.size(); }
117         ///
118         const_iterator begin() const { return languagelist.begin(); }
119         ///
120         const_iterator end() const { return languagelist.end(); }
121         ///
122
123 private:
124         ///
125         LanguageList languagelist;
126 };
127
128 /// Global singleton instance.
129 extern Languages languages;
130 /// Default language defined in LyXRC
131 extern Language const * default_language;
132 /// Used to indicate that the language should be left unchanged when
133 /// applying a font change.
134 extern Language const * ignore_language;
135 /// Default language defined in LyXRC
136 extern Language const * latex_language;
137 /// Used to indicate that the language should be reset to the Buffer
138 // language when applying a font change.
139 extern Language const * reset_language;
140
141
142 } // namespace lyx
143
144 #endif