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