]> git.lyx.org Git - lyx.git/blob - src/Language.h
Don't update paths of non-existing files
[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) {}
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         ///
85         bool read(Lexer & lex);
86         ///
87         bool readLanguage(Lexer & lex);
88         ///
89         typedef std::map<trivstring, trivdocstring> TranslationMap;
90         ///
91         void readLayoutTranslations(TranslationMap const & trans, bool replace);
92         // for the use in std::map
93         friend bool operator<(Language const & p, Language const & q);
94 private:
95         ///
96         trivstring lang_;
97         ///
98         trivstring babel_;
99         ///
100         trivstring polyglossia_name_;
101         ///
102         trivstring polyglossia_opts_;
103         ///
104         trivstring quote_style_;
105         ///
106         trivstring requires_;
107         ///
108         trivstring display_;
109         ///
110         bool rightToLeft_;
111         ///
112         trivstring encodingStr_;
113         ///
114         Encoding const * encoding_;
115         ///
116         trivstring code_;
117         ///
118         trivstring variety_;
119         ///
120         trivstring babel_postsettings_;
121         ///
122         trivstring babel_presettings_;
123         ///
124         trivstring fontenc_;
125         ///
126         bool internal_enc_;
127         ///
128         bool as_babel_options_;
129         ///
130         TranslationMap layoutTranslations_;
131 };
132
133
134 inline bool operator<(Language const & p, Language const & q)
135 {
136         return q.lang() > p.lang();
137 }
138
139
140 class Languages
141 {
142 public:
143         ///
144         typedef std::map<trivstring, Language> LanguageList;
145         ///
146         typedef LanguageList::const_iterator const_iterator;
147         ///
148         typedef LanguageList::size_type size_type;
149         ///
150         void read(support::FileName const & filename);
151         ///
152         void readLayoutTranslations(support::FileName const & filename);
153         ///
154         Language const * getLanguage(std::string const & language) const;
155         ///
156         size_type size() const { return languagelist.size(); }
157         ///
158         const_iterator begin() const { return languagelist.begin(); }
159         ///
160         const_iterator end() const { return languagelist.end(); }
161         ///
162
163 private:
164         ///
165         LanguageList languagelist;
166 };
167
168 /// Global singleton instance.
169 extern Languages languages;
170 /// Default language defined in LyXRC
171 extern Language const * default_language;
172 /// Used to indicate that the language should be left unchanged when
173 /// applying a font change.
174 extern Language const * ignore_language;
175 /// Default language defined in LyXRC
176 extern Language const * latex_language;
177 /// Used to indicate that the language should be reset to the Buffer
178 // language when applying a font change.
179 extern Language const * reset_language;
180
181
182 } // namespace lyx
183
184 #endif