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