From: Dan Scott Date: Wed, 25 Jul 2012 16:45:27 +0000 (-0400) Subject: Add evergreen.get_locale_name() function to base schema X-Git-Url: http://git.equinoxoli.org/?p=transitory.git;a=commitdiff_plain;h=e087d43fc733c96563a50abdd3ce33865f234ee4 Add evergreen.get_locale_name() function to base schema 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 Signed-off-by: Thomas Berezansky --- diff --git a/Open-ILS/src/sql/Pg/020.schema.functions.sql b/Open-ILS/src/sql/Pg/020.schema.functions.sql index 81dcdfc..f69bfa4 100644 --- a/Open-ILS/src/sql/Pg/020.schema.functions.sql +++ b/Open-ILS/src/sql/Pg/020.schema.functions.sql @@ -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;