2000-03-10 13:52:19 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Language.h
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Dekel Tsur
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
#ifndef LANGUAGE_H
|
|
|
|
#define LANGUAGE_H
|
|
|
|
|
2011-03-23 19:17:15 +00:00
|
|
|
#include "support/docstring.h"
|
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
#include <map>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
class Encoding;
|
2008-04-05 12:23:27 +00:00
|
|
|
class Lexer;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
///
|
|
|
|
class Language {
|
|
|
|
public:
|
|
|
|
///
|
2012-08-23 13:08:21 +00:00
|
|
|
Language() : rightToLeft_(false) {}
|
2010-11-16 11:07:43 +00:00
|
|
|
/// LyX language name
|
2005-07-16 12:02:31 +00:00
|
|
|
std::string const & lang() const { return lang_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// Babel language name
|
2005-07-16 12:02:31 +00:00
|
|
|
std::string const & babel() const { return babel_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// polyglossia language name
|
|
|
|
std::string const & polyglossia() const { return polyglossia_name_; }
|
|
|
|
/// polyglossia language options
|
|
|
|
std::string const & polyglossiaOpts() const { return polyglossia_opts_; }
|
2013-03-31 21:48:05 +00:00
|
|
|
/// Is this language only supported by polyglossia?
|
|
|
|
bool isPolyglossiaExclusive() const;
|
2012-07-01 09:25:52 +00:00
|
|
|
/// quotation marks style
|
|
|
|
std::string const & quoteStyle() const { return quote_style_; }
|
2012-06-09 09:32:34 +00:00
|
|
|
/// requirement (package, function)
|
|
|
|
std::string const & requires() const { return requires_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// translatable GUI name
|
2005-07-16 12:02:31 +00:00
|
|
|
std::string const & display() const { return display_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// is this a RTL language?
|
2006-04-09 00:26:19 +00:00
|
|
|
bool rightToLeft() const { return rightToLeft_; }
|
2011-03-23 19:17:15 +00:00
|
|
|
/**
|
|
|
|
* Translate a string from the layout files that appears in the output.
|
|
|
|
* It takes the translations from lib/layouttranslations instead of
|
|
|
|
* the .mo files. This should be used for every translation that
|
|
|
|
* appears in the exported document, since the output must not depend
|
|
|
|
* on installed locales. Non-ASCII keys are not translated. */
|
|
|
|
docstring const translateLayout(std::string const & msg) const;
|
2010-11-16 11:07:43 +00:00
|
|
|
/// default encoding
|
2005-07-16 12:02:31 +00:00
|
|
|
Encoding const * encoding() const { return encoding_; }
|
2000-09-22 15:09:51 +00:00
|
|
|
///
|
2005-07-16 15:55:36 +00:00
|
|
|
std::string const & encodingStr() const { return encodingStr_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// language code
|
2005-07-16 12:02:31 +00:00
|
|
|
std::string const & code() const { return code_; }
|
2010-02-09 11:26:49 +00:00
|
|
|
/// set code (needed for rc.spellchecker_alt_lang)
|
|
|
|
void setCode(std::string const c) { code_ = c; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// language variety (needed by aspell checker)
|
2010-01-18 17:02:05 +00:00
|
|
|
std::string const & variety() const { return variety_; }
|
2010-02-09 11:26:49 +00:00
|
|
|
/// set variety (needed for rc.spellchecker_alt_lang)
|
|
|
|
void setVariety(std::string const v) { variety_ = v; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// preamble settings after babel was called
|
2010-11-13 17:25:03 +00:00
|
|
|
std::string const & babel_postsettings() const { return babel_postsettings_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// preamble settings before babel is called
|
2010-11-14 09:54:24 +00:00
|
|
|
std::string const & babel_presettings() const { return babel_presettings_; }
|
2010-11-14 10:35:35 +00:00
|
|
|
/// This language internally sets a font encoding
|
2010-11-13 17:25:03 +00:00
|
|
|
bool internalFontEncoding() const { return internal_enc_; }
|
2010-11-14 10:35:35 +00:00
|
|
|
/// This language needs to be passed to babel itself (not the class)
|
|
|
|
bool asBabelOptions() const { return as_babel_options_; }
|
2008-11-21 14:58:26 +00:00
|
|
|
///
|
2008-04-05 12:23:27 +00:00
|
|
|
bool read(Lexer & lex);
|
2010-11-13 17:25:03 +00:00
|
|
|
///
|
|
|
|
bool readLanguage(Lexer & lex);
|
2011-03-23 19:17:15 +00:00
|
|
|
///
|
2011-03-24 19:40:54 +00:00
|
|
|
typedef std::map<std::string, docstring> TranslationMap;
|
2011-03-23 19:17:15 +00:00
|
|
|
///
|
2011-03-24 19:40:54 +00:00
|
|
|
void readLayoutTranslations(TranslationMap const & trans, bool replace);
|
2009-12-18 14:48:56 +00:00
|
|
|
// for the use in std::map
|
|
|
|
friend bool operator<(Language const & p, Language const & q);
|
2000-06-08 23:16:16 +00:00
|
|
|
private:
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string lang_;
|
2000-06-08 23:16:16 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string babel_;
|
2000-09-27 15:23:24 +00:00
|
|
|
///
|
2010-11-16 11:07:43 +00:00
|
|
|
std::string polyglossia_name_;
|
|
|
|
///
|
|
|
|
std::string polyglossia_opts_;
|
|
|
|
///
|
2012-07-01 09:25:52 +00:00
|
|
|
std::string quote_style_;
|
|
|
|
///
|
2012-06-09 09:32:34 +00:00
|
|
|
std::string requires_;
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string display_;
|
2000-06-08 23:16:16 +00:00
|
|
|
///
|
2005-07-16 12:02:31 +00:00
|
|
|
bool rightToLeft_;
|
2000-07-04 20:32:37 +00:00
|
|
|
///
|
2005-07-16 15:55:36 +00:00
|
|
|
std::string encodingStr_;
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
Encoding const * encoding_;
|
2000-09-22 15:09:51 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string code_;
|
2001-01-20 14:16:01 +00:00
|
|
|
///
|
2010-01-18 17:02:05 +00:00
|
|
|
std::string variety_;
|
|
|
|
///
|
2010-11-13 17:25:03 +00:00
|
|
|
std::string babel_postsettings_;
|
|
|
|
///
|
2010-11-14 09:54:24 +00:00
|
|
|
std::string babel_presettings_;
|
|
|
|
///
|
2010-11-13 17:25:03 +00:00
|
|
|
bool internal_enc_;
|
2010-11-14 10:35:35 +00:00
|
|
|
///
|
|
|
|
bool as_babel_options_;
|
2010-12-03 17:48:06 +00:00
|
|
|
///
|
2011-03-23 19:17:15 +00:00
|
|
|
TranslationMap layoutTranslations_;
|
2000-03-10 13:52:19 +00:00
|
|
|
};
|
|
|
|
|
2009-12-18 14:48:56 +00:00
|
|
|
|
|
|
|
inline bool operator<(Language const & p, Language const & q)
|
|
|
|
{
|
|
|
|
return q.lang() > p.lang();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
class Languages
|
2000-04-26 13:57:28 +00:00
|
|
|
{
|
2000-10-10 12:36:36 +00:00
|
|
|
public:
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
typedef std::map<std::string, Language> LanguageList;
|
2000-10-10 12:36:36 +00:00
|
|
|
///
|
|
|
|
typedef LanguageList::const_iterator const_iterator;
|
|
|
|
///
|
2001-03-21 13:27:03 +00:00
|
|
|
typedef LanguageList::size_type size_type;
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
void read(support::FileName const & filename);
|
2000-10-10 12:36:36 +00:00
|
|
|
///
|
2011-03-23 19:17:15 +00:00
|
|
|
void readLayoutTranslations(support::FileName const & filename);
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
Language const * getLanguage(std::string const & language) const;
|
2000-10-10 12:36:36 +00:00
|
|
|
///
|
2005-07-16 12:02:31 +00:00
|
|
|
size_type size() const { return languagelist.size(); }
|
2001-03-21 13:27:03 +00:00
|
|
|
///
|
2005-07-16 12:02:31 +00:00
|
|
|
const_iterator begin() const { return languagelist.begin(); }
|
2002-03-21 17:27:08 +00:00
|
|
|
///
|
2005-07-16 12:02:31 +00:00
|
|
|
const_iterator end() const { return languagelist.end(); }
|
2002-03-21 17:27:08 +00:00
|
|
|
///
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
LanguageList languagelist;
|
|
|
|
};
|
2000-04-26 13:57:28 +00:00
|
|
|
|
2008-05-07 18:53:48 +00:00
|
|
|
/// Global singleton instance.
|
2000-03-10 13:52:19 +00:00
|
|
|
extern Languages languages;
|
2008-05-07 18:53:48 +00:00
|
|
|
/// Default language defined in LyXRC
|
2000-03-17 10:14:46 +00:00
|
|
|
extern Language const * default_language;
|
2008-05-07 18:53:48 +00:00
|
|
|
/// Used to indicate that the language should be left unchanged when
|
|
|
|
/// applying a font change.
|
2001-03-21 13:27:03 +00:00
|
|
|
extern Language const * ignore_language;
|
2008-05-07 18:53:48 +00:00
|
|
|
/// Default language defined in LyXRC
|
2001-08-11 18:31:14 +00:00
|
|
|
extern Language const * latex_language;
|
2008-05-07 18:53:48 +00:00
|
|
|
/// Used to indicate that the language should be reset to the Buffer
|
|
|
|
// language when applying a font change.
|
|
|
|
extern Language const * reset_language;
|
2000-03-10 13:52:19 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
#endif
|