[Mapbender-commits] r2792 - in trunk/mapbender/resources/db: mysql pgsql

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Aug 14 10:23:42 EDT 2008


Author: christoph
Date: 2008-08-14 10:23:42 -0400 (Thu, 14 Aug 2008)
New Revision: 2792

Added:
   trunk/mapbender/resources/db/mysql/mysql_gettext.sql
   trunk/mapbender/resources/db/pgsql/pgsql_gettext.sql
Log:
gettext function for mysql and pgsql

Added: trunk/mapbender/resources/db/mysql/mysql_gettext.sql
===================================================================
--- trunk/mapbender/resources/db/mysql/mysql_gettext.sql	                        (rev 0)
+++ trunk/mapbender/resources/db/mysql/mysql_gettext.sql	2008-08-14 14:23:42 UTC (rev 2792)
@@ -0,0 +1,24 @@
+
+DELIMITER $$
+
+DROP FUNCTION IF EXISTS gettext$$
+
+
+CREATE FUNCTION gettext(locale_arg text, querystring text) RETURNS text READS SQL DATA
+
+BEGIN
+
+DECLARE result text;
+
+SELECT msgstr INTO result FROM translations WHERE locale = locale_arg AND msgid = querystring;
+
+IF result IS NULL THEN
+RETURN querystring;
+ELSE
+RETURN result;
+END IF;
+
+END$$
+
+DELIMITER ;
+

Added: trunk/mapbender/resources/db/pgsql/pgsql_gettext.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/pgsql_gettext.sql	                        (rev 0)
+++ trunk/mapbender/resources/db/pgsql/pgsql_gettext.sql	2008-08-14 14:23:42 UTC (rev 2792)
@@ -0,0 +1,43 @@
+-- check if plpgsql exists; if yes, install it.
+CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
+        RETURNS TEXT
+        AS $$
+            CREATE LANGUAGE plpgsql;
+            SELECT 'language plpgsql created'::TEXT;
+        $$
+LANGUAGE 'sql';
+
+SELECT CASE WHEN
+              (SELECT true::BOOLEAN
+                 FROM pg_language
+                WHERE lanname='plpgsql')
+            THEN
+              (SELECT 'language already installed'::TEXT)
+            ELSE
+              (SELECT public.create_plpgsql_language())
+            END;
+
+DROP FUNCTION public.create_plpgsql_language ();
+
+-- function gettext for i18n (requires plpgsql)
+CREATE FUNCTION gettext(locale_arg text, string text) RETURNS character varying
+    AS $$
+ DECLARE
+    msgstr varchar(512);
+    trl RECORD;
+ BEGIN
+    -- RAISE NOTICE '>%<', locale_arg;
+
+    SELECT INTO trl * FROM translations
+    WHERE trim(from locale) = trim(from locale_arg) AND msgid = string;
+    -- we return the original string, if no translation is found.
+    -- this is consistent with gettext's behaviour
+    IF NOT FOUND THEN
+        RETURN string;
+    ELSE
+        RETURN trl.msgstr;
+    END IF; 
+ END;
+ $$
+    LANGUAGE plpgsql;
+



More information about the Mapbender_commits mailing list