Le 20/05/2015 15:19, Kornel Benko a écrit :
The sorting of languages is suboptimal. It was better in the original version.

For instance in Czech and Slovak the letters 'c' and 'č' follows immediately.
In the Slovak GUI the sort in the patch moves 'č' nearly to the end of the list

Here is a much simpler patch that should also fix the sorting problem.

Is it better?

JMarc



>From 5629dad309b54d20eea19458838c575dddf05896 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 7 May 2015 17:20:23 +0200
Subject: [PATCH] Improve list of available languages for UI l10n.

Add a new tag HasGuiSupport to language file. Add it for all l10ns
that we currently ship. The po files that are unused are not currently
tagged as available, but this could be done, since the code later
checks that the translation is actually there.

This new information is used in GuiPrefs when populating the language combox.
---
 lib/languages                  |   33 +++++++++++++++++++++++++++++++++
 src/Language.cpp               |    5 +++++
 src/Language.h                 |    7 +++++--
 src/frontends/qt4/GuiPrefs.cpp |   16 ++++++----------
 4 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/lib/languages b/lib/languages
index 06d3c0f..b32bc15 100644
--- a/lib/languages
+++ b/lib/languages
@@ -141,6 +141,7 @@ End
 # to switch the language the way of the ArabTeX-package
 Language arabic_arabtex
 	GuiName          "Arabic (ArabTeX)"
+	HasGuiSupport    true
 	BabelName        arabtex
 	QuoteStyle       french
 	Encoding         cp1256
@@ -206,6 +207,7 @@ End
 
 Language bahasa
 	GuiName          "Indonesian"
+	HasGuiSupport    true
 	BabelName        bahasa
 	PolyglossiaName  bahasai
 	QuoteStyle       english
@@ -224,6 +226,7 @@ End
 
 Language basque
 	GuiName          "Basque"
+	HasGuiSupport    true
 	BabelName        basque
 	PolyglossiaName  basque
 	QuoteStyle       french
@@ -246,6 +249,7 @@ End
 
 Language brazilian
 	GuiName          "Portuguese (Brazil)"
+	HasGuiSupport    true
 	BabelName        brazil
 	PolyglossiaName  brazil
 	QuoteStyle       english
@@ -305,6 +309,7 @@ End
 
 Language catalan
 	GuiName          "Catalan"
+	HasGuiSupport    true
 	BabelName        catalan
 	PolyglossiaName  catalan
 	PolyglossiaOpts  "babelshorthands=true"
@@ -316,6 +321,7 @@ End
 # uses CJK package
 Language chinese-simplified
 	GuiName          "Chinese (simplified)"
+	HasGuiSupport    true
 	Encoding         euc-cn
 	QuoteStyle       english
 	LangCode         zh_CN
@@ -325,6 +331,7 @@ End
 # uses CJK package
 Language chinese-traditional
 	GuiName         "Chinese (traditional)"
+	HasGuiSupport    true
 	QuoteStyle       english
 	Encoding        utf8-cjk
 	LangCode        zh_TW
@@ -350,6 +357,7 @@ End
 
 Language czech
 	GuiName          "Czech"
+	HasGuiSupport    true
 	BabelName        czech
 	PolyglossiaName  czech
 	QuoteStyle       german
@@ -359,6 +367,7 @@ End
 
 Language danish
 	GuiName          "Danish"
+	HasGuiSupport    true
 	BabelName        danish
 	PolyglossiaName  danish
 	QuoteStyle       danish
@@ -376,6 +385,7 @@ End
 
 Language dutch
 	GuiName          "Dutch"
+	HasGuiSupport    true
 	BabelName        dutch
 	PolyglossiaName  dutch
 	PolyglossiaOpts  "babelshorthands=true"
@@ -386,6 +396,7 @@ End
 
 Language english
 	GuiName          "English"
+	HasGuiSupport    true
 	BabelName        english
 	PolyglossiaName  english
 	QuoteStyle       english
@@ -434,6 +445,7 @@ End
 
 Language finnish
 	GuiName          "Finnish"
+	HasGuiSupport    true
 	BabelName        finnish
 	PolyglossiaName  finnish
 	QuoteStyle       swedish
@@ -444,6 +456,7 @@ End
 # We redefine \og and \fg (guillemets) for older french language definitions
 Language french
 	GuiName          "French"
+	HasGuiSupport    true
 	BabelName        french
 	PolyglossiaName  french
 	QuoteStyle       french
@@ -459,6 +472,7 @@ End
 
 Language galician
 	GuiName          "Galician"
+	HasGuiSupport    true
 	BabelName        galician
 	PolyglossiaName  galician
 	QuoteStyle       french
@@ -493,6 +507,7 @@ End
 
 Language ngerman
 	GuiName          "German"
+	HasGuiSupport    true
 	BabelName        ngerman
 	PolyglossiaName  german
 	PolyglossiaOpts  "babelshorthands=true"
@@ -532,6 +547,7 @@ End
 
 Language greek
 	GuiName           "Greek"
+	HasGuiSupport     true
 	BabelName         greek
 	PolyglossiaName   greek
 	QuoteStyle        french
@@ -555,6 +571,7 @@ End
 
 Language hebrew
 	GuiName           "Hebrew"
+	HasGuiSupport     true
 	BabelName         hebrew
 	PolyglossiaName   hebrew
 	Encoding          cp1255
@@ -599,6 +616,7 @@ End
 # language. We therefore the name of its hunspell dictionary.
 Language interlingua
 	GuiName          "Interlingua"
+	HasGuiSupport    true
 	BabelName        interlingua
 	PolyglossiaName  interlingua
 	Encoding         iso8859-15
@@ -616,6 +634,7 @@ End
 
 Language italian
 	GuiName          "Italian"
+	HasGuiSupport    true
 	BabelName        italian
 	PolyglossiaName  italian
 	QuoteStyle       french
@@ -630,6 +649,7 @@ End
 # InternalEncoding to true.
 Language japanese
 	GuiName          "Japanese"
+	HasGuiSupport    true
 	BabelName        japanese
 	Encoding         jis-platex
 	LangCode         ja_JP
@@ -729,6 +749,7 @@ End
 
 Language magyar
 	GuiName          "Hungarian"
+	HasGuiSupport    true
 	BabelName        magyar
 	PolyglossiaName  magyar
 	QuoteStyle       polish
@@ -767,6 +788,7 @@ End
 
 Language norsk
 	GuiName          "Norwegian (Bokmaal)"
+	HasGuiSupport    true
 	BabelName        norsk
 	PolyglossiaName  norsk
 	QuoteStyle       french
@@ -776,6 +798,7 @@ End
 
 Language nynorsk
 	GuiName          "Norwegian (Nynorsk)"
+	HasGuiSupport    true
 	BabelName        nynorsk
 	PolyglossiaName  nynorsk
 	QuoteStyle       french
@@ -804,6 +827,7 @@ End
 
 Language polish
 	GuiName          "Polish"
+	HasGuiSupport    true
 	BabelName        polish
 	PolyglossiaName  polish
 	QuoteStyle       polish
@@ -813,6 +837,7 @@ End
 
 Language portuguese
 	GuiName          "Portuguese"
+	HasGuiSupport    true
 	BabelName        portuges
 	PolyglossiaName  portuges
 	QuoteStyle       english
@@ -822,6 +847,7 @@ End
 
 Language romanian
 	GuiName          "Romanian"
+	HasGuiSupport    true
 	BabelName        romanian
 	PolyglossiaName  romanian
 	QuoteStyle       polish
@@ -831,6 +857,7 @@ End
 
 Language russian
 	GuiName          "Russian"
+	HasGuiSupport    true
 	BabelName        russian
 	PolyglossiaName  russian
 	QuoteStyle       french
@@ -867,6 +894,7 @@ End
 
 Language serbian
 	GuiName          "Serbian"
+	HasGuiSupport    true
 	BabelName        serbianc
 	PolyglossiaName  serbian
 	QuoteStyle       german
@@ -887,6 +915,7 @@ End
 
 Language slovak
 	GuiName          "Slovak"
+	HasGuiSupport    true
 	BabelName        slovak
 	PolyglossiaName  slovak
 	QuoteStyle       german
@@ -905,6 +934,7 @@ End
 
 Language spanish
 	GuiName          "Spanish"
+	HasGuiSupport    true
 	BabelName        spanish
 	PolyglossiaName  spanish
 	QuoteStyle       french
@@ -930,6 +960,7 @@ End
 
 Language swedish
 	GuiName          "Swedish"
+	HasGuiSupport    true
 	BabelName        swedish
 	PolyglossiaName  swedish
 	QuoteStyle       swedish
@@ -984,6 +1015,7 @@ End
 
 Language turkish
 	GuiName          "Turkish"
+	HasGuiSupport    true
 	BabelName        turkish
 	PolyglossiaName  turkish
 	QuoteStyle       french
@@ -1008,6 +1040,7 @@ End
 
 Language ukrainian
 	GuiName          "Ukrainian"
+	HasGuiSupport    true
 	BabelName        ukrainian
 	PolyglossiaName  ukrainian
 	QuoteStyle       french
diff --git a/src/Language.cpp b/src/Language.cpp
index 28ce4e2..dc38bfc 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -74,6 +74,7 @@ bool Language::readLanguage(Lexer & lex)
 		LA_END,
 		LA_FONTENC,
 		LA_GUINAME,
+		LA_HAS_GUI_SUPPORT,
 		LA_INTERNAL_ENC,
 		LA_LANG_CODE,
 		LA_LANG_VARIETY,
@@ -94,6 +95,7 @@ bool Language::readLanguage(Lexer & lex)
 		{ "end",                  LA_END },
 		{ "fontencoding",         LA_FONTENC },
 		{ "guiname",              LA_GUINAME },
+		{ "hasguisupport",        LA_HAS_GUI_SUPPORT },
 		{ "internalencoding",     LA_INTERNAL_ENC },
 		{ "langcode",             LA_LANG_CODE },
 		{ "langvariety",          LA_LANG_VARIETY },
@@ -153,6 +155,9 @@ bool Language::readLanguage(Lexer & lex)
 		case LA_GUINAME:
 			lex >> display_;
 			break;
+		case LA_HAS_GUI_SUPPORT:
+			lex >> has_gui_support_;
+			break;
 		case LA_INTERNAL_ENC:
 			lex >> internal_enc_;
 			break;
diff --git a/src/Language.h b/src/Language.h
index b532d9c..2a9ebb3 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -33,7 +33,7 @@ class Language {
 public:
 	///
 	Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
-				 as_babel_options_(false) {}
+				 as_babel_options_(false), has_gui_support_(false) {}
 	/// LyX language name
 	std::string const lang() const { return lang_; }
 	/// Babel language name
@@ -81,6 +81,8 @@ public:
 	std::string const fontenc() const { return fontenc_; }
 	/// This language needs to be passed to babel itself (not the class)
 	bool asBabelOptions() const { return as_babel_options_; }
+	/// This language correspongs to a translation of the GUI
+	bool hasGuiSupport() const { return has_gui_support_; }
 	///
 	bool read(Lexer & lex);
 	///
@@ -127,6 +129,8 @@ private:
 	///
 	bool as_babel_options_;
 	///
+	bool has_gui_support_;
+	///
 	TranslationMap layoutTranslations_;
 };
 
@@ -158,7 +162,6 @@ public:
 	const_iterator begin() const { return languagelist.begin(); }
 	///
 	const_iterator end() const { return languagelist.end(); }
-	///
 
 private:
 	///
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index 1836501..23e42f1 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -2309,19 +2309,16 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
 	startCommandED->setValidator(new NoNewLineValidator(startCommandED));
 	endCommandED->setValidator(new NoNewLineValidator(endCommandED));
 
-	uiLanguageCO->clear();
-
-	QAbstractItemModel * language_model = guiApp->languageModel();
-	// FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
-	language_model->sort(0);
 	defaultDecimalPointLE->setInputMask("X; ");
 	defaultDecimalPointLE->setMaxLength(1);
 
 	defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM);
 	defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::IN]), Length::IN);
 
-	set<string> added;
+	QAbstractItemModel * language_model = guiApp->languageModel();
+	language_model->sort(0);
 	uiLanguageCO->blockSignals(true);
+	uiLanguageCO->clear();
 	uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
 	for (int i = 0; i != language_model->rowCount(); ++i) {
 		QModelIndex index = language_model->index(i, 0);
@@ -2335,11 +2332,10 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
 		if (name != form->rc().gui_language
 		    && name != lyxrc.gui_language
 		    && (!Messages::available(lang->code())
-			|| added.find(lang->code()) != added.end()))
-				continue;
-		added.insert(lang->code());
+		        || !lang->hasGuiSupport()))
+			continue;
 		uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
-			index.data(Qt::UserRole).toString());
+		                      index.data(Qt::UserRole).toString());
 	}
 	uiLanguageCO->blockSignals(false);
 }
-- 
1.7.9.5

Reply via email to