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.

The new scheme implies that adding a new language is now a two-step
process:
* the language code has to be added to po/LINGUAS, as before;
* one of the entries of the lib/language file has to be selected as
  reference and be given the "HasGuiSupport true" property.
This commit is contained in:
Jean-Marc Lasgouttes 2015-05-07 17:20:23 +02:00
parent f70e78487e
commit 88609b3984
5 changed files with 82 additions and 30 deletions

View File

@ -94,9 +94,10 @@ In order to test your translation you need to obtain the LyX sources
(from the git repository) and replace the existing .po with yours. (from the git repository) and replace the existing .po with yours.
Afterwards, you should compile and optionally install LyX (check the Afterwards, you should compile and optionally install LyX (check the
INSTALL file for your OS). Note that, as of LyX 2.1, it is not INSTALL file for your OS). Note that, as of LyX 2.1, it is not
necessary anymore to install anything. In order to run LyX with your necessary anymore to install anything.
translation, change the current language in Preferences dialog or use
the appropriate LANG variable: In order to run LyX with your translation, change the current language
in Preferences dialog or use the appropriate LANG variable:
On Linux: LANG=xx_CC lyx On Linux: LANG=xx_CC lyx
On Windows, you need to change the lyx.bat file and write: set LANG=xx_CC On Windows, you need to change the lyx.bat file and write: set LANG=xx_CC
@ -104,6 +105,12 @@ the appropriate LANG variable:
xx stands for your language code. CC stands for your country code. So to get, xx stands for your language code. CC stands for your country code. So to get,
e.g., Czech, the code is "cs_CZ". e.g., Czech, the code is "cs_CZ".
Another possibility is to use the Preferences dialog to set LyX UI to
use your language. Note that, as of LyX 2.2, a newly introduced
language will not appear in the languages combox unless it corresponds
to an entry of the lib/languages file that has a "HasGuiSupport true"
property. See this file for more details.
The most comfortable way to see your updated translation while The most comfortable way to see your updated translation while
editing, is running (in linux) "make xx.gmo" in the po directory to editing, is running (in linux) "make xx.gmo" in the po directory to
compile updated xx.po translation and then run LyX. compile updated xx.po translation and then run LyX.

View File

@ -6,6 +6,7 @@
# #
# Language <lyxname> # Language <lyxname>
# GuiName "<Gui Name>" # GuiName "<Gui Name>"
# HasGuiSupport <true|false>
# BabelName <babelname> # BabelName <babelname>
# PolyglossiaName <polyglossianame> # PolyglossiaName <polyglossianame>
# PolyglossiaOpts "<language-specific options>" # PolyglossiaOpts "<language-specific options>"
@ -31,6 +32,13 @@
# #
# * Omitted elements will be treated as empty (if string) or "false" # * Omitted elements will be treated as empty (if string) or "false"
# (if boolean). # (if boolean).
# * When HasGuiSupport is true, the language is candidate to appear in
# the list of possible GUI languages in the Preferences dialog. It
# will actually appear there only if a corresponding .mo file can be
# found among the translations. When several languages correspond to
# the same translation -- like English, English (US) and English
# (UK) -- try to select the entry that is most generic -- here
# English.
# * The QuoteStyle arguments correspond to the following styles: # * The QuoteStyle arguments correspond to the following styles:
# - danish: >>text<< >text< (inward guillemets) # - danish: >>text<< >text< (inward guillemets)
# - english: ``text'' `text' (66_99) # - english: ``text'' `text' (66_99)
@ -141,6 +149,7 @@ End
# to switch the language the way of the ArabTeX-package # to switch the language the way of the ArabTeX-package
Language arabic_arabtex Language arabic_arabtex
GuiName "Arabic (ArabTeX)" GuiName "Arabic (ArabTeX)"
HasGuiSupport true
BabelName arabtex BabelName arabtex
QuoteStyle french QuoteStyle french
Encoding cp1256 Encoding cp1256
@ -206,6 +215,7 @@ End
Language bahasa Language bahasa
GuiName "Indonesian" GuiName "Indonesian"
HasGuiSupport true
BabelName bahasa BabelName bahasa
PolyglossiaName bahasai PolyglossiaName bahasai
QuoteStyle english QuoteStyle english
@ -224,6 +234,7 @@ End
Language basque Language basque
GuiName "Basque" GuiName "Basque"
HasGuiSupport true
BabelName basque BabelName basque
PolyglossiaName basque PolyglossiaName basque
QuoteStyle french QuoteStyle french
@ -246,6 +257,7 @@ End
Language brazilian Language brazilian
GuiName "Portuguese (Brazil)" GuiName "Portuguese (Brazil)"
HasGuiSupport true
BabelName brazil BabelName brazil
PolyglossiaName brazil PolyglossiaName brazil
QuoteStyle english QuoteStyle english
@ -305,6 +317,7 @@ End
Language catalan Language catalan
GuiName "Catalan" GuiName "Catalan"
HasGuiSupport true
BabelName catalan BabelName catalan
PolyglossiaName catalan PolyglossiaName catalan
PolyglossiaOpts "babelshorthands=true" PolyglossiaOpts "babelshorthands=true"
@ -316,6 +329,7 @@ End
# uses CJK package # uses CJK package
Language chinese-simplified Language chinese-simplified
GuiName "Chinese (simplified)" GuiName "Chinese (simplified)"
HasGuiSupport true
Encoding euc-cn Encoding euc-cn
QuoteStyle english QuoteStyle english
LangCode zh_CN LangCode zh_CN
@ -325,6 +339,7 @@ End
# uses CJK package # uses CJK package
Language chinese-traditional Language chinese-traditional
GuiName "Chinese (traditional)" GuiName "Chinese (traditional)"
HasGuiSupport true
QuoteStyle english QuoteStyle english
Encoding utf8-cjk Encoding utf8-cjk
LangCode zh_TW LangCode zh_TW
@ -350,6 +365,7 @@ End
Language czech Language czech
GuiName "Czech" GuiName "Czech"
HasGuiSupport true
BabelName czech BabelName czech
PolyglossiaName czech PolyglossiaName czech
QuoteStyle german QuoteStyle german
@ -359,6 +375,7 @@ End
Language danish Language danish
GuiName "Danish" GuiName "Danish"
HasGuiSupport true
BabelName danish BabelName danish
PolyglossiaName danish PolyglossiaName danish
QuoteStyle danish QuoteStyle danish
@ -376,6 +393,7 @@ End
Language dutch Language dutch
GuiName "Dutch" GuiName "Dutch"
HasGuiSupport true
BabelName dutch BabelName dutch
PolyglossiaName dutch PolyglossiaName dutch
PolyglossiaOpts "babelshorthands=true" PolyglossiaOpts "babelshorthands=true"
@ -386,6 +404,7 @@ End
Language english Language english
GuiName "English" GuiName "English"
HasGuiSupport true
BabelName english BabelName english
PolyglossiaName english PolyglossiaName english
QuoteStyle english QuoteStyle english
@ -434,6 +453,7 @@ End
Language finnish Language finnish
GuiName "Finnish" GuiName "Finnish"
HasGuiSupport true
BabelName finnish BabelName finnish
PolyglossiaName finnish PolyglossiaName finnish
QuoteStyle swedish QuoteStyle swedish
@ -444,6 +464,7 @@ End
# We redefine \og and \fg (guillemets) for older french language definitions # We redefine \og and \fg (guillemets) for older french language definitions
Language french Language french
GuiName "French" GuiName "French"
HasGuiSupport true
BabelName french BabelName french
PolyglossiaName french PolyglossiaName french
QuoteStyle french QuoteStyle french
@ -459,6 +480,7 @@ End
Language galician Language galician
GuiName "Galician" GuiName "Galician"
HasGuiSupport true
BabelName galician BabelName galician
PolyglossiaName galician PolyglossiaName galician
QuoteStyle french QuoteStyle french
@ -493,6 +515,7 @@ End
Language ngerman Language ngerman
GuiName "German" GuiName "German"
HasGuiSupport true
BabelName ngerman BabelName ngerman
PolyglossiaName german PolyglossiaName german
PolyglossiaOpts "babelshorthands=true" PolyglossiaOpts "babelshorthands=true"
@ -532,6 +555,7 @@ End
Language greek Language greek
GuiName "Greek" GuiName "Greek"
HasGuiSupport true
BabelName greek BabelName greek
PolyglossiaName greek PolyglossiaName greek
QuoteStyle french QuoteStyle french
@ -555,6 +579,7 @@ End
Language hebrew Language hebrew
GuiName "Hebrew" GuiName "Hebrew"
HasGuiSupport true
BabelName hebrew BabelName hebrew
PolyglossiaName hebrew PolyglossiaName hebrew
Encoding cp1255 Encoding cp1255
@ -599,6 +624,7 @@ End
# language. We therefore the name of its hunspell dictionary. # language. We therefore the name of its hunspell dictionary.
Language interlingua Language interlingua
GuiName "Interlingua" GuiName "Interlingua"
HasGuiSupport true
BabelName interlingua BabelName interlingua
PolyglossiaName interlingua PolyglossiaName interlingua
Encoding iso8859-15 Encoding iso8859-15
@ -616,6 +642,7 @@ End
Language italian Language italian
GuiName "Italian" GuiName "Italian"
HasGuiSupport true
BabelName italian BabelName italian
PolyglossiaName italian PolyglossiaName italian
QuoteStyle french QuoteStyle french
@ -630,6 +657,7 @@ End
# InternalEncoding to true. # InternalEncoding to true.
Language japanese Language japanese
GuiName "Japanese" GuiName "Japanese"
HasGuiSupport true
BabelName japanese BabelName japanese
Encoding jis-platex Encoding jis-platex
LangCode ja_JP LangCode ja_JP
@ -729,6 +757,7 @@ End
Language magyar Language magyar
GuiName "Hungarian" GuiName "Hungarian"
HasGuiSupport true
BabelName magyar BabelName magyar
PolyglossiaName magyar PolyglossiaName magyar
QuoteStyle polish QuoteStyle polish
@ -767,6 +796,7 @@ End
Language norsk Language norsk
GuiName "Norwegian (Bokmaal)" GuiName "Norwegian (Bokmaal)"
HasGuiSupport true
BabelName norsk BabelName norsk
PolyglossiaName norsk PolyglossiaName norsk
QuoteStyle french QuoteStyle french
@ -776,6 +806,7 @@ End
Language nynorsk Language nynorsk
GuiName "Norwegian (Nynorsk)" GuiName "Norwegian (Nynorsk)"
HasGuiSupport true
BabelName nynorsk BabelName nynorsk
PolyglossiaName nynorsk PolyglossiaName nynorsk
QuoteStyle french QuoteStyle french
@ -804,6 +835,7 @@ End
Language polish Language polish
GuiName "Polish" GuiName "Polish"
HasGuiSupport true
BabelName polish BabelName polish
PolyglossiaName polish PolyglossiaName polish
QuoteStyle polish QuoteStyle polish
@ -813,6 +845,7 @@ End
Language portuguese Language portuguese
GuiName "Portuguese" GuiName "Portuguese"
HasGuiSupport true
BabelName portuges BabelName portuges
PolyglossiaName portuges PolyglossiaName portuges
QuoteStyle english QuoteStyle english
@ -822,6 +855,7 @@ End
Language romanian Language romanian
GuiName "Romanian" GuiName "Romanian"
HasGuiSupport true
BabelName romanian BabelName romanian
PolyglossiaName romanian PolyglossiaName romanian
QuoteStyle polish QuoteStyle polish
@ -831,6 +865,7 @@ End
Language russian Language russian
GuiName "Russian" GuiName "Russian"
HasGuiSupport true
BabelName russian BabelName russian
PolyglossiaName russian PolyglossiaName russian
QuoteStyle french QuoteStyle french
@ -867,6 +902,7 @@ End
Language serbian Language serbian
GuiName "Serbian" GuiName "Serbian"
HasGuiSupport true
BabelName serbianc BabelName serbianc
PolyglossiaName serbian PolyglossiaName serbian
QuoteStyle german QuoteStyle german
@ -887,6 +923,7 @@ End
Language slovak Language slovak
GuiName "Slovak" GuiName "Slovak"
HasGuiSupport true
BabelName slovak BabelName slovak
PolyglossiaName slovak PolyglossiaName slovak
QuoteStyle german QuoteStyle german
@ -905,6 +942,7 @@ End
Language spanish Language spanish
GuiName "Spanish" GuiName "Spanish"
HasGuiSupport true
BabelName spanish BabelName spanish
PolyglossiaName spanish PolyglossiaName spanish
QuoteStyle french QuoteStyle french
@ -930,6 +968,7 @@ End
Language swedish Language swedish
GuiName "Swedish" GuiName "Swedish"
HasGuiSupport true
BabelName swedish BabelName swedish
PolyglossiaName swedish PolyglossiaName swedish
QuoteStyle swedish QuoteStyle swedish
@ -984,6 +1023,7 @@ End
Language turkish Language turkish
GuiName "Turkish" GuiName "Turkish"
HasGuiSupport true
BabelName turkish BabelName turkish
PolyglossiaName turkish PolyglossiaName turkish
QuoteStyle french QuoteStyle french
@ -1008,6 +1048,7 @@ End
Language ukrainian Language ukrainian
GuiName "Ukrainian" GuiName "Ukrainian"
HasGuiSupport true
BabelName ukrainian BabelName ukrainian
PolyglossiaName ukrainian PolyglossiaName ukrainian
QuoteStyle french QuoteStyle french

View File

@ -74,6 +74,7 @@ bool Language::readLanguage(Lexer & lex)
LA_END, LA_END,
LA_FONTENC, LA_FONTENC,
LA_GUINAME, LA_GUINAME,
LA_HAS_GUI_SUPPORT,
LA_INTERNAL_ENC, LA_INTERNAL_ENC,
LA_LANG_CODE, LA_LANG_CODE,
LA_LANG_VARIETY, LA_LANG_VARIETY,
@ -94,6 +95,7 @@ bool Language::readLanguage(Lexer & lex)
{ "end", LA_END }, { "end", LA_END },
{ "fontencoding", LA_FONTENC }, { "fontencoding", LA_FONTENC },
{ "guiname", LA_GUINAME }, { "guiname", LA_GUINAME },
{ "hasguisupport", LA_HAS_GUI_SUPPORT },
{ "internalencoding", LA_INTERNAL_ENC }, { "internalencoding", LA_INTERNAL_ENC },
{ "langcode", LA_LANG_CODE }, { "langcode", LA_LANG_CODE },
{ "langvariety", LA_LANG_VARIETY }, { "langvariety", LA_LANG_VARIETY },
@ -153,6 +155,9 @@ bool Language::readLanguage(Lexer & lex)
case LA_GUINAME: case LA_GUINAME:
lex >> display_; lex >> display_;
break; break;
case LA_HAS_GUI_SUPPORT:
lex >> has_gui_support_;
break;
case LA_INTERNAL_ENC: case LA_INTERNAL_ENC:
lex >> internal_enc_; lex >> internal_enc_;
break; break;

View File

@ -33,7 +33,7 @@ class Language {
public: public:
/// ///
Language() : rightToLeft_(false), encoding_(0), internal_enc_(false), Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
as_babel_options_(false) {} as_babel_options_(false), has_gui_support_(false) {}
/// LyX language name /// LyX language name
std::string const lang() const { return lang_; } std::string const lang() const { return lang_; }
/// Babel language name /// Babel language name
@ -81,6 +81,8 @@ public:
std::string const fontenc() const { return fontenc_; } std::string const fontenc() const { return fontenc_; }
/// This language needs to be passed to babel itself (not the class) /// This language needs to be passed to babel itself (not the class)
bool asBabelOptions() const { return as_babel_options_; } 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); bool read(Lexer & lex);
/// ///
@ -127,6 +129,8 @@ private:
/// ///
bool as_babel_options_; bool as_babel_options_;
/// ///
bool has_gui_support_;
///
TranslationMap layoutTranslations_; TranslationMap layoutTranslations_;
}; };
@ -158,7 +162,6 @@ public:
const_iterator begin() const { return languagelist.begin(); } const_iterator begin() const { return languagelist.begin(); }
/// ///
const_iterator end() const { return languagelist.end(); } const_iterator end() const { return languagelist.end(); }
///
private: private:
/// ///

View File

@ -2309,19 +2309,16 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
startCommandED->setValidator(new NoNewLineValidator(startCommandED)); startCommandED->setValidator(new NoNewLineValidator(startCommandED));
endCommandED->setValidator(new NoNewLineValidator(endCommandED)); 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->setInputMask("X; ");
defaultDecimalPointLE->setMaxLength(1); defaultDecimalPointLE->setMaxLength(1);
defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM); defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM);
defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::IN]), Length::IN); 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->blockSignals(true);
uiLanguageCO->clear();
uiLanguageCO->addItem(qt_("Default"), toqstr("auto")); uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
for (int i = 0; i != language_model->rowCount(); ++i) { for (int i = 0; i != language_model->rowCount(); ++i) {
QModelIndex index = language_model->index(i, 0); QModelIndex index = language_model->index(i, 0);
@ -2335,11 +2332,10 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
if (name != form->rc().gui_language if (name != form->rc().gui_language
&& name != lyxrc.gui_language && name != lyxrc.gui_language
&& (!Messages::available(lang->code()) && (!Messages::available(lang->code())
|| added.find(lang->code()) != added.end())) || !lang->hasGuiSupport()))
continue; continue;
added.insert(lang->code());
uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(), uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
index.data(Qt::UserRole).toString()); index.data(Qt::UserRole).toString());
} }
uiLanguageCO->blockSignals(false); uiLanguageCO->blockSignals(false);
} }