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