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