Jean-Marc Lasgouttes wrote:
> No objection in general, but did you check the uses of this de_DE entry
> in our code, to make sure that we handle gracefully the de-alt form? Are
> labels still translated on screen?

No, they're not, thanks.

Attached is a more sane approach that works and does not interfere with other 
uses of the language code.

The patch is against branch. Note that PSpell also supports varieties (oddly 
called "jargons"), but I think it's not worth implementing this. In trunk, 
PSpell has been removed anyway.

OK?

Jürgen

PS. I know that WordLangTuple is a triple now, strictly speaking. But I'd keep 
the naming for now.
Index: src/ASpell.cpp
===================================================================
--- src/ASpell.cpp	(Revision 33078)
+++ src/ASpell.cpp	(Arbeitskopie)
@@ -25,10 +25,11 @@
 
 namespace lyx {
 
-ASpell::ASpell(BufferParams const &, string const & lang)
+ASpell::ASpell(BufferParams const &, string const & lang,
+	       string const & variety)
 	: els(0), spell_error_object(0)
 {
-	addSpeller(lang);
+	addSpeller(lang, variety);
 }
 
 
@@ -53,11 +54,15 @@
 }
 
 
-void ASpell::addSpeller(string const & lang)
+void ASpell::addSpeller(string const & lang, string const & variety)
 {
 	AspellConfig * config = new_aspell_config();
-	// FIXME The aspell documentation says to use "lang"
-	aspell_config_replace(config, "language-tag", lang.c_str());
+	// Aspell supports both languages and varieties (such as German
+	// old vs. new spelling). The respective naming convention is
+	// lang_REGION-variety (e.g. de_DE-alt); so check for a variety:
+	aspell_config_replace(config, "lang", lang.c_str());
+	if (!variety.empty())
+		aspell_config_replace(config, "variety", variety.c_str());
 	// Set the encoding to utf-8.
 	// aspell does also understand "ucs-4", so we would not need a
 	// conversion in theory, but if this is used it expects all
@@ -81,7 +86,7 @@
 		Speller m;
 		m.speller = to_aspell_speller(err);
 		m.config = config;
-		spellers_[lang] = m;
+		spellers_[spellerID(lang, variety)] = m;
 	} else {
 		spell_error_object = err;
 	}
@@ -92,10 +97,13 @@
 {
 	Result res = UNKNOWN_WORD;
 
-	Spellers::iterator it = spellers_.find(word.lang_code());
+	string const speller =
+		spellerID(word.lang_code(), word.lang_variety());
+	
+	Spellers::iterator it = spellers_.find(speller);
 	if (it == spellers_.end()) {
-		addSpeller(word.lang_code());
-		it = spellers_.find(word.lang_code());
+		addSpeller(word.lang_code(), word.lang_variety());
+		it = spellers_.find(speller);
 		// FIXME
 		if (it == spellers_.end())
 			return res;
@@ -124,17 +132,21 @@
 
 void ASpell::insert(WordLangTuple const & word)
 {
-	Spellers::iterator it = spellers_.find(word.lang_code());
+	Spellers::iterator it =
+		spellers_.find(spellerID(word.lang_code(), word.lang_variety()));
 	if (it != spellers_.end())
-		aspell_speller_add_to_personal(it->second.speller, to_utf8(word.word()).c_str(), -1);
+		aspell_speller_add_to_personal(
+			it->second.speller, to_utf8(word.word()).c_str(), -1);
 }
 
 
 void ASpell::accept(WordLangTuple const & word)
 {
-	Spellers::iterator it = spellers_.find(word.lang_code());
+	Spellers::iterator it =
+		spellers_.find(spellerID(word.lang_code(), word.lang_variety()));
 	if (it != spellers_.end())
-		aspell_speller_add_to_session(it->second.speller, to_utf8(word.word()).c_str(), -1);
+		aspell_speller_add_to_session(
+			it->second.speller, to_utf8(word.word()).c_str(), -1);
 }
 
 
@@ -161,4 +173,12 @@
 }
 
 
+string const ASpell::spellerID(string const & lang, string const & variety)
+{
+	if (variety.empty())
+		return lang;
+	return lang + "-" + variety;
+}
+
+
 } // namespace lyx
Index: src/Language.cpp
===================================================================
--- src/Language.cpp	(Revision 33078)
+++ src/Language.cpp	(Arbeitskopie)
@@ -20,6 +20,7 @@
 
 #include "support/debug.h"
 #include "support/FileName.h"
+#include "support/lstrings.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -44,11 +45,13 @@
 	lex >> display_;
 	lex >> rightToLeft_;
 	lex >> encodingStr_;
-	lex >> code_;
+	lex >> codeStr_;
 	lex >> latex_options_;
 	if (!lex)
 		return false;
 
+	variety_ = split(codeStr_, code_, '-');
+
 	encoding_ = encodings.fromLyXName(encodingStr_);
 	if (!encoding_ && !encodingStr_.empty()) {
 		encoding_ = encodings.fromLyXName("iso8859-1");
Index: src/ASpell_local.h
===================================================================
--- src/ASpell_local.h	(Revision 33078)
+++ src/ASpell_local.h	(Arbeitskopie)
@@ -31,9 +31,11 @@
 class ASpell : public SpellBase {
 public:
 	/**
-	 * Initialise the spellchecker with the given buffer params and language.
+	 * Initialise the spellchecker with the given buffer params, language
+	 * and variety.
 	 */
-	ASpell(BufferParams const & params, std::string const & lang);
+	ASpell(BufferParams const & params, std::string const & lang,
+	       std::string const & variety = std::string());
 
 	virtual ~ASpell();
 
@@ -59,8 +61,9 @@
 	virtual docstring const error();
 
 private:
-	/// add a speller of the given language
-	void addSpeller(std::string const & lang);
+	/// add a speller of the given language and variety
+	void addSpeller(std::string const & lang,
+			std::string const & variety);
 
 	struct Speller {
 		AspellSpeller * speller;
@@ -76,6 +79,9 @@
 	AspellStringEnumeration * els;
 	/// FIXME
 	AspellCanHaveError * spell_error_object;
+	///
+	std::string const spellerID(std::string const & lang,
+				    std::string const & variety);
 };
 
 
Index: src/frontends/qt4/GuiSpellchecker.cpp
===================================================================
--- src/frontends/qt4/GuiSpellchecker.cpp	(Revision 33079)
+++ src/frontends/qt4/GuiSpellchecker.cpp	(Arbeitskopie)
@@ -222,13 +222,18 @@
 
 static SpellBase * createSpeller(BufferParams const & bp)
 {
-	string lang = (lyxrc.isp_use_alt_lang)
-		      ? lyxrc.isp_alt_lang
-		      : bp.language->code();
+	string lang;
+	string variety;
+	if (lyxrc.isp_use_alt_lang)
+		variety = split(lyxrc.isp_alt_lang, lang, '-');
+	else {
+	      lang = bp.language->code();
+	      variety = bp.language->variety();
+	}
 
 #if defined(USE_ASPELL)
 	if (lyxrc.use_spell_lib)
-		return new ASpell(bp, lang);
+		return new ASpell(bp, lang, variety);
 #elif defined(USE_PSPELL)
 	if (lyxrc.use_spell_lib)
 		return new PSpell(bp, lang);
@@ -301,6 +306,7 @@
 	cur.resetAnchor();
 	docstring word;
 	string lang_code;
+	string lang_variety;
 
 	while (cur.depth()) {
 		if (isLetter(cur)) {
@@ -309,7 +315,10 @@
 				ignoreword = false;
 				cur.resetAnchor();
 				word.clear();
-				lang_code = cur.paragraph().getFontSettings(bp, cur.pos()).language()->code();
+				lang_code = cur.paragraph().getFontSettings(
+					bp, cur.pos()).language()->code();
+				lang_variety = cur.paragraph().getFontSettings(
+					bp, cur.pos()).language()->variety();
 			}
 			// Insets like optional hyphens and ligature
 			// break are part of a word.
@@ -323,7 +332,7 @@
 			if (inword)
 				if (!word.empty() && !ignoreword) {
 					cur.setSelection();
-					return WordLangTuple(word, lang_code);
+					return WordLangTuple(word, lang_code, lang_variety);
 				}
 				inword = false;
 		}
Index: src/WordLangTuple.h
===================================================================
--- src/WordLangTuple.h	(Revision 33078)
+++ src/WordLangTuple.h	(Arbeitskopie)
@@ -19,15 +19,17 @@
 
 
 /**
- * A word and its given language code ("en_US").
+ * A word and its given language code ("en_US")
+ * plus a variety if needed.
  * This is used for spellchecking.
  */
 class WordLangTuple {
 public:
 	WordLangTuple() {}
 
-	WordLangTuple(docstring const & w, std::string const & c)
-		: word_(w), code_(c)
+	WordLangTuple(docstring const & w, std::string const & c,
+		      std::string const & v = std::string())
+		: word_(w), code_(c), variety_(v)
 	{}
 
 	/// return the word
@@ -40,11 +42,18 @@
 		return code_;
 	}
 
+	/// return the language variety
+	std::string const & lang_variety() const {
+		return variety_;
+	}
+
 private:
 	/// the word
 	docstring word_;
 	/// language code of word
 	std::string code_;
+	/// language variety of word
+	std::string variety_;
 };
 
 
Index: src/Language.h
===================================================================
--- src/Language.h	(Revision 33078)
+++ src/Language.h	(Arbeitskopie)
@@ -4,10 +4,10 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bj�nnes
+ * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
  * \author Dekel Tsur
- * \author J�rgen Vigna
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -46,6 +46,8 @@
 	///
 	std::string const & code() const { return code_; }
 	///
+	std::string const & variety() const { return variety_; }
+	///
 	std::string const & latex_options() const { return latex_options_; }
 	///
 	bool internalFontEncoding() const;
@@ -65,8 +67,12 @@
 	///
 	Encoding const * encoding_;
 	///
+	std::string codeStr_;
+	///
 	std::string code_;
 	///
+	std::string variety_;
+	///
 	std::string latex_options_;
 };
 
Index: lib/languages
===================================================================
--- lib/languages	(Revision 33078)
+++ lib/languages	(Arbeitskopie)
@@ -39,7 +39,7 @@
 # We redefine \og and \fg (guillemets) for older french language definitions
 french      french 	"French"	false  iso8859-15 fr_FR	 "\addto\extrasfrench{\providecommand{\og}{\leavevmode\flqq~}\providecommand{\fg}{\ifdim\lastskip>\...@\unskip\fi~\frqq}}"
 galician    galician	"Galician"	false  iso8859-15 gl_ES	 ""
-german      german	"German (old spelling)"	false  iso8859-15 de_DE	 ""
+german      german	"German (old spelling)"	false  iso8859-15 de-alt	 ""
 ngerman     ngerman	"German"	false  iso8859-15 de_DE	 ""
 greek       greek	"Greek"		false  iso8859-7  el_GR	 ""
 polutonikogreek polutonikogreek	"Greek (polytonic)"	false  iso8859-7  el_GR	 "\providecommand*{\perispomeni}{\char126}\addto\extraspolutonikogreek{\let\~\perispomeni}\addto\extrasgreek{\let\~\perispomeni}"

Reply via email to