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
|
|
|
|
|
2018-04-22 17:06:46 +00:00
|
|
|
#include "BufferParams.h"
|
|
|
|
|
2011-03-23 19:17:15 +00:00
|
|
|
#include "support/docstring.h"
|
2014-12-07 17:26:44 +00:00
|
|
|
#include "support/trivstring.h"
|
2011-03-23 19:17:15 +00:00
|
|
|
|
2000-03-10 13:52:19 +00:00
|
|
|
#include <map>
|
2018-04-22 17:06:46 +00:00
|
|
|
#include <vector>
|
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:
|
|
|
|
///
|
2015-03-05 11:17:52 +00:00
|
|
|
Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
|
2015-05-07 15:20:23 +00:00
|
|
|
as_babel_options_(false), has_gui_support_(false) {}
|
2010-11-16 11:07:43 +00:00
|
|
|
/// LyX language name
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const lang() const { return lang_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// Babel language name
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const babel() const { return babel_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// polyglossia language name
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const polyglossia() const { return polyglossia_name_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// polyglossia language options
|
2014-12-07 17:26:44 +00:00
|
|
|
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;
|
2016-10-27 07:59:01 +00:00
|
|
|
/// Is this language only supported by babel?
|
|
|
|
bool isBabelExclusive() const;
|
2012-07-01 09:25:52 +00:00
|
|
|
/// quotation marks style
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const quoteStyle() const { return quote_style_; }
|
2012-06-09 09:32:34 +00:00
|
|
|
/// requirement (package, function)
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const requires() const { return requires_; }
|
2018-04-21 13:47:39 +00:00
|
|
|
/// provides feature
|
|
|
|
std::string const provides() const { return provides_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// translatable GUI name
|
2014-12-07 17:26:44 +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
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
std::string const encodingStr() const { return encodingStr_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// language code
|
2014-12-07 17:26:44 +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)
|
2014-07-05 17:13:10 +00:00
|
|
|
void setCode(std::string const & c) { code_ = c; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// language variety (needed by aspell checker)
|
2014-12-07 17:26:44 +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)
|
2014-07-05 17:13:10 +00:00
|
|
|
void setVariety(std::string const & v) { variety_ = v; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// preamble settings after babel was called
|
2016-09-25 10:37:40 +00:00
|
|
|
docstring babel_postsettings() const { return babel_postsettings_; }
|
2010-11-16 11:07:43 +00:00
|
|
|
/// preamble settings before babel is called
|
2016-09-25 10:37:40 +00:00
|
|
|
docstring 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_; }
|
2015-01-24 13:02:16 +00:00
|
|
|
/// fontenc encoding(s)
|
2018-04-22 17:06:46 +00:00
|
|
|
std::string fontenc(BufferParams const &) const;
|
|
|
|
/// fontenc encoding(s)
|
|
|
|
std::vector<std::string> fontencs() const;
|
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_; }
|
2016-01-20 16:40:47 +00:00
|
|
|
/// This language corresponds to a translation of the GUI
|
2015-05-07 15:20:23 +00:00
|
|
|
bool hasGuiSupport() const { return has_gui_support_; }
|
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
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
typedef std::map<trivstring, trivdocstring> 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:
|
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring lang_;
|
2000-06-08 23:16:16 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring babel_;
|
2000-09-27 15:23:24 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring polyglossia_name_;
|
2010-11-16 11:07:43 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring polyglossia_opts_;
|
2010-11-16 11:07:43 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring quote_style_;
|
2012-07-01 09:25:52 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring requires_;
|
2012-06-09 09:32:34 +00:00
|
|
|
///
|
2018-04-21 13:47:39 +00:00
|
|
|
trivstring provides_;
|
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring 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
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring encodingStr_;
|
2005-07-16 15:55:36 +00:00
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
Encoding const * encoding_;
|
2000-09-22 15:09:51 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring code_;
|
2001-01-20 14:16:01 +00:00
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
trivstring variety_;
|
2010-01-18 17:02:05 +00:00
|
|
|
///
|
2016-09-25 10:37:40 +00:00
|
|
|
trivdocstring babel_postsettings_;
|
2010-11-13 17:25:03 +00:00
|
|
|
///
|
2016-09-25 10:37:40 +00:00
|
|
|
trivdocstring babel_presettings_;
|
2010-11-14 09:54:24 +00:00
|
|
|
///
|
2018-04-22 17:06:46 +00:00
|
|
|
std::vector<std::string> fontenc_;
|
2015-01-24 13:02:16 +00:00
|
|
|
///
|
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
|
|
|
///
|
2015-05-07 15:20:23 +00:00
|
|
|
bool has_gui_support_;
|
|
|
|
///
|
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:
|
|
|
|
///
|
2014-12-07 17:26:44 +00:00
|
|
|
typedef std::map<trivstring, 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
|