summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Storz <eduard.braun2@gmx.de>2019-08-10 22:29:46 +0000
committerPatrick Storz <eduard.braun2@gmx.de>2019-08-31 14:50:39 +0000
commitc6e8c1efdf2395580c261da2f29b26e40f97d726 (patch)
tree0de88584e972442309e7999ca404838a88d76746 /src
parentTemplates: Accept non-underscored variants of "inkscape:templateinfo" (diff)
downloadinkscape-c6e8c1efdf2395580c261da2f29b26e40f97d726.tar.gz
inkscape-c6e8c1efdf2395580c261da2f29b26e40f97d726.zip
Templates: Translate metadata within extension contexts
(i.e. implement "translationdomain" for procedural templates)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/template-load-tab.cpp25
-rw-r--r--src/ui/dialog/template-load-tab.h39
2 files changed, 40 insertions, 24 deletions
diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp
index 083513f4b..f290dcab7 100644
--- a/src/ui/dialog/template-load-tab.cpp
+++ b/src/ui/dialog/template-load-tab.cpp
@@ -19,6 +19,7 @@
#include <gtkmm/scrolledwindow.h>
#include <iostream>
+#include "extension/extension.h"
#include "extension/db.h"
#include "inkscape.h"
#include "file.h"
@@ -273,29 +274,39 @@ void TemplateLoadTab::_getProceduralTemplates()
result.path = "";
result.tpl_effect = *it;
- _getDataFromNode(templateinfo, result);
+ _getDataFromNode(templateinfo, result, *it);
_tdata[result.display_name] = result;
}
++it;
}
}
+// if the template data comes from a procedural template (aka Effect extension),
+// attempt to translate within the extension's context (which might use a different gettext textdomain)
+const char *_translate(const char* msgid, Extension::Extension *extension)
+{
+ if (extension) {
+ return extension->get_translation(msgid);
+ } else {
+ return _(msgid);
+ }
+}
-void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data)
+void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data, Extension::Extension *extension)
{
Inkscape::XML::Node *currentData;
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:name")) != nullptr)
- data.display_name = _(currentData->firstChild()->content());
+ data.display_name = _translate(currentData->firstChild()->content(), extension);
else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != nullptr) // backwards-compatibility
- data.display_name = _(currentData->firstChild()->content());
+ data.display_name = _translate(currentData->firstChild()->content(), extension);
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:author")) != nullptr)
data.author = currentData->firstChild()->content();
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:shortdesc")) != nullptr)
- data.short_description = _( currentData->firstChild()->content());
+ data.short_description = _translate(currentData->firstChild()->content(), extension);
else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) // backwards-compatibility
- data.short_description = _( currentData->firstChild()->content());
+ data.short_description = _translate(currentData->firstChild()->content(), extension);
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != nullptr)
data.preview_name = currentData->firstChild()->content();
@@ -304,7 +315,7 @@ void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateDa
data.creation_date = currentData->firstChild()->content();
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != nullptr){
- Glib::ustring tplKeywords = _(currentData->firstChild()->content());
+ Glib::ustring tplKeywords = _translate(currentData->firstChild()->content(), extension);
while (!tplKeywords.empty()){
std::size_t pos = tplKeywords.find_first_of(" ");
if (pos == Glib::ustring::npos)
diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h
index be0bdc161..2b8f98f12 100644
--- a/src/ui/dialog/template-load-tab.h
+++ b/src/ui/dialog/template-load-tab.h
@@ -27,11 +27,16 @@
namespace Inkscape {
+
+namespace Extension {
+class Extension;
+}
+
namespace UI {
class TemplateWidget;
class NewFromTemplate;
-
+
class TemplateLoadTab : public Gtk::HBox
{
@@ -49,12 +54,12 @@ public:
std::set<Glib::ustring> keywords;
Inkscape::Extension::Effect *tpl_effect;
};
-
+
TemplateLoadTab(NewFromTemplate* parent);
~TemplateLoadTab() override;
virtual void createTemplate();
-protected:
+protected:
class StringModelColumns : public Gtk::TreeModelColumnRecord
{
public:
@@ -62,32 +67,32 @@ protected:
{
add(textValue);
}
-
+
Gtk::TreeModelColumn<Glib::ustring> textValue;
};
-
+
Glib::ustring _current_keyword;
Glib::ustring _current_template;
std::map<Glib::ustring, TemplateData> _tdata;
std::set<Glib::ustring> _keywords;
-
-
+
+
virtual void _displayTemplateInfo();
virtual void _initKeywordsList();
virtual void _refreshTemplatesList();
void _loadTemplates();
void _initLists();
-
+
Gtk::VBox _tlist_box;
Gtk::HBox _search_box;
TemplateWidget *_info_widget;
-
+
Gtk::ComboBoxText _keywords_combo;
-
+
Gtk::TreeView _tlist_view;
Glib::RefPtr<Gtk::ListStore> _tlist_store;
- StringModelColumns _columns;
-
+ StringModelColumns _columns;
+
private:
enum SearchType
{
@@ -95,16 +100,16 @@ private:
USER_SPECIFIED,
ALL
};
-
+
SearchType _current_search_type;
NewFromTemplate* _parent_widget;
-
- void _getDataFromNode(Inkscape::XML::Node *, TemplateData &);
+
+ void _getDataFromNode(Inkscape::XML::Node *, TemplateData &, Extension::Extension *extension=nullptr);
void _getProceduralTemplates();
void _getTemplatesFromDomain(Inkscape::IO::Resource::Domain domain);
- void _keywordSelected();
+ void _keywordSelected();
TemplateData _processTemplateFile(const std::string &);
-
+
void _onRowActivated(const Gtk::TreeModel::Path &, Gtk::TreeViewColumn*);
};