[open-ils-commits] r8130 - in trunk/Open-ILS/src: c-apps sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Dec 3 14:38:42 EST 2007
Author: miker
Date: 2007-12-03 14:19:19 -0500 (Mon, 03 Dec 2007)
New Revision: 8130
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
Log:
patch suggested by Dan Scott to simplify the in-database translation logic
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2007-12-03 15:40:47 UTC (rev 8129)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2007-12-03 19:19:19 UTC (rev 8130)
@@ -1809,7 +1809,7 @@
char* pkey = osrfHashGet(idlClass, "primarykey");
char* tname = osrfHashGet(idlClass, "tablename");
- buffer_fadd(select_buf, " COALESCE( oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s'), \"%s\".%s ) AS %s", tname, __column, cname, pkey, locale, cname, __column, __column);
+ buffer_fadd(select_buf, " oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s') AS \"%s\"", tname, __column, cname, pkey, locale, __column);
} else {
buffer_fadd(select_buf, " \"%s\".%s AS \"%s\"", cname, __column, __column);
}
@@ -1853,7 +1853,7 @@
char* pkey = osrfHashGet(idlClass, "primarykey");
char* tname = osrfHashGet(idlClass, "tablename");
- buffer_fadd(select_buf, " COALESCE( oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s'), \"%s\".%s ) AS \"%s\"", tname, fname, cname, pkey, locale, cname, fname, __alias);
+ buffer_fadd(select_buf, " oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s') AS \"%s\"", tname, fname, cname, pkey, locale, __alias);
} else {
buffer_fadd(select_buf, " \"%s\".%s AS \"%s\"", cname, fname, __alias);
}
@@ -2214,7 +2214,7 @@
char* pkey = osrfHashGet(idlClass, "primarykey");
char* tname = osrfHashGet(idlClass, "tablename");
- buffer_fadd(select_buf, " COALESCE( oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s'), \"%s\".%s ) AS %s", tname, fname, cname, pkey, locale, cname, fname, fname);
+ buffer_fadd(select_buf, " oils_i18n_xlate('%s.%s', \"%s\".%s::TEXT, '%s') AS \"%s\"", tname, fname, cname, pkey, locale, fname);
} else {
buffer_fadd(select_buf, " \"%s\".%s", cname, fname);
}
Modified: trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2007-12-03 15:40:47 UTC (rev 8129)
+++ trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2007-12-03 19:19:19 UTC (rev 8130)
@@ -47,12 +47,14 @@
result config.i18n_core%ROWTYPE;
BEGIN
+ -- Try the full locale
SELECT * INTO result
FROM config.i18n_core
WHERE fq_field = keyfield
AND identity_value = keyvalue
AND translation = locale;
+ -- Try just the language
IF NOT FOUND THEN
SELECT * INTO result
FROM config.i18n_core
@@ -61,10 +63,19 @@
AND translation = language;
END IF;
+ -- Fall back to the string we passed in in the first place
+ IF NOT FOUND THEN
+ RETURN keyvalue;
+ END IF;
+
RETURN result.string;
END;
$func$ LANGUAGE PLPGSQL;
+-- Function for marking translatable strings in SQL statements
+CREATE OR REPLACE FUNCTION oils_i18n_gettext( TEXT ) RETURNS TEXT AS $$
+ SELECT $1;
+$$ LANGUAGE SQL;
COMMIT;
More information about the open-ils-commits
mailing list