diff options
Diffstat (limited to 'src/ui/dialog/template-load-tab.cpp')
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 6c17a9a96..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" @@ -170,8 +171,7 @@ void TemplateLoadTab::_refreshTemplatesList() if (it.second.keywords.count(_current_keyword.lowercase()) != 0 || it.second.display_name.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || it.second.author.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || - it.second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || - it.second.long_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ) + it.second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos) { Gtk::TreeModel::iterator iter = _tlist_store->append(); Gtk::TreeModel::Row row = *iter; @@ -236,16 +236,19 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::s Inkscape::XML::Document *rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI); if (rdoc){ - Inkscape::XML::Node *myRoot = rdoc->root(); - if (strcmp(myRoot->name(), "svg:svg") != 0){ // Wrong file format + Inkscape::XML::Node *root = rdoc->root(); + if (strcmp(root->name(), "svg:svg") != 0){ // Wrong file format return result; } - myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + Inkscape::XML::Node *templateinfo = sp_repr_lookup_name(root, "inkscape:templateinfo"); + if (!templateinfo) { + templateinfo = sp_repr_lookup_name(root, "inkscape:_templateinfo"); // backwards-compatibility + } - if (myRoot == nullptr) // No template info + if (templateinfo == nullptr) // No template info return result; - _getDataFromNode(myRoot, result); + _getDataFromNode(templateinfo, result); } return result; @@ -258,43 +261,61 @@ void TemplateLoadTab::_getProceduralTemplates() std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin(); while (it != effects.end()){ - Inkscape::XML::Node *myRoot; - myRoot = (*it)->get_repr(); - myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + Inkscape::XML::Node *repr = (*it)->get_repr(); + Inkscape::XML::Node *templateinfo = sp_repr_lookup_name(repr, "inkscape:templateinfo"); + if (!templateinfo) { + templateinfo = sp_repr_lookup_name(repr, "inkscape:_templateinfo"); // backwards-compatibility + } - if (myRoot){ + if (templateinfo){ TemplateData result; result.display_name = (*it)->get_name(); result.is_procedural = true; result.path = ""; result.tpl_effect = *it; - _getDataFromNode(myRoot, 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()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:name")) != nullptr) + data.display_name = _translate(currentData->firstChild()->content(), extension); + else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != nullptr) // backwards-compatibility + 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()); - if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_long") )!= nullptr) - data.long_description = _(currentData->firstChild()->content()); + + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:shortdesc")) != nullptr) + data.short_description = _translate(currentData->firstChild()->content(), extension); + else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) // backwards-compatibility + data.short_description = _translate(currentData->firstChild()->content(), extension); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != nullptr) data.preview_name = currentData->firstChild()->content(); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != nullptr) 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) |
