summaryrefslogtreecommitdiffstats
path: root/src/extension/extension.cpp
diff options
context:
space:
mode:
authorPatrick Storz <eduard.braun2@gmx.de>2019-08-03 23:34:27 +0000
committerPatrick Storz <eduard.braun2@gmx.de>2019-08-31 14:50:38 +0000
commitea05ba3338bec1517826614f27935a36c3b0f0f8 (patch)
treedce3126f09fe834a6bf165031d28c607dba73327 /src/extension/extension.cpp
parentRemove unused "nopref" variant of effects (diff)
downloadinkscape-ea05ba3338bec1517826614f27935a36c3b0f0f8.tar.gz
inkscape-ea05ba3338bec1517826614f27935a36c3b0f0f8.zip
Implement "translationdomain" attribute for extensions
Will allow extensions to ship their own message catalog used for translation of the extension#s strings. Needs to be set on the root <inkscape-extension> element of the .inx Currently supported values: - unset: use default textdomain (which happens to be 'inkscape') - 'inkscape': use Inkscape's message catalog - 'none': disable translation for the extension's strings
Diffstat (limited to 'src/extension/extension.cpp')
-rw-r--r--src/extension/extension.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp
index 85ea99ca8..05a5f4402 100644
--- a/src/extension/extension.cpp
+++ b/src/extension/extension.cpp
@@ -64,6 +64,17 @@ Extension::Extension (Inkscape::XML::Node *in_repr, Implementation::Implementati
imp = in_imp;
}
+ // get name of the translation catalog ("gettext textdomain") that the extension wants to use for translations
+ const char *translationdomain = repr->attribute("translationdomain");
+ if (translationdomain) {
+ _translationdomain = g_strdup(translationdomain);
+
+ // special keyword "none" means the extension author does not want translation of extension strings
+ if (!strcmp(translationdomain, "none")) {
+ _translation_enabled = false;
+ }
+ }
+
// Read XML tree and parse extension
Inkscape::XML::Node *child_repr = repr->firstChild();
while (child_repr) {
@@ -119,8 +130,6 @@ Extension::Extension (Inkscape::XML::Node *in_repr, Implementation::Implementati
throw extension_no_name();
}
db.register_ext (this);
-
- timer = nullptr;
}
/**
@@ -372,6 +381,30 @@ Extension::deactivated ()
return get_state() == STATE_DEACTIVATED;
}
+/** Gets a translation within the context of the current extension
+ *
+ * Query gettext for the translated version of the input string,
+ * handling the preferred translation domain of the extension internally.
+ *
+ * @param msgid String to translate
+ * @param msgctxt Context for the translation
+ *
+ * @return Translated string (or original string if extension is not supposed to be translated)
+ */
+const char *Extension::get_translation(const char *msgid, const char *msgctxt) {
+ if (!_translation_enabled) {
+ return msgid;
+ }
+
+ // Note: _translationdomain might be NULL, which is fine.
+ // We will simply default to the domain set via textdomain() in this case (which should be 'inkscape')
+ if (msgctxt) {
+ return g_dpgettext2(_translationdomain, msgctxt, msgid);
+ } else {
+ return g_dgettext(_translationdomain, msgid);
+ }
+}
+
Parameter *Extension::get_param(const gchar *name)
{
if (name == nullptr) {
@@ -746,7 +779,7 @@ Extension::get_info_widget()
info->add(*table);
int row = 0;
- add_val(_("Name:"), _(_name), table, &row);
+ add_val(_("Name:"), get_translation(_name), table, &row);
add_val(_("ID:"), _id, table, &row);
add_val(_("State:"), _state == STATE_LOADED ? _("Loaded") : _state == STATE_UNLOADED ? _("Unloaded") : _("Deactivated"), table, &row);