]> git.lyx.org Git - lyx.git/blob - src/Language.h
Remove all uses of Q_WS_* macros
[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 "support/docstring.h"
19 #include "support/trivstring.h"
20
21 #include <map>
22 #include <set>
23 #include <vector>
24
25
26 namespace lyx {
27
28 namespace support { class FileName; }
29
30 class BufferParams;
31 class Encoding;
32 class Lexer;
33
34 ///
35 class Language {
36 public:
37         ///
38         Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
39                                  has_gui_support_(false), word_wrap_(true) {}
40         /// LyX language name
41         std::string const lang() const { return lang_; }
42         /// Babel language name
43         std::string const babel() const { return babel_; }
44         /// polyglossia language name
45         std::string const polyglossia() const { return polyglossia_name_; }
46         /// polyglossia language options
47         std::string const polyglossiaOpts() const { return polyglossia_opts_; }
48         /// polyglossia language options
49         std::string const xindy() const { return xindy_; }
50         /// Is this language only supported by polyglossia?
51         bool isPolyglossiaExclusive() const;
52         /// Is this language only supported by babel?
53         bool isBabelExclusive() const;
54         /// quotation marks style
55         std::string const quoteStyle() const { return quote_style_; }
56         /// active characters
57         std::string const activeChars() const { return active_chars_; }
58         /// requirement (package, function)
59         std::string const required() const { return required_; }
60         /// provides feature
61         std::string const provides() const { return provides_; }
62         /// translatable GUI name
63         std::string const display() const { return display_; }
64         /// is this a RTL language?
65         bool rightToLeft() const { return rightToLeft_; }
66         /// shall text be wrapped at word boundary ?
67         bool wordWrap() const { return word_wrap_; }
68         /**
69          * Translate a string from the layout files that appears in the output.
70          * It takes the translations from lib/layouttranslations instead of
71          * the .mo files. This should be used for every translation that
72          * appears in the exported document, since the output must not depend
73          * on installed locales. Non-ASCII keys are not translated. */
74         docstring const translateLayout(std::string const & msg) const;
75         /// default encoding
76         Encoding const * encoding() const { return encoding_; }
77         ///
78         std::string const encodingStr() const { return encodingStr_; }
79         /// language code
80         std::string const code() const { return code_; }
81         /// set code (needed for rc.spellchecker_alt_lang)
82         void setCode(std::string const & c) { code_ = c; }
83         /// language variety (needed by aspell checker)
84         std::string const variety() const { return variety_; }
85         /// set variety (needed for rc.spellchecker_alt_lang)
86         void setVariety(std::string const & v) { variety_ = v; }
87         /// preamble settings after babel was called
88         docstring babel_postsettings() const { return babel_postsettings_; }
89         /// preamble settings before babel is called
90         docstring babel_presettings() const { return babel_presettings_; }
91         /// This language internally sets a font encoding
92         bool internalFontEncoding() const { return internal_enc_; }
93         /// The most suitable font encoding(s) for the selected document font
94         std::string fontenc(BufferParams const &) const;
95         /// Return the localized date formats (long, medium, short format)
96         std::string dateFormat(size_t i) const;
97         /// Return the localized decimal separator
98         docstring decimalSeparator() const;
99         /// This language corresponds to a translation of the GUI
100         bool hasGuiSupport() const { return has_gui_support_; }
101         ///
102         bool read(Lexer & lex);
103         ///
104         bool readLanguage(Lexer & lex);
105         ///
106         typedef std::map<trivstring, trivdocstring> TranslationMap;
107         ///
108         void readLayoutTranslations(TranslationMap const & trans, bool replace);
109         // for the use in std::map
110         friend bool operator<(Language const & p, Language const & q);
111 private:
112         ///
113         trivstring lang_;
114         ///
115         trivstring babel_;
116         ///
117         trivstring polyglossia_name_;
118         ///
119         trivstring polyglossia_opts_;
120         ///
121         trivstring xindy_;
122         ///
123         trivstring quote_style_;
124         ///
125         trivstring active_chars_;
126         ///
127         trivstring required_;
128         ///
129         trivstring provides_;
130         ///
131         trivstring display_;
132         ///
133         bool rightToLeft_;
134         ///
135         trivstring encodingStr_;
136         ///
137         Encoding const * encoding_;
138         ///
139         trivstring code_;
140         ///
141         trivstring variety_;
142         ///
143         trivdocstring babel_postsettings_;
144         ///
145         trivdocstring babel_presettings_;
146         ///
147         std::vector<std::string> fontenc_;
148         ///
149         std::vector<std::string> dateformats_;
150         ///
151         bool internal_enc_;
152         ///
153         bool has_gui_support_;
154         ///
155         bool word_wrap_;
156         ///
157         TranslationMap layoutTranslations_;
158 };
159
160
161 inline bool operator<(Language const & p, Language const & q)
162 {
163         return q.lang() > p.lang();
164 }
165
166
167 class Languages
168 {
169 public:
170         ///
171         typedef std::map<trivstring, Language> LanguageList;
172         ///
173         typedef LanguageList::const_iterator const_iterator;
174         ///
175         typedef LanguageList::size_type size_type;
176         ///
177         void read(support::FileName const & filename);
178         ///
179         Language const * getFromCode(std::string const & code) const;
180         ///
181         Language const * getFromCode(std::string const & code,
182                         std::set<Language const *> const & tryfirst) const;
183         ///
184         void readLayoutTranslations(support::FileName const & filename);
185         ///
186         Language const * getLanguage(std::string const & language) const;
187         ///
188         size_type size() const { return languagelist_.size(); }
189         ///
190         const_iterator begin() const { return languagelist_.begin(); }
191         ///
192         const_iterator end() const { return languagelist_.end(); }
193
194 private:
195         ///
196         LanguageList languagelist_;
197 };
198
199 /// Global singleton instance.
200 extern Languages languages;
201 /// Default language defined in LyXRC
202 extern Language const * default_language;
203 /// Used to indicate that the language should be left unchanged when
204 /// applying a font change.
205 extern Language const * ignore_language;
206 /// Default language defined in LyXRC
207 extern Language const * latex_language;
208 /// Used to indicate that the language should be reset to the Buffer
209 // language when applying a font change.
210 extern Language const * reset_language;
211
212
213 } // namespace lyx
214
215 #endif