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