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