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"
30 namespace support { class FileName; }
39 Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
40 has_gui_support_(false), word_wrap_(true) {}
42 std::string const lang() const { return lang_; }
43 /// Babel language name
44 std::string const babel() const { return babel_; }
45 /// polyglossia language name
46 std::string const polyglossia() const { return polyglossia_name_; }
47 /// polyglossia language options
48 std::string const polyglossiaOpts() const { return polyglossia_opts_; }
49 /// Is this language only supported by polyglossia?
50 bool isPolyglossiaExclusive() const;
51 /// Is this language only supported by babel?
52 bool isBabelExclusive() const;
53 /// quotation marks style
54 std::string const quoteStyle() const { return quote_style_; }
55 /// requirement (package, function)
56 std::string const requires() const { return requires_; }
58 std::string const provides() const { return provides_; }
59 /// translatable GUI name
60 std::string const display() const { return display_; }
61 /// is this a RTL language?
62 bool rightToLeft() const { return rightToLeft_; }
63 /// shall text be wrapped at word boundary ?
64 bool wordWrap() const { return word_wrap_; }
66 * Translate a string from the layout files that appears in the output.
67 * It takes the translations from lib/layouttranslations instead of
68 * the .mo files. This should be used for every translation that
69 * appears in the exported document, since the output must not depend
70 * on installed locales. Non-ASCII keys are not translated. */
71 docstring const translateLayout(std::string const & msg) const;
73 Encoding const * encoding() const { return encoding_; }
75 std::string const encodingStr() const { return encodingStr_; }
77 std::string const code() const { return code_; }
78 /// set code (needed for rc.spellchecker_alt_lang)
79 void setCode(std::string const & c) { code_ = c; }
80 /// language variety (needed by aspell checker)
81 std::string const variety() const { return variety_; }
82 /// set variety (needed for rc.spellchecker_alt_lang)
83 void setVariety(std::string const & v) { variety_ = v; }
84 /// preamble settings after babel was called
85 docstring babel_postsettings() const { return babel_postsettings_; }
86 /// preamble settings before babel is called
87 docstring babel_presettings() const { return babel_presettings_; }
88 /// This language internally sets a font encoding
89 bool internalFontEncoding() const { return internal_enc_; }
90 /// The most suitable font encoding(s) for the selected document font
91 std::string fontenc(BufferParams const &) const;
92 /// Return the localized date formats (long, medium, short format)
93 std::string dateFormat(size_t i) const;
94 /// This language corresponds to a translation of the GUI
95 bool hasGuiSupport() const { return has_gui_support_; }
97 bool read(Lexer & lex);
99 bool readLanguage(Lexer & lex);
101 typedef std::map<trivstring, trivdocstring> TranslationMap;
103 void readLayoutTranslations(TranslationMap const & trans, bool replace);
104 // for the use in std::map
105 friend bool operator<(Language const & p, Language const & q);
112 trivstring polyglossia_name_;
114 trivstring polyglossia_opts_;
116 trivstring quote_style_;
118 trivstring requires_;
120 trivstring provides_;
126 trivstring encodingStr_;
128 Encoding const * encoding_;
134 trivdocstring babel_postsettings_;
136 trivdocstring babel_presettings_;
138 std::vector<std::string> fontenc_;
140 std::vector<std::string> dateformats_;
144 bool has_gui_support_;
148 TranslationMap layoutTranslations_;
152 inline bool operator<(Language const & p, Language const & q)
154 return q.lang() > p.lang();
162 typedef std::map<trivstring, Language> LanguageList;
164 typedef LanguageList::const_iterator const_iterator;
166 typedef LanguageList::size_type size_type;
168 void read(support::FileName const & filename);
170 Language const * getFromCode(std::string const & code) const;
172 Language const * getFromCode(std::string const & code,
173 std::set<Language const *> const & tryfirst) const;
175 void readLayoutTranslations(support::FileName const & filename);
177 Language const * getLanguage(std::string const & language) const;
179 size_type size() const { return languagelist_.size(); }
181 const_iterator begin() const { return languagelist_.begin(); }
183 const_iterator end() const { return languagelist_.end(); }
187 LanguageList languagelist_;
190 /// Global singleton instance.
191 extern Languages languages;
192 /// Default language defined in LyXRC
193 extern Language const * default_language;
194 /// Used to indicate that the language should be left unchanged when
195 /// applying a font change.
196 extern Language const * ignore_language;
197 /// Default language defined in LyXRC
198 extern Language const * latex_language;
199 /// Used to indicate that the language should be reset to the Buffer
200 // language when applying a font change.
201 extern Language const * reset_language;