summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/plugin.h14
-rw-r--r--slv2/port.h10
-rw-r--r--src/plugin.c38
-rw-r--r--src/port.c37
-rw-r--r--src/slv2_internal.h4
-rw-r--r--src/util.c23
-rw-r--r--wscript3
7 files changed, 114 insertions, 15 deletions
diff --git a/slv2/plugin.h b/slv2/plugin.h
index 39fd2c5..8980f2e 100644
--- a/slv2/plugin.h
+++ b/slv2/plugin.h
@@ -178,6 +178,18 @@ slv2_plugin_get_value_by_qname(SLV2Plugin p,
const char* predicate);
+/** Get a translated value associated with the plugin in a plugin's data files.
+ *
+ * This function is identical to slv2_plugin_get_value, but takes a QName
+ * string parameter for a predicate instead of an SLV2Value, which may be
+ * more convenient. It returns the value translated to the current language
+ * if possible.
+ */
+SLV2Values
+slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p,
+ const char* predicate);
+
+
/** Get a value associated with some subject in a plugin's data files.
*
* Returns the ?object of all triples found of the form:
@@ -200,7 +212,7 @@ slv2_plugin_get_value_by_qname(SLV2Plugin p,
SLV2Values
slv2_plugin_get_value_for_subject(SLV2Plugin p,
SLV2Value subject_uri,
- SLV2Value predicate_uri);
+ SLV2Value predicate_uri);
/** Return whether a feature is supported by a plugin.
diff --git a/slv2/port.h b/slv2/port.h
index b064b24..5dbe454 100644
--- a/slv2/port.h
+++ b/slv2/port.h
@@ -53,6 +53,16 @@ slv2_port_get_value_by_qname(SLV2Plugin plugin,
const char* property_uri);
+/** Port analog of slv2_plugin_get_value_by_qname_i18n.
+ *
+ * Time = Query
+ */
+SLV2Values
+slv2_port_get_value_by_qname_i18n(SLV2Plugin plugin,
+ SLV2Port port,
+ const char* property_uri);
+
+
/** Return the LV2 port properties of a port.
*
* Time = Query
diff --git a/src/plugin.c b/src/plugin.c
index c539f77..42cb1c9 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -373,19 +373,21 @@ slv2_plugin_verify(SLV2Plugin plugin)
SLV2Value
slv2_plugin_get_name(SLV2Plugin plugin)
{
- SLV2Values results = slv2_plugin_get_value_by_qname(plugin, "doap:name");
+ SLV2Values results = slv2_plugin_get_value_by_qname_i18n(plugin, "doap:name");
SLV2Value ret = NULL;
- // FIXME: lang?
-
if (results) {
SLV2Value val = slv2_values_get_at(results, 0);
if (slv2_value_is_string(val))
ret = slv2_value_duplicate(val);
- }
-
- if (results)
slv2_values_free(results);
+ } else {
+ results = slv2_plugin_get_value_by_qname(plugin, "doap:name");
+ SLV2Value val = slv2_values_get_at(results, 0);
+ if (slv2_value_is_string(val))
+ ret = slv2_value_duplicate(val);
+ slv2_values_free(results);
+ }
return ret;
}
@@ -429,11 +431,29 @@ SLV2Values
slv2_plugin_get_value_by_qname(SLV2Plugin p,
const char* predicate)
{
- char* query = NULL;
+ char* query = slv2_strjoin(
+ "SELECT DISTINCT ?value WHERE { \n"
+ "<> ", predicate, " ?value . \n"
+ "FILTER(lang(?value) = \"\") \n"
+ "}\n", NULL);
+
+ SLV2Values result = slv2_plugin_query_variable(p, query, 0);
- query = slv2_strjoin(
+ free(query);
+
+ return result;
+}
+
+
+/* internal: get i18n value if possible */
+SLV2Values
+slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p,
+ const char* predicate)
+{
+ char* query = slv2_strjoin(
"SELECT DISTINCT ?value WHERE { \n"
- "<> ", predicate, " ?value \n"
+ "<> ", predicate, " ?value . \n"
+ "FILTER(lang(?value) = \"", slv2_get_lang(), "\") \n"
"}\n", NULL);
SLV2Values result = slv2_plugin_query_variable(p, query, 0);
diff --git a/src/port.c b/src/port.c
index 5641de4..7fd3ede 100644
--- a/src/port.c
+++ b/src/port.c
@@ -141,7 +141,8 @@ slv2_port_get_value_by_qname(SLV2Plugin p,
"SELECT DISTINCT ?value WHERE {\n"
"<", slv2_value_as_uri(p->plugin_uri), "> lv2:port ?port .\n"
"?port lv2:symbol \"", slv2_value_as_string(port->symbol), "\";\n\t",
- property, " ?value .\n}", NULL);
+ property, " ?value .\n"
+ "FILTER(lang(?value) = \"\") }", NULL);
results = slv2_plugin_query_variable(p, query, 0);
@@ -188,6 +189,29 @@ slv2_port_get_value(SLV2Plugin p,
}
+SLV2Values
+slv2_port_get_value_by_qname_i18n(SLV2Plugin p,
+ SLV2Port port,
+ const char* property)
+{
+ assert(property);
+ SLV2Values results = NULL;
+
+ char* query = slv2_strjoin(
+ "SELECT DISTINCT ?value WHERE {\n"
+ "<", slv2_value_as_uri(p->plugin_uri), "> lv2:port ?port .\n"
+ "?port lv2:symbol \"", slv2_value_as_string(port->symbol), "\";\n\t",
+ property, " ?value .\n"
+ "FILTER(lang(?value) = \"", slv2_get_lang(),
+ "\") }", NULL);
+
+ results = slv2_plugin_query_variable(p, query, 0);
+
+ free(query);
+ return results;
+}
+
+
SLV2Value
slv2_port_get_symbol(SLV2Plugin p,
SLV2Port port)
@@ -201,11 +225,16 @@ slv2_port_get_name(SLV2Plugin p,
SLV2Port port)
{
SLV2Value ret = NULL;
- SLV2Values results = slv2_port_get_value_by_qname(p, port, "lv2:name");
+ SLV2Values results = slv2_port_get_value_by_qname_i18n(p, port, "lv2:name");
- if (results && slv2_values_size(results) == 1)
+ if (results && slv2_values_size(results) > 0) {
ret = slv2_value_duplicate(slv2_values_get_at(results, 0));
-
+ } else {
+ results = slv2_port_get_value_by_qname(p, port, "lv2:name");
+ if (results && slv2_values_size(results) > 0)
+ ret = slv2_value_duplicate(slv2_values_get_at(results, 0));
+ }
+
slv2_values_free(results);
return ret;
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 40ddbac..f5c0ace 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -25,6 +25,7 @@ extern "C" {
#include <stdbool.h>
#include <stddef.h>
+#include <stdlib.h>
#include <inttypes.h>
#include <librdf.h>
#include "slv2/types.h"
@@ -243,6 +244,9 @@ void slv2_scale_point_free(SLV2ScalePoint point);
char* slv2_strjoin(const char* first, ...);
+/* I18N utility functions */
+char* slv2_get_lang();
+
#ifdef __cplusplus
}
diff --git a/src/util.c b/src/util.c
index 3c53026..71094ab 100644
--- a/src/util.c
+++ b/src/util.c
@@ -71,4 +71,27 @@ slv2_uri_to_path(const char* uri)
}
+char*
+slv2_get_lang()
+{
+ static char lang[32];
+ lang[31] = '\0';
+ char* tmp = getenv("LANG");
+ if (!tmp) {
+ lang[0] = '\0';
+ } else {
+ strncpy(lang, tmp, 31);
+ for (int i = 0; i < 31 && lang[i]; ++i) {
+ if (lang[i] == '_') {
+ lang[i] = '-';
+ } else if ( !(lang[i] >= 'a' && lang[i] <= 'z')
+ && !(lang[i] >= 'A' && lang[i] <= 'Z')) {
+ lang[i] = '\0';
+ break;
+ }
+ }
+ }
+
+ return lang;
+}
diff --git a/wscript b/wscript
index cfa8416..ddd977e 100644
--- a/wscript
+++ b/wscript
@@ -24,7 +24,8 @@ SLV2_VERSION = '0.6.1'
# 0.4.5 = 7,0,1
# 0.5.0 = 8,0,0
# 0.6.0 = 9,0,0 (SVN r1282)
-SLV2_LIB_VERSION = '9.0.0'
+# 0.6.1 = 9,1,0
+SLV2_LIB_VERSION = '9.1.0'
# Variables for 'waf dist'
APPNAME = 'slv2'