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