4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
18 #include "support/docstring.h"
19 #include "support/trivstring.h"
26 namespace support { class FileName; }
35 Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
36 as_babel_options_(false), has_gui_support_(false) {}
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_; }
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;
65 Encoding const * encoding() const { return encoding_; }
67 std::string const encodingStr() const { return encodingStr_; }
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_; }
89 bool read(Lexer & lex);
91 bool readLanguage(Lexer & lex);
93 typedef std::map<trivstring, trivdocstring> TranslationMap;
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);
104 trivstring polyglossia_name_;
106 trivstring polyglossia_opts_;
108 trivstring quote_style_;
110 trivstring requires_;
116 trivstring encodingStr_;
118 Encoding const * encoding_;
124 trivdocstring babel_postsettings_;
126 trivdocstring babel_presettings_;
132 bool as_babel_options_;
134 bool has_gui_support_;
136 TranslationMap layoutTranslations_;
140 inline bool operator<(Language const & p, Language const & q)
142 return q.lang() > p.lang();
150 typedef std::map<trivstring, Language> LanguageList;
152 typedef LanguageList::const_iterator const_iterator;
154 typedef LanguageList::size_type size_type;
156 void read(support::FileName const & filename);
158 void readLayoutTranslations(support::FileName const & filename);
160 Language const * getLanguage(std::string const & language) const;
162 size_type size() const { return languagelist.size(); }
164 const_iterator begin() const { return languagelist.begin(); }
166 const_iterator end() const { return languagelist.end(); }
170 LanguageList languagelist;
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;