]> git.lyx.org Git - lyx.git/blob - src/Language.h
fbb37202df022016f04f3b7b8257b32d9e1b6158
[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), translated_(false) {}
34         /// LyX language name
35         std::string const & lang() const { return lang_; }
36         /// Babel language name
37         std::string const & babel() const { return babel_; }
38         /// polyglossia language name
39         std::string const & polyglossia() const { return polyglossia_name_; }
40         /// polyglossia language options
41         std::string const & polyglossiaOpts() const { return polyglossia_opts_; }
42         /// translatable GUI name
43         std::string const & display() const { return display_; }
44         /// is this a RTL language?
45         bool rightToLeft() const { return rightToLeft_; }
46         /// Is an (at least partial) translation of this language available?
47         bool translated() const { return translated_; }
48         /// default encoding
49         Encoding const * encoding() const { return encoding_; }
50         ///
51         std::string const & encodingStr() const { return encodingStr_; }
52         /// language code
53         std::string const & code() const { return code_; }
54         /// set code (needed for rc.spellchecker_alt_lang)
55         void setCode(std::string const c) { code_ = c; }
56         /// language variety (needed by aspell checker)
57         std::string const & variety() const { return variety_; }
58         /// set variety (needed for rc.spellchecker_alt_lang)
59         void setVariety(std::string const v) { variety_ = v; }
60         /// create a unique ID from lang code and variety
61         std::string const id() const {
62                 return variety_.empty() ? code_ : code_ + "-" + variety_; }
63         /// preamble settings after babel was called
64         std::string const & babel_postsettings() const { return babel_postsettings_; }
65         /// preamble settings before babel is called
66         std::string const & babel_presettings() const { return babel_presettings_; }
67         /// This language internally sets a font encoding
68         bool internalFontEncoding() const { return internal_enc_; }
69         /// This language needs to be passed to babel itself (not the class)
70         bool asBabelOptions() const { return as_babel_options_; }
71         ///
72         bool read(Lexer & lex);
73         ///
74         bool readLanguage(Lexer & lex);
75         // for the use in std::map
76         friend bool operator<(Language const & p, Language const & q);
77 private:
78         ///
79         std::string lang_;
80         ///
81         std::string babel_;
82         ///
83         std::string polyglossia_name_;
84         ///
85         std::string polyglossia_opts_;
86         ///
87         std::string display_;
88         ///
89         bool rightToLeft_;
90         ///
91         std::string encodingStr_;
92         ///
93         Encoding const * encoding_;
94         ///
95         std::string code_;
96         ///
97         std::string variety_;
98         ///
99         std::string babel_postsettings_;
100         ///
101         std::string babel_presettings_;
102         ///
103         bool internal_enc_;
104         ///
105         bool as_babel_options_;
106         ///
107         bool translated_;
108 };
109
110
111 inline bool operator<(Language const & p, Language const & q)
112 {
113         return q.lang() > p.lang();
114 }
115
116
117 class Languages
118 {
119 public:
120         ///
121         typedef std::map<std::string, Language> LanguageList;
122         ///
123         typedef LanguageList::const_iterator const_iterator;
124         ///
125         typedef LanguageList::size_type size_type;
126         ///
127         void read(support::FileName const & filename);
128         ///
129         Language const * getLanguage(std::string const & language) const;
130         ///
131         size_type size() const { return languagelist.size(); }
132         ///
133         const_iterator begin() const { return languagelist.begin(); }
134         ///
135         const_iterator end() const { return languagelist.end(); }
136         ///
137
138 private:
139         ///
140         LanguageList languagelist;
141 };
142
143 /// Global singleton instance.
144 extern Languages languages;
145 /// Default language defined in LyXRC
146 extern Language const * default_language;
147 /// Used to indicate that the language should be left unchanged when
148 /// applying a font change.
149 extern Language const * ignore_language;
150 /// Default language defined in LyXRC
151 extern Language const * latex_language;
152 /// Used to indicate that the language should be reset to the Buffer
153 // language when applying a font change.
154 extern Language const * reset_language;
155
156
157 } // namespace lyx
158
159 #endif