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