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"
28 namespace support { class FileName; }
38 Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
39 has_gui_support_(false), word_wrap_(true) {}
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 /// polyglossia language options
49 std::string const xindy() const { return xindy_; }
50 /// Is this language only supported by polyglossia?
51 bool isPolyglossiaExclusive() const;
52 /// Is this language only supported by babel?
53 bool isBabelExclusive() const;
54 /// quotation marks style
55 std::string const quoteStyle() const { return quote_style_; }
57 std::string const activeChars() const { return active_chars_; }
58 /// requirement (package, function)
59 std::string const required() const { return required_; }
61 std::string const provides() const { return provides_; }
62 /// translatable GUI name
63 std::string const display() const { return display_; }
64 /// is this a RTL language?
65 bool rightToLeft() const { return rightToLeft_; }
66 /// shall text be wrapped at word boundary ?
67 bool wordWrap() const { return word_wrap_; }
69 * Translate a string from the layout files that appears in the output.
70 * It takes the translations from lib/layouttranslations instead of
71 * the .mo files. This should be used for every translation that
72 * appears in the exported document, since the output must not depend
73 * on installed locales. Non-ASCII keys are not translated. */
74 docstring const translateLayout(std::string const & msg) const;
76 Encoding const * encoding() const { return encoding_; }
78 std::string const encodingStr() const { return encodingStr_; }
80 std::string const code() const { return code_; }
81 /// set code (needed for rc.spellchecker_alt_lang)
82 void setCode(std::string const & c) { code_ = c; }
83 /// language variety (needed by aspell checker)
84 std::string const variety() const { return variety_; }
85 /// set variety (needed for rc.spellchecker_alt_lang)
86 void setVariety(std::string const & v) { variety_ = v; }
87 /// preamble settings after babel was called
88 docstring babel_postsettings() const { return babel_postsettings_; }
89 /// preamble settings before babel is called
90 docstring babel_presettings() const { return babel_presettings_; }
91 /// This language internally sets a font encoding
92 bool internalFontEncoding() const { return internal_enc_; }
93 /// The most suitable font encoding(s) for the selected document font
94 std::string fontenc(BufferParams const &) const;
95 /// Return the localized date formats (long, medium, short format)
96 std::string dateFormat(size_t i) const;
97 /// Return the localized decimal separator
98 docstring decimalSeparator() const;
99 /// This language corresponds to a translation of the GUI
100 bool hasGuiSupport() const { return has_gui_support_; }
102 bool read(Lexer & lex);
104 bool readLanguage(Lexer & lex);
106 typedef std::map<trivstring, trivdocstring> TranslationMap;
108 void readLayoutTranslations(TranslationMap const & trans, bool replace);
109 // for the use in std::map
110 friend bool operator<(Language const & p, Language const & q);
117 trivstring polyglossia_name_;
119 trivstring polyglossia_opts_;
123 trivstring quote_style_;
125 trivstring active_chars_;
127 trivstring required_;
129 trivstring provides_;
135 trivstring encodingStr_;
137 Encoding const * encoding_;
143 trivdocstring babel_postsettings_;
145 trivdocstring babel_presettings_;
147 std::vector<std::string> fontenc_;
149 std::vector<std::string> dateformats_;
153 bool has_gui_support_;
157 TranslationMap layoutTranslations_;
161 inline bool operator<(Language const & p, Language const & q)
163 return q.lang() > p.lang();
171 typedef std::map<trivstring, Language> LanguageList;
173 typedef LanguageList::const_iterator const_iterator;
175 typedef LanguageList::size_type size_type;
177 void read(support::FileName const & filename);
179 Language const * getFromCode(std::string const & code) const;
181 Language const * getFromCode(std::string const & code,
182 std::set<Language const *> const & tryfirst) const;
184 void readLayoutTranslations(support::FileName const & filename);
186 Language const * getLanguage(std::string const & language) const;
188 size_type size() const { return languagelist_.size(); }
190 const_iterator begin() const { return languagelist_.begin(); }
192 const_iterator end() const { return languagelist_.end(); }
196 LanguageList languagelist_;
199 /// Global singleton instance.
200 extern Languages languages;
201 /// Default language defined in LyXRC
202 extern Language const * default_language;
203 /// Used to indicate that the language should be left unchanged when
204 /// applying a font change.
205 extern Language const * ignore_language;
206 /// Default language defined in LyXRC
207 extern Language const * latex_language;
208 /// Used to indicate that the language should be reset to the Buffer
209 // language when applying a font change.
210 extern Language const * reset_language;