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