Add evergreen.get_locale_name() function to base schema
authorDan Scott <dscott@laurentian.ca>
Wed, 25 Jul 2012 16:45:27 +0000 (12:45 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 25 Jul 2012 16:52:35 +0000 (12:52 -0400)
I added the evergreen.get_locale_name() function to the database schema
upgrades in 0723 but failed to add it to the base schema, resulting in
errors like: 'egweb: template error: undef error - Can't call method
"maketext"'. Get rid of that problem!

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>

Open-ILS/src/sql/Pg/020.schema.functions.sql

index 81dcdfc..f69bfa4 100644 (file)
@@ -412,3 +412,40 @@ $$ LANGUAGE plpgsql;
 
 CREATE TRIGGER proximity_update_tgr AFTER INSERT OR UPDATE OR DELETE ON actor.org_unit FOR EACH ROW EXECUTE PROCEDURE actor.org_unit_prox_update ();
 
+CREATE OR REPLACE FUNCTION evergreen.get_locale_name(
+    IN locale TEXT,
+    OUT name TEXT,
+    OUT description TEXT
+) AS $$
+DECLARE
+    eg_locale TEXT;
+BEGIN
+    eg_locale := LOWER(SUBSTRING(locale FROM 1 FOR 2)) || '-' || UPPER(SUBSTRING(locale FROM 4 FOR 2));
+        
+    SELECT i18nc.string INTO name
+    FROM config.i18n_locale i18nl
+       INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation
+    WHERE i18nc.identity_value = eg_locale
+       AND code = eg_locale
+       AND i18nc.fq_field = 'i18n_l.name';
+
+    IF name IS NULL THEN
+       SELECT i18nl.name INTO name
+       FROM config.i18n_locale i18nl
+       WHERE code = eg_locale;
+    END IF;
+
+    SELECT i18nc.string INTO description
+    FROM config.i18n_locale i18nl
+       INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation
+    WHERE i18nc.identity_value = eg_locale
+       AND code = eg_locale
+       AND i18nc.fq_field = 'i18n_l.description';
+
+    IF description IS NULL THEN
+       SELECT i18nl.description INTO description
+       FROM config.i18n_locale i18nl
+       WHERE code = eg_locale;
+    END IF;
+END;
+$$ LANGUAGE PLPGSQL COST 1 STABLE;