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 "BufferParams.h"
20 #include "support/docstring.h"
21 #include "support/trivstring.h"
29 namespace support { class FileName; }
38 Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
39 as_babel_options_(false), has_gui_support_(false) {}
41 std::string const lang() const { return lang_; }
42 /// Babel language name
43 std::string const babel() const { return babel_; }
44 /// polyglossia language name
45 std::string const polyglossia() const { return polyglossia_name_; }
46 /// polyglossia language options
47 std::string const polyglossiaOpts() const { return polyglossia_opts_; }
48 /// Is this language only supported by polyglossia?
49 bool isPolyglossiaExclusive() const;
50 /// Is this language only supported by babel?
51 bool isBabelExclusive() const;
52 /// quotation marks style
53 std::string const quoteStyle() const { return quote_style_; }
54 /// requirement (package, function)
55 std::string const requires() const { return requires_; }
57 std::string const provides() const { return provides_; }
58 /// translatable GUI name
59 std::string const display() const { return display_; }
60 /// is this a RTL language?
61 bool rightToLeft() const { return rightToLeft_; }
63 * Translate a string from the layout files that appears in the output.
64 * It takes the translations from lib/layouttranslations instead of
65 * the .mo files. This should be used for every translation that
66 * appears in the exported document, since the output must not depend
67 * on installed locales. Non-ASCII keys are not translated. */
68 docstring const translateLayout(std::string const & msg) const;
70 Encoding const * encoding() const { return encoding_; }
72 std::string const encodingStr() const { return encodingStr_; }
74 std::string const code() const { return code_; }
75 /// set code (needed for rc.spellchecker_alt_lang)
76 void setCode(std::string const & c) { code_ = c; }
77 /// language variety (needed by aspell checker)
78 std::string const variety() const { return variety_; }
79 /// set variety (needed for rc.spellchecker_alt_lang)
80 void setVariety(std::string const & v) { variety_ = v; }
81 /// preamble settings after babel was called
82 docstring babel_postsettings() const { return babel_postsettings_; }
83 /// preamble settings before babel is called
84 docstring babel_presettings() const { return babel_presettings_; }
85 /// This language internally sets a font encoding
86 bool internalFontEncoding() const { return internal_enc_; }
87 /// The most suitable font encoding(s) for the selected document font
88 std::string fontenc(BufferParams const &) const;
89 /// Return the localized date formats (long, medium, short format)
90 std::string dateFormat(size_t i) const;
91 /// This language needs to be passed to babel itself (not the class)
92 bool asBabelOptions() const { return as_babel_options_; }
93 /// This language corresponds to a translation of the GUI
94 bool hasGuiSupport() const { return has_gui_support_; }
96 bool read(Lexer & lex);
98 bool readLanguage(Lexer & lex);
100 typedef std::map<trivstring, trivdocstring> TranslationMap;
102 void readLayoutTranslations(TranslationMap const & trans, bool replace);
103 // for the use in std::map
104 friend bool operator<(Language const & p, Language const & q);
111 trivstring polyglossia_name_;
113 trivstring polyglossia_opts_;
115 trivstring quote_style_;
117 trivstring requires_;
119 trivstring provides_;
125 trivstring encodingStr_;
127 Encoding const * encoding_;
133 trivdocstring babel_postsettings_;
135 trivdocstring babel_presettings_;
137 std::vector<std::string> fontenc_;
139 std::vector<std::string> dateformats_;
143 bool as_babel_options_;
145 bool has_gui_support_;
147 TranslationMap layoutTranslations_;
151 inline bool operator<(Language const & p, Language const & q)
153 return q.lang() > p.lang();
161 typedef std::map<trivstring, Language> LanguageList;
163 typedef LanguageList::const_iterator const_iterator;
165 typedef LanguageList::size_type size_type;
167 void read(support::FileName const & filename);
169 Language const * getFromCode(std::string const & code) const;
171 void readLayoutTranslations(support::FileName const & filename);
173 Language const * getLanguage(std::string const & language) const;
175 size_type size() const { return languagelist.size(); }
177 const_iterator begin() const { return languagelist.begin(); }
179 const_iterator end() const { return languagelist.end(); }
183 LanguageList languagelist;
186 /// Global singleton instance.
187 extern Languages languages;
188 /// Default language defined in LyXRC
189 extern Language const * default_language;
190 /// Used to indicate that the language should be left unchanged when
191 /// applying a font change.
192 extern Language const * ignore_language;
193 /// Default language defined in LyXRC
194 extern Language const * latex_language;
195 /// Used to indicate that the language should be reset to the Buffer
196 // language when applying a font change.
197 extern Language const * reset_language;