[open-ils-commits] r8011 - in trunk/Open-ILS: examples src/c-apps
src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 5 19:40:43 EST 2007
Author: miker
Date: 2007-11-05 19:25:09 -0500 (Mon, 05 Nov 2007)
New Revision: 8011
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/c-apps/oils_cstore.c
trunk/Open-ILS/src/c-apps/oils_idl-core.c
trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/build-db.sh
Log:
first round of i18n magic in cstore
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2007-11-06 00:25:09 UTC (rev 8011)
@@ -922,7 +922,7 @@
<field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
<field name="holdable" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="bool"/>
<field name="id" oils_obj:array_position="4" oils_persist:virtual="false" reporter:selector="name" reporter:datatype="id"/>
- <field name="name" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text"/>
+ <field name="name" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true"/>
</fields>
<links/>
</class>
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2007-11-06 00:25:09 UTC (rev 8011)
@@ -1,5 +1,6 @@
#include "opensrf/osrf_application.h"
#include "opensrf/osrf_settings.h"
+#include "opensrf/osrf_message.h"
#include "opensrf/utils.h"
#include "objson/object.h"
#include "opensrf/log.h"
@@ -2080,6 +2081,7 @@
while ( (node = jsonObjectIteratorNext( select_itr )) ) {
osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), jsonObjectToSimpleString(node->item) );
char* fname = osrfHashGet(field, "name");
+ char* locale = osrf_message_get_last_locale();
if (!field) continue;
@@ -2089,7 +2091,20 @@
buffer_add(select_buf, ",");
}
- buffer_fadd(select_buf, " \"%s\".%s", cname, fname);
+ if (locale) {
+ char* i18n = osrfHashGet(field, "i18n");
+
+ if ( i18n && !strncasecmp("true", i18n, 4)) {
+ 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 )", tname, fname, cname, pkey, locale, cname, fname);
+ } else {
+ buffer_fadd(select_buf, " \"%s\".%s", cname, fname);
+ }
+ } else {
+ buffer_fadd(select_buf, " \"%s\".%s", cname, fname);
+ }
}
}
Modified: trunk/Open-ILS/src/c-apps/oils_idl-core.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_idl-core.c 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/src/c-apps/oils_idl-core.c 2007-11-06 00:25:09 UTC (rev 8011)
@@ -142,6 +142,15 @@
}
string_tmp = NULL;
+ if( (string_tmp = (char*)xmlGetNsProp(_f, BAD_CAST "i18n", BAD_CAST PERSIST_NS)) ) {
+ osrfHashSet(
+ _tmp,
+ strdup( string_tmp ),
+ "i18n"
+ );
+ }
+
+ string_tmp = NULL;
if( (string_tmp = (char*)xmlGetNsProp(_f, BAD_CAST "virtual", BAD_CAST PERSIST_NS)) ) {
osrfHashSet(
_tmp,
Modified: trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2007-11-06 00:25:09 UTC (rev 8011)
@@ -1,5 +1,6 @@
BEGIN;
+/*
CREATE OR REPLACE FUNCTION oils_xml_transform ( TEXT, TEXT ) RETURNS TEXT AS $_$
SELECT CASE WHEN (SELECT COUNT(*) FROM config.xml_transform WHERE name = $2 AND xslt = '---') > 0 THEN $1
ELSE xslt_process($1, (SELECT xslt FROM config.xml_transform WHERE name = $2))
@@ -17,14 +18,14 @@
FOR i IN ARRAY_LOWER(field_list,1) .. ARRAY_UPPER(field_list,1) LOOP
FOR rec IN SELECT DISTINCT r, field_list[i], BTRIM(REGEXP_REPLACE(REGEXP_REPLACE(f, E'\n', ' ', 'g'), '[ ]+', ' ', 'g'))
FROM xpath_table_ns(
- 'id',
- $$oils_xml_transform(marc,'$$ || (SELECT format FROM config.metabib_field WHERE id = field_list[i]) || $$')$$,
- 'biblio.record_entry',
- (SELECT xpath FROM config.metabib_field WHERE id = field_list[i]),
- 'id = ' || record,
- (SELECT x.prefix FROM config.xml_transform x JOIN config.metabib_field m ON (m.format = x.name) WHERE m.id = field_list[i]),
- (SELECT x.namespace_uri FROM config.xml_transform x JOIN config.metabib_field m ON (m.format = x.name) WHERE m.id = field_list[i])
- ) AS t( r bigint, f text)
+ 'id',
+ $$oils_xml_transform(marc,'$$ || (SELECT format FROM config.metabib_field WHERE id = field_list[i]) || $$')$$,
+ 'biblio.record_entry',
+ (SELECT xpath FROM config.metabib_field WHERE id = field_list[i]),
+ 'id = ' || record,
+ (SELECT x.prefix FROM config.xml_transform x JOIN config.metabib_field m ON (m.format = x.name) WHERE m.id = field_list[i]),
+ (SELECT x.namespace_uri FROM config.xml_transform x JOIN config.metabib_field m ON (m.format = x.name) WHERE m.id = field_list[i])
+ ) AS t( r bigint, f text)
WHERE f IS NOT NULL LOOP
RETURN NEXT rec;
END LOOP;
@@ -33,10 +34,39 @@
$_$ LANGUAGE PLPGSQL;
-
CREATE OR REPLACE FUNCTION biblio_field_table ( record BIGINT, field INT ) RETURNS SETOF biblio_field_vtype AS $_$
SELECT * FROM biblio_field_table( $1, ARRAY[$2] )
$_$ LANGUAGE SQL;
+*/
+
+CREATE OR REPLACE FUNCTION oils_i18n_xlate ( keyfield TEXT, keyvalue TEXT, raw_locale TEXT ) RETURNS TEXT AS $func$
+DECLARE
+ locale TEXT := LOWER( REGEXP_REPLACE( REGEXP_REPLACE( raw_locale, E'[;, ].+$', '' ), E'-', '_', 'g' ) );
+ language TEXT := REGEXP_REPLACE( locale, E'_.+$', '' );
+ result config.i18n_core%ROWTYPE;
+BEGIN
+
+ RAISE NOTICE '%', locale;
+
+ SELECT * INTO result
+ FROM config.i18n_core
+ WHERE fq_field = keyfield
+ AND identity_value = keyvalue
+ AND translation = locale;
+
+ IF NOT FOUND THEN
+ SELECT * INTO result
+ FROM config.i18n_core
+ WHERE fq_field = keyfield
+ AND identity_value = keyvalue
+ AND translation = language;
+ END IF;
+
+ RETURN result.string;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+
COMMIT;
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2007-11-06 00:25:09 UTC (rev 8011)
@@ -28,7 +28,16 @@
*/
$$;
+CREATE TABLE config.i18n_core (
+ id BIGSERIAL PRIMARY KEY,
+ fq_field TEXT NOT NULL,
+ identity_value TEXT NOT NULL,
+ translation TEXT NOT NULL,
+ string TEXT NOT NULL
+);
+CREATE UNIQUE INDEX i18n_identity ON config.i18n_core (fq_field,identity_value,translation);
+
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
quality INT CHECK ( quality BETWEEN 0 AND 100 ),
Modified: trunk/Open-ILS/src/sql/Pg/build-db.sh
===================================================================
--- trunk/Open-ILS/src/sql/Pg/build-db.sh 2007-11-05 21:41:24 UTC (rev 8010)
+++ trunk/Open-ILS/src/sql/Pg/build-db.sh 2007-11-06 00:25:09 UTC (rev 8011)
@@ -6,6 +6,7 @@
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 000.english.pg$6.fts-config.sql
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 001.schema.offline.sql
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.schema.config.sql
+PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.functions.config.sql
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 005.schema.actors.sql
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.schema.permissions.sql
PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.data.permissions.sql
More information about the open-ils-commits
mailing list