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