Am Mittwoch, den 25.07.2018, 13:56 +0200 schrieb Jean-Marc Lasgouttes:
> > Anyway, I am currently looking into a more general solution wrt
> > #5348.
>
> Great.
Here is it. What this does, is:
* Use the context language of the info inset (rather than the buffer
language), and translate strings accordingly
* For menu and shortcuts, use the Gui language instead
* Actually care that all translatable strings end in po (this wasn't
the case).
Remaining glitch: When selecting an Info Inset and changing the
language, the effect in the workarea is only shown after buffe reload
or a change in the inset's settings. A buffer update missing, but I
can't see where.
What do you think?
Jürgen
>
> JMarc
diff --git a/src/Language.cpp b/src/Language.cpp
index 8110c17401..d7bcbd3c58 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -375,6 +375,26 @@ Match match(string const & code, Language const & lang)
} // namespace
+
+Language const * Languages::getFromCode(string const & code) const
+{
+ LanguageList::const_iterator const lbeg = languagelist.begin();
+ LanguageList::const_iterator const lend = languagelist.end();
+ // Try for exact match first
+ for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
+ if (match(code, lit->second) == ExactMatch)
+ return &lit->second;
+ }
+ // If not found, look for lang prefix (without country) instead
+ for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
+ if (match(code, lit->second) == ApproximateMatch)
+ return &lit->second;
+ }
+ LYXERR0("Unknown language `" + code + "'");
+ return 0;
+}
+
+
void Languages::readLayoutTranslations(support::FileName const & filename)
{
Lexer lex;
@@ -395,13 +415,7 @@ void Languages::readLayoutTranslations(support::FileName const & filename)
if (!lex.next(true))
break;
string const code = lex.getString();
- bool found = false;
- for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
- if (match(code, lit->second) != NoMatch) {
-found = true;
-break;
- }
- }
+ bool found = getFromCode(code);
if (!found) {
lex.printError("Unknown language `" + code + "'");
break;
diff --git a/src/Language.h b/src/Language.h
index d3f0e17139..9587d7987a 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -162,6 +162,8 @@ public:
///
void read(support::FileName const & filename);
///
+ Language const * getFromCode(std::string const & code) const;
+ ///
void readLayoutTranslations(support::FileName const & filename);
///
Language const * getLanguage(std::string const & language) const;
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index 3cec4ee77d..e6776abe4a 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -15,6 +15,7 @@
#include "BufferParams.h"
#include "BufferView.h"
#include "CutAndPaste.h"
+#include "Font.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetGraphics.h"
@@ -28,6 +29,8 @@
#include "LyXRC.h"
#include "LyXVC.h"
#include "Lexer.h"
+#include "Paragraph.h"
+#include "ParIterator.h"
#include "ParagraphParameters.h"
#include "version.h"
@@ -41,6 +44,7 @@
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/Messages.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/Translator.h"
@@ -284,22 +288,29 @@ void InsetInfo::setInfo(string const & name)
}
-void InsetInfo::error(string const & err)
+void InsetInfo::error(docstring const & err, Language const * lang)
{
- setText(bformat(_(err), from_utf8(name_)),
- Font(inherit_font, buffer().params().language), false);
+ setText(bformat(translateIfPossible(err, lang->code()), from_utf8(name_)),
+ Font(inherit_font, lang), false);
}
-void InsetInfo::setText(docstring const & str)
+void InsetInfo::info(docstring const & err, Language const * lang)
{
- setText(str, Font(inherit_font, buffer().params().language), false);
+ setText(translateIfPossible(err, lang->code()),
+ Font(inherit_font, lang), false);
+}
+
+
+void InsetInfo::setText(docstring const & str, Language const * lang)
+{
+ setText(str, Font(inherit_font, lang), false);
}
bool InsetInfo::forceLTR() const
{
- return !buffer().params().language->rightToLeft() || force_ltr_;
+ return force_ltr_;
}
@@ -313,11 +324,18 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
return;
BufferParams const & bp = buffer().params();
-
- force_ltr_ = false;
+ Language const * lang = it.paragraph().getFontSettings(bp, it.pos()).language();
+ Language const * tryguilang = languages.getFromCode(Messages::guiLanguage());
+ // Some info insets use the language of the GUI (if available)
+ Language const * guilang = tryguilang ? tryguilang : lang;
+
+ force_ltr_ = !lang->rightToLeft();
+ // This is just to get the string into the po files
+ docstring gui;
switch (type_) {
case UNKNOWN_INFO:
- error("Unknown Info: %1$s");
+ gui = _("Unknown In