Index: openacs-4/packages/acs-lang/acs-lang.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/acs-lang.info,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/acs-lang/acs-lang.info	23 Sep 2002 23:32:03 -0000	1.6
+++ openacs-4/packages/acs-lang/acs-lang.info	7 Oct 2002 14:32:41 -0000	1.7
@@ -4,17 +4,17 @@
 <package key="acs-lang" url="http://www.openacs.org/acs-repository/apm/packages/acs-lang" type="apm_service">
     <package-name>OpenACS Localization Utils</package-name>
     <pretty-plural>OpenACS Localization Utils</pretty-plural>
-    <initial-install-p>f</initial-install-p>
+    <initial-install-p>t</initial-install-p>
     <singleton-p>t</singleton-p>
 
-    <version name="4.1b" url="http://www.openacs.org/acs-repository/download/apm/acs-lang-4.1b.apm">
+    <version name="4.7d2" url="http://www.openacs.org/acs-repository/download/apm/acs-lang-4.7d2.apm">
     <database-support>
         <database>oracle</database>
         <database>postgresql</database>
     </database-support>
         <owner url="mailto:hqm@ai.mit.edu">Henry Minsky</owner>
         <summary>OpenACS Internationalization Utilities</summary>
-        <release-date>2001-01-21</release-date>
+        <release-date>2002-09-26</release-date>
         <vendor url="http://www.arsdigita.com/">ArsDigita Corporation</vendor>
         <description format="text/html">OpenACS Internationalization Utilities. Routines for manipulating Locales,
 request processor hooks, templating, message catalog, and
@@ -25,8 +25,8 @@
 and must be run manually from a shell. See the README file
 in that directory for details.</description>
 
-        <requires url="acs-kernel" version="4.1"/>
         <provides url="acs-lang" version="4.1b"/>
+        <requires url="acs-kernel" version="4.1"/>
 
         <files>
             <file path="ACS4.1b-PATCHES/README"/>
@@ -35,29 +35,31 @@
             <file path="ACS4.1b-PATCHES/tag-init.patch"/>
             <file path="ACS4.1b-PATCHES/util-procs.patch"/>
             <file type="package_spec" path="acs-lang.info"/>
-            <file path="acs-lang.info.orig"/>
-            <file path="acs-lang.info.rej"/>
             <file path="catalog/test.iso-8859-1.cat"/>
             <file type="data_model_create" db_type="oracle" path="sql/oracle/acs-lang-create.sql"/>
             <file type="data_model" db_type="oracle" path="sql/oracle/ad-locales-drop.sql"/>
             <file type="data_model" db_type="oracle" path="sql/oracle/ad-locales.sql"/>
-            <file type="data_model" db_type="oracle" path="sql/oracle/currency.sql"/>
             <file type="data_model" db_type="oracle" path="sql/oracle/message-catalog-drop.sql"/>
             <file type="data_model" db_type="oracle" path="sql/oracle/message-catalog.sql"/>
+            <file type="data_model_upgrade" db_type="oracle" path="sql/oracle/upgrade/upgrade-4.1-4.7.sql"/>
             <file type="data_model_create" db_type="postgresql" path="sql/postgresql/acs-lang-create.sql"/>
             <file type="data_model" db_type="postgresql" path="sql/postgresql/ad-locales-drop.sql"/>
             <file type="data_model" db_type="postgresql" path="sql/postgresql/ad-locales.sql"/>
-            <file type="data_model" db_type="postgresql" path="sql/postgresql/currency.sql"/>
             <file type="data_model" db_type="postgresql" path="sql/postgresql/message-catalog-drop.sql"/>
             <file type="data_model" db_type="postgresql" path="sql/postgresql/message-catalog.sql"/>
-            <file type="tcl_procs" path="tcl/acs-lang-procs.tcl"/>
-            <file type="query_file" db_type="oracle" path="tcl/lang-init-oracle.xql"/>
-            <file type="query_file" db_type="postgresql" path="tcl/lang-init-postgresql.xql"/>
-            <file type="tcl_init" path="tcl/lang-init.tcl"/>
-            <file type="query_file" db_type="oracle" path="tcl/lang-procs-oracle.xql"/>
-            <file type="tcl_procs" path="tcl/lang-procs.tcl"/>
-            <file type="query_file" path="tcl/lang-procs.xql"/>
-            <file type="tcl_init" path="tcl/locale-init.tcl"/>
+            <file type="data_model_upgrade" db_type="postgresql" path="sql/postgresql/upgrade/upgrade-4.1-4.7.sql"/>
+            <file type="tcl_init" path="tcl/lang-catalog-init.tcl"/>
+            <file type="tcl_procs" path="tcl/lang-catalog-procs.tcl"/>
+            <file type="query_file" path="tcl/lang-catalog-procs.xql"/>
+            <file type="tcl_init" path="tcl/lang-message-init.tcl"/>
+            <file type="query_file" db_type="oracle" path="tcl/lang-message-procs-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="tcl/lang-message-procs-postgresql.xql"/>
+            <file type="tcl_procs" path="tcl/lang-message-procs.tcl"/>
+            <file type="query_file" path="tcl/lang-message-procs.xql"/>
+            <file type="query_file" db_type="oracle" path="tcl/lang-util-procs-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="tcl/lang-util-procs-postgresql.xql"/>
+            <file type="tcl_procs" path="tcl/lang-util-procs.tcl"/>
+            <file type="query_file" path="tcl/lang-util-procs.xql"/>
             <file type="query_file" db_type="oracle" path="tcl/locale-procs-oracle.xql"/>
             <file type="query_file" db_type="postgresql" path="tcl/locale-procs-postgresql.xql"/>
             <file type="tcl_procs" path="tcl/locale-procs.tcl"/>
@@ -67,39 +69,77 @@
             <file type="query_file" db_type="postgresql" path="tcl/localization-procs-postgresql.xql"/>
             <file type="tcl_procs" path="tcl/localization-procs.tcl"/>
             <file type="query_file" path="tcl/localization-procs.xql"/>
-            <file type="content_page" path="www/catalog-test.adp"/>
-            <file type="content_page" path="www/catalog-test.tcl"/>
-            <file type="content_page" path="www/compile.tcl"/>
+            <file type="tcl_util" path="test/proc-tests.tcl"/>
+            <file type="content_page" path="www/admin/display-grouped-messages.adp"/>
+            <file type="content_page" path="www/admin/display-grouped-messages.tcl"/>
+            <file type="content_page" path="www/admin/display-localized-messages.adp"/>
+            <file type="content_page" path="www/admin/display-localized-messages.tcl"/>
+            <file type="content_page" path="www/admin/edit-localized-message-2.tcl"/>
+            <file type="content_page" path="www/admin/edit-localized-message.adp"/>
+            <file type="content_page" path="www/admin/edit-localized-message.tcl"/>
+            <file type="content_page" path="www/admin/index.adp"/>
+            <file type="content_page" path="www/admin/index.tcl"/>
+            <file type="content_page" path="www/admin/load-catalog-files.tcl"/>
+            <file type="content_page" path="www/admin/locale-delete-confirm.adp"/>
+            <file type="content_page" path="www/admin/locale-delete.adp"/>
+            <file type="content_page" path="www/admin/locale-delete.tcl"/>
+            <file type="content_page" path="www/admin/locale-edit.adp"/>
+            <file type="content_page" path="www/admin/locale-edit.tcl"/>
+            <file type="content_page" path="www/admin/locale-make-default.tcl"/>
+            <file type="content_page" path="www/admin/locale-new.adp"/>
+            <file type="content_page" path="www/admin/locale-new.tcl"/>
+            <file type="content_page" path="www/admin/locales-tabs.adp"/>
+            <file type="content_page" path="www/admin/locales-tabs.tcl"/>
+            <file type="content_page" path="www/admin/locales.adp"/>
+            <file type="content_page" path="www/admin/locales.tcl"/>
+            <file type="content_page" path="www/admin/localized-message-new-2.adp"/>
+            <file type="content_page" path="www/admin/localized-message-new-2.tcl"/>
+            <file type="content_page" path="www/admin/localized-message-new-3.tcl"/>
+            <file type="content_page" path="www/admin/localized-message-new.adp"/>
+            <file type="content_page" path="www/admin/localized-message-new.tcl"/>
+            <file type="content_page" path="www/admin/localized-messages.adp"/>
+            <file type="content_page" path="www/admin/localized-messages.tcl"/>
+            <file type="content_page" path="www/admin/master.adp"/>
+            <file type="content_page" path="www/admin/master.tcl"/>
+            <file type="content_page" path="www/admin/test/catalog-test.adp"/>
+            <file type="content_page" path="www/admin/test/catalog-test.tcl"/>
+            <file type="content_page" path="www/admin/test/compile.tcl"/>
+            <file type="query_file" db_type="oracle" path="www/admin/test/format-test-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="www/admin/test/format-test-postgresql.xql"/>
+            <file type="content_page" path="www/admin/test/format-test.adp"/>
+            <file type="content_page" path="www/admin/test/format-test.tcl"/>
+            <file type="content_page" path="www/admin/test/index.html"/>
+            <file type="content_page" path="www/admin/test/show-catalog.adp"/>
+            <file type="content_page" path="www/admin/test/show-catalog.tcl"/>
+            <file type="content_page" path="www/admin/test/show.tcl"/>
+            <file type="query_file" db_type="oracle" path="www/admin/test/test-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="www/admin/test/test-postgresql.xql"/>
+            <file type="content_page" path="www/admin/test/test.adp"/>
+            <file type="content_page" path="www/admin/test/test.tcl"/>
+            <file type="query_file" db_type="oracle" path="www/admin/test/timezone-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="www/admin/test/timezone-postgresql.xql"/>
+            <file type="content_page" path="www/admin/test/timezone.adp"/>
+            <file type="content_page" path="www/admin/test/timezone.tcl"/>
+            <file type="content_page" path="www/admin/test/tz-test.tcl"/>
+            <file type="content_page" path="www/change-locale-include.adp"/>
+            <file type="content_page" path="www/change-locale-include.tcl"/>
+            <file type="content_page" path="www/change-locale.tcl"/>
             <file type="documentation" path="www/doc/RELEASE-NOTES"/>
             <file type="documentation" path="www/doc/acs4-patches.txt"/>
             <file type="documentation" path="www/doc/i18n-design.html"/>
             <file type="documentation" path="www/doc/i18n-requirements.html"/>
+            <file type="documentation" path="www/doc/index.html"/>
             <file type="documentation" path="www/doc/questions"/>
-            <file type="query_file" db_type="oracle" path="www/format-test-oracle.xql"/>
-            <file type="query_file" db_type="postgresql" path="www/format-test-postgresql.xql"/>
-            <file type="content_page" path="www/format-test.adp"/>
-            <file type="content_page" path="www/format-test.tcl"/>
-            <file type="content_page" path="www/index.html"/>
+            <file type="content_page" path="www/index.adp"/>
+            <file type="content_page" path="www/index.tcl"/>
             <file type="content_page" path="www/locale-set.tcl"/>
             <file type="query_file" db_type="oracle" path="www/set-system-timezone-oracle.xql"/>
             <file type="query_file" db_type="postgresql" path="www/set-system-timezone-postgresql.xql"/>
             <file type="content_page" path="www/set-system-timezone.tcl"/>
-            <file type="content_page" path="www/show-catalog.adp"/>
-            <file type="content_page" path="www/show-catalog.tcl"/>
-            <file type="content_page" path="www/show.tcl"/>
-            <file type="query_file" db_type="oracle" path="www/test-oracle.xql"/>
-            <file type="query_file" db_type="postgresql" path="www/test-postgresql.xql"/>
-            <file type="content_page" path="www/test.adp"/>
-            <file type="content_page" path="www/test.tcl"/>
-            <file type="query_file" db_type="oracle" path="www/timezone-oracle.xql"/>
-            <file type="query_file" db_type="postgresql" path="www/timezone-postgresql.xql"/>
-            <file type="content_page" path="www/timezone.adp"/>
-            <file type="content_page" path="www/timezone.tcl"/>
-            <file type="content_page" path="www/tz-test.tcl"/>
-            <file type="documentation" path="www/doc/index.html"/>
         </files>
         <parameters>
             <parameter datatype="string"  min_n_values="1"  max_n_values="1"  name="SystemTimezone"  default="America/New_York" description="The timezone that Oracle is set to use. Use a name from the acs-reference package, e.g., America/Los_Angeles or Asia/Tokyo"/>
+            <parameter datatype="string"  min_n_values="1"  max_n_values="1"  name="SiteWideLocale"  default="de_DE" description="The site-wide default locale"/>
         </parameters>
 
     </version>
Index: openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql	10 Jul 2002 11:57:19 -0000	1.2
+++ openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql	7 Oct 2002 14:32:42 -0000	1.3
@@ -95,3 +95,13 @@
 );
 
 commit;
+
+create table ad_locale_user_prefs (
+       user_id                        integer
+                                      primary key
+                                      references users (user_id),
+       locale                         varchar2(30) not null
+                                      constraint
+                                      trb_language_preference_lid_fk
+                                      references ad_locales (locale)
+);
Index: openacs-4/packages/acs-lang/sql/oracle/message-catalog-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/message-catalog-drop.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/sql/oracle/message-catalog-drop.sql	10 Jul 2002 11:57:19 -0000	1.2
+++ openacs-4/packages/acs-lang/sql/oracle/message-catalog-drop.sql	7 Oct 2002 14:32:42 -0000	1.3
@@ -1,7 +1,7 @@
 --
 -- packages/language/sql/language-drop.sql
 --
--- @author davis@xarg.net
+-- @author davis@arsdigita.com
 -- @creation-date 2000-09-10
 -- @cvs-id $Id$
 --
Index: openacs-4/packages/acs-lang/sql/oracle/message-catalog.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/message-catalog.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/sql/oracle/message-catalog.sql	10 Jul 2002 11:57:19 -0000	1.2
+++ openacs-4/packages/acs-lang/sql/oracle/message-catalog.sql	7 Oct 2002 14:32:42 -0000	1.3
@@ -1,20 +1,40 @@
 --
--- packages/acs-i18n/sql/language-create.sql
+-- packages/gp-lang/sql/language-create.sql
 --
--- @author Jeff Davis (davis@xarg.net)
+-- @author Jeff Davis (davis@arsdigita.com)
+-- @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+--
 -- @creation-date 2000-09-10
 -- @cvs-id $Id$
 --
 
+create table lang_keys (
+    key                varchar2(200),
+    package_key        varchar2(100)
+                       constraint lang_keys_pk_fk
+                       references apm_package_types (package_key)
+);
+
 create table lang_messages (    
-        key     	varchar2(200),
-	lang		char(2) not null,
-        message         clob,
-        registered_p    char(1)
-                        constraint lm_tranlated_p_tf check(registered_p in ('t','f')),
-        constraint lang_messages_pk primary key (key, lang)
+    key                    varchar2(200)
+                           constraint lang_messages_key_fk
+                           references lang_keys(key),
+    locale                 varchar2(30) 
+                           constraint lang_messages_locale_fk
+                           references ad_locales(locale)
+                           constraint lang_messages_locale_nn
+                           not null,
+    message                clob,
+    registered_p           char(1)
+                           constraint lm_tranlated_p_ck check(registered_p in ('t','f')),
+    constraint lang_messages_pk primary key (key, locale)
 );
 
+comment on table lang_messages is '
+    Holds all the messages translated. The key is the way to get to a message.
+    This table should be read at boot time -from ACS- to load all the messages
+    into an nsv_array.
+';
 
 -- ****************************************************************************
 -- * The lang_translate_columns table holds the columns that require translation.
@@ -23,26 +43,27 @@
 -- ****************************************************************************
 
 create table lang_translate_columns (   
-        column_id               integer primary key,
+        column_id integer 
+	    constraint ltc_column_id_pk primary key,
         -- cant do references on user_tables cause oracle sucks
-        on_which_table          varchar2(50),
-        on_what_column          varchar2(50),
+        on_which_table varchar2(50),
+        on_what_column varchar2(50),
         --
         -- whether all entries in a column must be translated for the 
         -- site to function.
         --
         -- probably ultimately need something more sophisticated than 
         -- simply required_p
         --
-        required_p              char(1)
-                                constraint ltc_required_p_tf check(required_p in ('t','f')),
+        required_p char(1)
+            constraint ltc_required_p_ck check(required_p in ('t','f')),
         --
         -- flag for whether to use the lang_translations table for content
         -- or add a row in the on_which_table table with the translated content.
         --
-        short_p                 char(1)
-                                constraint ltc_short_p_tf check(short_p in ('t','f')),
-        constraint  ltc_u unique (on_which_table, on_what_column)
+        short_p char(1)
+            constraint ltc_short_p_ck check(short_p in ('t','f')),
+        constraint ltc_un unique (on_which_table, on_what_column)
 );
 
 
@@ -53,16 +74,15 @@
 -- ****************************************************************************
 
 create table lang_translation_registry (
-	on_which_table		varchar(50),
-	on_what_id		integer not null,
-        locale                  constraint ltr_locale_ref
-                                references ad_locales(locale),
+	on_which_table varchar(50),
+	on_what_id integer 
+	    constraint ltr_on_what_id_nn not null,
+        locale varchar2(30)
+	    constraint ltr_locale_fk
+            references ad_locales(locale),
         --
         -- should have dependency info here
         --
         constraint lang_translation_registry_pk primary key(on_what_id, on_which_table, locale)
 );
 
-
-
-
Index: openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-4.1-4.7.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/upgrade/Attic/upgrade-4.1-4.7.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-4.1-4.7.sql	7 Oct 2002 14:32:43 -0000	1.1
@@ -0,0 +1,72 @@
+--
+-- Upgrade script from 4.1 to 4.7
+--
+-- Changes lang_messages so it uses locale instead of language
+-- by looking up the default locale in ad_locales.
+--
+-- There two things that could go wrong here:
+--
+-- 1. There could be no locale at all for some language
+--    in that case the scripts adds a new locale
+-- 2. There could be no default locale
+--    the script makes sure that theres is one default locale
+--    pr. language 
+--
+-- @author Christian Hvid
+--
+
+-- Make sure that there is a default for every language
+
+UPDATE ad_locales
+SET    default_p = 't'
+WHERE  (SELECT count(*) 
+        FROM   ad_locales a 
+        WHERE  a.language = ad_locales.language AND default_p='t') = 0;
+
+-- Make sure that there is a locale for every language used in lang_messages
+
+INSERT INTO ad_locales (language, locale, country, label, nls_language, default_p)
+SELECT      language, 
+            language || '_' || UPPER(language) as locale, 
+             '??' as country, 
+             'Locale created by upgrade-4.1-4.7 for language ' || language as label,
+             '??' as nls_language, 
+             't' as default_p
+FROM 
+  ((SELECT DISTINCT lang as language 
+    FROM            lang_messages) MINUS
+   (SELECT DISTINCT language
+    FROM            ad_locales));
+
+create table temp (    
+  key                     varchar(200),
+  lang                    varchar(2),
+  message                 clob,
+  registered_p char(1)
+);
+
+INSERT INTO temp(key, lang, message, registered_p) 
+SELECT      key, lang, message, registered_p
+FROM        lang_messages;
+
+DROP TABLE lang_messages;
+
+create table lang_messages (    
+    key varchar2(200),
+    locale varchar2(30) 
+        constraint lang_messages_locale_fk
+            references ad_locales(locale)
+        constraint lang_messages_locale_nn
+	    not null,
+    message clob,
+    registered_p char(1)
+        constraint lm_tranlated_p_ck check(registered_p in ('t','f')),
+        constraint lang_messages_pk primary key (key, locale)
+);
+
+INSERT INTO lang_messages(key, locale, message, registered_p) 
+SELECT      key, ad_locales.locale, message, registered_p
+FROM        temp, ad_locales
+WHERE       ad_locales.language = temp.lang;
+
+DROP TABLE temp;
Index: openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql	10 Jul 2002 11:57:19 -0000	1.2
+++ openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql	7 Oct 2002 14:32:44 -0000	1.3
@@ -19,9 +19,11 @@
   locale		varchar(30)
                         constraint ad_locale_abbrev_pk
                         primary key,
-  language		char(2) constraint ad_language_name_nil
+  language		char(2) 
+                        constraint ad_language_name_nil
 			not null,
-  country		char(2) constraint ad_country_name_nil
+  country		char(2) 
+                        constraint ad_country_name_nil
 			not null,
   variant		varchar(30),
   label			varchar(200)
@@ -51,6 +53,23 @@
   nls_charset is  Oracle charset name
 ';
 
+create table ad_locale_user_prefs (
+  user_id               integer
+                        constraint ad_locale_user_prefs_pk
+                        primary key
+                        constraint ad_locale_user_prefs_users_fk
+                        references users (user_id) on delete cascade,
+  locale                varchar(30) not null
+                        constraint trb_language_preference_lid_fk
+                        references ad_locales (locale) on delete cascade
+);
+
+--
+--
+-- And now for some default locales
+--
+--
+
 insert into ad_locales (
   locale, label, language, country,
   nls_language, nls_territory, nls_charset, mime_charset, default_p
@@ -96,3 +115,4 @@
 );
 
 end;
+
Index: openacs-4/packages/acs-lang/sql/postgresql/message-catalog.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/message-catalog.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/sql/postgresql/message-catalog.sql	10 Jul 2002 11:57:19 -0000	1.2
+++ openacs-4/packages/acs-lang/sql/postgresql/message-catalog.sql	7 Oct 2002 14:32:44 -0000	1.3
@@ -9,11 +9,16 @@
 begin;
 
 create table lang_messages (    
-        key     	varchar(200),
-	lang		char(2) not null,
-        message         text,
-        registered_p	boolean,
-        constraint lang_messages_pk primary key (key, lang)
+  key                     varchar(200),
+  locale                  varchar(30) 
+                          constraint lang_messages_locale_fk
+                          references ad_locales(locale)
+                          constraint lang_messages_locale_nn
+                          not null,
+  message                 text,
+  registered_p            boolean,
+  constraint lang_messages_pk 
+  primary key (key, locale)
 );
 
 
Index: openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-4.1-4.7.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/upgrade/Attic/upgrade-4.1-4.7.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-4.1-4.7.sql	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,73 @@
+--
+-- Upgrade script from 4.1 to 4.7
+--
+-- Changes lang_messages so it uses locale instead of language
+-- by looking up the default locale in ad_locales.
+--
+-- There two things that could go wrong here:
+--
+-- 1. There could be no locale at all for some language
+--    in that case the scripts adds a new locale
+-- 2. There could be no default locale
+--    the script makes sure that theres is one default locale
+--    pr. language 
+--
+-- @author Christian Hvid
+--
+
+-- Make sure that there is a default for every language
+
+UPDATE ad_locales
+SET    default_p = 't'
+WHERE  (SELECT count(*) 
+        FROM   ad_locales AS a 
+        WHERE  a.language = ad_locales.language AND default_p='t') = 0;
+
+-- Make sure that there is a locale for every language used in lang_messages
+
+INSERT INTO ad_locales (language, locale, country, label, nls_language, default_p)
+SELECT      language, 
+            language || '_' || UPPER(language) as locale, 
+             '??' as country, 
+             'Locale created by upgrade-4.1-4.7 for language ' || language as label,
+             '??' as nls_language, 
+             't' as default_p
+FROM 
+  ((SELECT DISTINCT lang as language 
+    FROM            lang_messages) EXCEPT
+   (SELECT DISTINCT language
+    FROM            ad_locales)) as new_languages;
+
+create table temp (    
+  key                     varchar(200),
+  lang                    varchar(2),
+  message                 text,
+  registered_p            boolean
+);
+
+INSERT INTO temp(key, lang, message, registered_p) 
+SELECT      key, lang, message, registered_p
+FROM        lang_messages;
+
+DROP TABLE lang_messages;
+
+create table lang_messages (    
+  key                     varchar(200),
+  locale                  varchar(30) 
+                          constraint lang_messages_locale_fk
+                          references ad_locales(locale)
+                          constraint lang_messages_locale_nn
+                          not null,
+  message                 text,
+  registered_p            boolean,
+  constraint lang_messages_pk 
+  primary key (key, locale)
+);
+
+INSERT INTO lang_messages(key, locale, message, registered_p) 
+SELECT      key, ad_locales.locale, message, registered_p
+FROM        temp, ad_locales
+WHERE       cast (ad_locales.language as text) = cast (temp.lang as text)
+AND         ad_locales.default_p = 't';
+
+DROP TABLE temp;
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/acs-lang-procs.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/tcl/lang-catalog-init.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/Attic/lang-catalog-init.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-catalog-init.tcl	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,31 @@
+#/packages/acs-lang/tcl/lang-catalog-init.tcl
+ad_library {
+    Loads files that contain messages.
+    <p>
+    This is free software distributed under the terms of the GNU Public
+    License.  Full text of the license is available from the GNU Project:
+    http://www.fsf.org/copyleft/gpl.html
+
+    @creation-date 10 September 2000
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @author Peter Marklund (peter@collaboraid.biz)
+    @author Lars Pind (lars@collaboraid.biz)
+    @cvs-id $Id: lang-catalog-init.tcl,v 1.1 2002/10/07 14:32:45 lars Exp $
+}
+
+#####
+#
+# Load catalog files from all packages into the database
+#
+#####
+
+# This is done in a scheduled proc so that it won't take up time at server startup.
+# Instead, it can be done by a thread after the server has started multithreading.
+#
+# Peter Marklund, 7 October 2002: Commenting out since we don't want to source the catalog
+# files on every startup (we want to source them just once). If the acs_messages table 
+# had a package_key column we could easily
+# check if a certain package has already had its catalog files sourced or not.
+
+#ad_schedule_proc -once t 5 lang::catalog::load_all
Index: openacs-4/packages/acs-lang/tcl/lang-catalog-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-catalog-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-catalog-procs.tcl	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,148 @@
+#/packages/acs-lang/tcl/lang-catalog-procs.tcl
+ad_library {
+
+    Routines for loading message catalog files 
+    <p>
+    This is free software distributed under the terms of the GNU Public
+    License.  Full text of the license is available from the GNU Project:
+    http://www.fsf.org/copyleft/gpl.html
+
+    @creation-date 10 September 2000
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @author Peter Marklund (peter@collaboraid.biz)
+    @author Lars Pind (lars@collaboraid.biz)
+    @cvs-id $Id: lang-catalog-procs.tcl,v 1.1 2002/10/07 14:32:45 lars Exp $
+}
+
+namespace eval lang::catalog {
+
+    ad_proc -public load {
+        {package_key "acs-lang"} 
+    } { 
+        Load the message catalogs from a package, defaults to /packages/acs-lang/catalog/ directory.
+        Catalogs specify the MIME charset name of their encoding in their pathname.
+    
+        @author Jeff Davis (davis@arsdigita.com)
+        @return Number of files loaded
+    
+    } { 
+        set glob_pattern [file join [acs_package_root_dir $package_key] catalog *.cat]
+        ns_log Notice "Starting load of the message catalogs $glob_pattern"
+        
+        global __lang_catalog_load_package_key
+        set __lang_catalog_load_package_key $package_key
+    
+        set files [glob -nocomplain $glob_pattern]
+        
+        set charsets [ns_charsets]
+    
+        if {[empty_string_p $files]} { 
+            ns_log Warning "no files found in message catalog directory"
+        } else { 
+            foreach msg_file $files { 
+                if {![regexp {/([^/]*)\.([^/]*)\.cat$} $msg_file match base msg_encoding]} { 
+                    ns_log Warning "assuming $msg_file is iso-8859-1" 
+                    set msg_encoding iso-8859-1
+                }
+                 
+                if {[lsearch -exact $charsets $msg_encoding] < 0} { 
+                    ns_log Warning "$msg_file in $msg_encoding not supported by tcl, assuming [encoding system]"
+                    set msg_encoding [encoding system]
+                }
+                
+                ns_log Notice "Loading $msg_file in $msg_encoding"
+                set in [open $msg_file]
+                fconfigure $in -encoding [ns_encodingforcharset $msg_encoding]
+                set src [read $in]
+                close $in 
+                
+                eval $src
+                #if {[catch {eval $src} errMsg]} { 
+                #    ns_log Warning "Failed loading message catalog $msg_file:\n$errMsg"
+                #}
+            }
+        }
+    
+        ns_log Notice "Finished load of the message catalog" 
+        
+        unset __lang_catalog_load_package_key 
+    
+        return $files
+    }
+        
+    ad_proc -public load_all {} {
+        Loops over all installed and enabled packages and invokes lang_catalog_load
+        for each package.
+    } {
+        db_foreach all_enabled_packages {} {
+            if { [file isdirectory [file join [acs_package_root_dir $package_key] catalog]] } {
+                lang_catalog_load $package_key
+            }
+        }
+    }
+    
+    ad_proc -private translate {} {
+        Translates all untranslated strings in a message catalog
+        from English into Spanish, French and German
+        using Babelfish. Quick way to get a multilingual site up and
+        running if you can live with the quality of the translations.
+        <p>
+        Not a good idea to run this procedure if you have
+        a large message catalog. Use for testing purposes only.
+    
+        @author            John Lowry (lowry@arsdigita.com)
+    
+    } {
+        set default_locale [parameter::get -package_id [apm_package_id_from_key acs-lang] -parameter SiteWideLocale]
+        db_foreach get_untranslated_messages {} {
+    
+            foreach lang [list es_ES fr_FR de_DE] {
+                if [catch {
+                    set translated_message [lang_babel_translate $message en_$lang]
+                } errmsg] {
+                    ns_log Notice "Error translating $message into $lang: $errmsg"
+                } else {
+                    _mr $lang $key $translated_message
+                }
+            }
+        }                 
+    }
+
+}
+
+#####
+#
+# Backwards compatibility procs
+#
+#####
+
+ad_proc -deprecated -warn lang_catalog_load_all {} {
+    @see lang::catalog::load_all
+} {
+    return [lang::catalog::load_all]
+}
+    
+ad_proc -deprecated -warn lang_catalog_load {
+    {package_key "acs-lang"} 
+} {
+    @see lang::catalog::load_all
+} {
+    return [lang::catalog::load $package_key]
+}
+
+ad_proc -deprecated -warn lang_translate_message_catalog {} {
+    Translates all untranslated strings in a message catalog
+    from English into Spanish, French and German
+    using Babelfish. Quick way to get a multilingual site up and
+    running if you can live with the quality of the translations.
+    <p>
+    Not a good idea to run this procedure if you have
+    a large message catalog. Use for testing purposes only.
+
+    @author            John Lowry (lowry@arsdigita.com)
+
+    @see lang::catalog::translate
+} {
+    return [lang::catalog::translate]
+}
Index: openacs-4/packages/acs-lang/tcl/lang-catalog-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-catalog-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-catalog-procs.xql	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<queryset>
+
+  <fullquery name="lang::catalog::load_all.all_enabled_packages">
+    <querytext>
+      select package_key
+      from   apm_package_types
+      where  exists (select 1 
+                     from   apm_package_versions
+                     where  installed_p = 't'
+                     and    enabled_p = 't')
+    </querytext>
+  </fullquery>
+
+  <fullquery name="lang::catalog::translate.get_untranslated_messages">
+    <querytext>
+      select key,
+             message 
+      from   lang_messages lm1 
+      where  locale = :default_locale
+      and    not exists (select 1 
+                         from   lang_messages lm2 
+                         where  locale != :default_locale
+                         and    lm1.key = lm2.key)
+    </querytext>
+  </fullquery>
+
+</queryset>
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-init-oracle.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-init-postgresql.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-init.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/tcl/lang-message-init.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/Attic/lang-message-init.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-message-init.tcl	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,22 @@
+#/packages/acs-lang/tcl/lang-message-init.tcl
+ad_library {
+
+    Initializes the message cache.
+    <p>
+    This is free software distributed under the terms of the GNU Public
+    License.  Full text of the license is available from the GNU Project:
+    http://www.fsf.org/copyleft/gpl.html
+
+    @creation-date 10 September 2000
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @author Peter Marklund (peter@collaboraid.biz)
+    @author Lars Pind (lars@collaboraid.biz)
+    @cvs-id $Id: lang-message-init.tcl,v 1.1 2002/10/07 14:32:45 lars Exp $
+}
+
+#
+# Cache the message catalog from the database
+#
+
+lang::message::cache
Index: openacs-4/packages/acs-lang/tcl/lang-message-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-message-procs-oracle.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-message-procs-oracle.xql	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<queryset>
+  <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
+
+  <fullquery name="lang::message::register.lang_message_update">
+    <querytext>
+      update lang_messages
+      set    registered_p = 't',
+             message = empty_clob()
+      where  locale = :locale 
+      and    key = :key
+      returning message into :1
+    </querytext>
+  </fullquery>
+
+  <fullquery name="lang::message::register.lang_message_insert">      
+    <querytext>
+      insert into lang_messages (key, locale, message, registered_p) 
+      values (:key, :locale, empty_clob(), 't') 
+      returning message into :1
+    </querytext>
+  </fullquery>
+
+</queryset>
Index: openacs-4/packages/acs-lang/tcl/lang-message-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-message-procs-postgresql.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-message-procs-postgresql.xql	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<queryset>
+  <rdbms><type>postgresql</type><version>7.2</version></rdbms>
+
+  <fullquery name="lang::message::register.lang_message_update">
+    <querytext>
+      update lang_messages
+      set    registered_p = 't',
+             message = :message
+      where  locale = :locale 
+      and    key = :key
+    </querytext>
+  </fullquery>
+
+  <fullquery name="lang::message::register.lang_message_insert">      
+    <querytext>
+      insert into lang_messages (key, locale, message, registered_p) 
+      values (:key, :locale, :message, 't') 
+    </querytext>
+  </fullquery>
+
+</queryset>
Index: openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,399 @@
+#/packages/acs-lang/tcl/lang-message-procs.tcl
+ad_library {
+
+    Routines for displaying web pages in multiple languages
+    <p>
+    This is free software distributed under the terms of the GNU Public
+    License.  Full text of the license is available from the GNU Project:
+    http://www.fsf.org/copyleft/gpl.html
+
+    @creation-date 10 September 2000
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @author Peter Marklund (peter@collaboraid.biz)
+    @author Lars Pind (lars@collaboraid.biz)
+    @cvs-id $Id: lang-message-procs.tcl,v 1.1 2002/10/07 14:32:45 lars Exp $
+}
+
+namespace eval lang::message {
+
+    ad_proc -public register { 
+        locale
+        key
+        message
+    } { 
+        Normally accessed through the _mr procedure.
+        Registers a message in a given locale or language.
+        Inserts the message into the table lang_messages
+        if it does not exist and updates if it does.
+    
+        @author Jeff Davis (davis@arsdigita.com)
+        @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+        @see _mr
+        
+        @param locale  Locale or language of the message. If a language is supplied,
+                       the default locale for the language is looked up. 
+                       Taken from ad_locales table.
+        @param key     Unique identifier for this message. Will be the same identifier
+                       for each language
+        @param message Text of the message
+    
+    } { 
+        # First we check if the given key already exists
+        # or if this is different than what we have saved.
+        
+        # Check if the $lang parameter is a language or a locale
+        if { [string length $locale] == 2 } {
+            # It seems to be a language (iso codes are 2 characters)
+            # We don't do a more throughout check since this is not
+            # invoked by users.
+            # let's get the default locale for that language
+            set locale [util_memoize [list ad_locale_locale_from_lang $locale]]
+        } 
+    
+        # Check the cache
+        if { [nsv_exists lang_message_$locale $key] } { 
+
+            set old_message [nsv_get lang_message_$locale $key]
+
+            if { ![string equal $message $old_message] } {
+
+                # changed message ... update.
+
+                # Trying to avoid hitting Oracle bug#2011927
+    
+                if { [empty_string_p [string trim $message]] } {
+                    db_dml lang_message_null_update {}
+                } else { 
+                    db_dml lang_message_update {} -clobs [list $message]
+                }
+                nsv_set lang_message_$locale $key $message
+            }
+        } else { 
+            ns_log Notice "Inserting into database message: $locale $key" 
+            db_transaction {
+                # As above, avoiding the bug#2011927 from Oracle.
+    
+                if { [empty_string_p [string trim $message]] } {
+                    db_dml lang_message_insert_null_msg {}
+                } else {
+                    # LARS:
+                    # We may need to have two different lines here, one for
+                    # Oracle w/clobs, one for PG w/o clobs.
+                    db_dml lang_message_insert {} -clobs [list $message]
+                }
+                nsv_set lang_message_$locale $key $message
+            }
+        }
+    }
+    
+    ad_proc -public lookup {
+        locale
+        key
+        {default "TRANSLATION MISSING"}
+    } {
+        Normally accessed through the _ procedure.
+    
+        Returns a translated string for the given language and message key.
+    
+        The key of the localized message is stored in the following format,
+        string1.string2 where string1 is a string that contains only alpha
+        characters and '-' concateneted with a '.' and string2 is the 
+        identification of the message.
+        
+        The lookup is tried in this order:
+    
+        1 A check is done by prefixing the key with
+            the package key of the request.
+        2. If there is no match, a lookup is performed with the key
+             prepended with 'generic.' since it doesn't contain a dot.
+        3. If there is no match a check is done with the full key and
+             a warning is issued if a match is found since this means the key is uncategorized.
+             All keys should belong to a package or be generic/site-wide.
+        4. If there is still no match the default message is issued.
+    
+        @author Jeff Davis (davis@arsdigita.com), Henry Minsky (hqm@arsdigita.com)
+        @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+        @author Peter Marklund (peter@collaboraid.biz)
+        @see _
+        
+        @param locale  Locale (e.g., "en_US") or language (e.g., "en") string.
+        @param key     Unique identifier for this message. Will be the same identifier
+                       for each language
+        @return        The translated string for the message specified by the key in the language specified.
+    } { 
+        # Peter Marklund: I simplified this proc by removing the check for a dot
+        # We could add that check back later for optimization but there was too much
+        # duplication in the proc and it was too complex
+        # TODO: add translation links
+    
+        set full_key $key
+        set default_locale [parameter::get -package_id [apm_package_id_from_key acs-lang] -parameter SiteWideLocale]
+        
+        if { [string length $locale] == 2 } {
+    
+            # it's a language and not a locale
+            # let's get the default locale for this language
+            # The cache is flushed if the default locale for this language is
+            # is changed.
+            set locale [util_memoize [list ad_locale_locale_from_lang $locale]]
+    
+        } 
+    
+        # Since we have for sure the locale (one way or another)
+        set lang [string range $locale 0 1]
+    
+        # Most keys should be prefixed with the package key so try that first
+        if { [catch "set package_key \[ad_conn package_key\].${full_key}" errmsg] } {
+            # This means we have no connection and no package_key to use
+            set package_key $full_key
+        }
+    
+        set generic_key "generic.${full_key}"
+    
+        if { [nsv_exists lang_message_$locale $package_key] } {    
+            # Prefixing with package key
+    
+            return [nsv_get lang_message_$locale $package_key]
+    
+        } elseif { [nsv_exists lang_message_$locale $generic_key] } {                
+            # Prefixing with generic
+    
+            # We found it.
+            return [nsv_get lang_message_$locale $generic_key]
+    
+        } elseif { [nsv_exists lang_message_$locale $full_key] } {
+    
+            if {! [regexp {[\.]} $full_key match] } {
+                ns_log Warning "Warning" "Localized message key \"$full_key\" found but is not categorized (contains no dot)."
+            }
+    
+            return [nsv_get lang_message_$locale $full_key]
+    
+        } else {
+    
+            # Oops. No, not here ... Let's get the translation missing
+            # message out! If we are being queried in the default locale
+            # then we can give the answer right away, if not, requery
+            # ourselves with the default locale (this is the default 
+            # behaviour required).
+    
+            if {[string match $locale $default_locale]} {
+    
+                if {![empty_string_p $default]} {
+    
+                    if { [string equal $default "TRANSLATION MISSING"] } {
+    
+                        append default_answer $default " - " $full_key
+    
+                    } else {
+    
+                        set default_answer $default
+    
+                    }
+    
+                    return $default_answer
+    
+                } else {
+    
+                    return "$key"
+    
+                }
+    
+            } else {
+    
+                # Returning the default (in the default locale)
+                #return "[lang_message_lookup $default_locale $key $default]"
+    
+                # Peter: Just return the default
+                return $default
+            }            
+        }
+    }
+
+    ad_proc -private translate { 
+        msg
+        locale
+    } {
+        Translates an English string into a different language
+        using Babelfish.
+        
+        @author            Henry Minsky (hqm@mit.edu)
+        
+        @param msg         String to translate
+        @param lang        Abbreviation for lang in which to translate string
+        @return            Translated string
+    } {
+        set lang [string range $locale 0 2]
+        set marker "XXYYZZXX. "
+        set qmsg "$marker $msg"
+        set url "http://babel.altavista.com/translate.dyn?doit=done&BabelFishFrontPage=yes&bblType=urltext&url="
+        set babel_result [ns_httpget "$url&lp=$lang&urltext=[ns_urlencode $qmsg]"]
+        set result_pattern "$marker (\[^<\]*)"
+        if [regexp -nocase $result_pattern $babel_result ignore msg_tr] {
+            regsub "$marker." $msg_tr "" msg_tr
+            return [string trim $msg_tr]
+        } else {
+            error "Babelfish translation error"
+        }
+    }     
+
+
+    ad_proc -private cache {} {
+        Loads the entire message catalog from the database into the cache.
+    } {
+        # We segregate messages by language. It might reduce contention
+        # if we segregage instead by package. Check for problems with ns_info locks.
+        
+        set i 0 
+        db_foreach select_locale_keys {} {
+            nsv_set lang_message_$locale $key $message
+            incr i
+        }
+        
+        db_release_unused_handles
+        
+        ns_log Notice "Initialized message table; got $i rows"
+    }
+
+}
+
+
+
+#####
+#
+# Shorthand notation procs _ and _mr
+#
+#####
+
+ad_proc -public _mr { locale key message } {
+
+    Registers a message in a given locale or language.
+    Inserts the message into the table lang_messages
+    if it does not exist and updates if it does.
+
+    @author Jeff Davis (davis@arsdigita.com)
+    
+    @param locale  Abbreviation for language of the message or the locale.
+    @param key     Unique identifier for this message. Will be the same identifier
+                   for each language
+    @param message Text of the message
+
+    @see lang::message::register
+} {
+    return [lang::message::register $locale $key $message]
+}
+
+
+ad_proc -public _ {
+    locale 
+    key 
+    {default "TRANSLATION MISSING"}
+} {
+    Returns a translated string for the given language and message key.
+    If the user is a translator, inserts tags to link to the translator
+    interface. This allows a translator to work from the context of a web page.
+
+    @author Jeff Davis (davis@arsdigita.com)
+    
+    @param locale  Locale or language of the message. Locale is taken from ad_locales table,
+                   language is taken from language_codes table.
+    @param key     Unique identifier for this message. Will be the same identifier
+                   for each locale
+    @return        The translated string for the message specified by the key in the language specified.
+    
+    @see lang::message::lookup
+} {
+    return [lang::message::lookup $locale $key $default]
+}
+    
+
+
+
+#####
+#
+# Backwards compatibility procs
+#
+#####
+
+ad_proc -private -deprecated -warn lang_message_register { locale key message } { 
+
+    Normally accessed through the _mr procedure.
+    Registers a message in a given locale or language.
+    Inserts the message into the table lang_messages
+    if it does not exist and updates if it does.
+
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @see _mr
+    
+    @param locale  Locale or language of the message. If a language is supplied,
+                   the default locale for the language is looked up. 
+                   Taken from ad_locales table.
+    @param key     Unique identifier for this message. Will be the same identifier
+                   for each language
+    @param message Text of the message
+    
+    @see lang::message::register
+} { 
+    return [lang::message::register $locale $key $message]
+}
+
+ad_proc -private -deprecated -warn lang_message_lookup {
+    locale
+    key
+    {default "TRANSLATION MISSING"}
+} {
+    Normally accessed through the _ procedure.
+
+    Returns a translated string for the given language and message key.
+
+    The key of the localized message is stored in the following format,
+    string1.string2 where string1 is a string that contains only alpha
+    characters and '-' concateneted with a '.' and string2 is the 
+    identification of the message.
+    
+    The lookup is tried in this order:
+
+    1 A check is done by prefixing the key with
+        the package key of the request.
+    2. If there is no match, a lookup is performed with the key
+         prepended with 'generic.' since it doesn't contain a dot.
+    3. If there is no match a check is done with the full key and
+         a warning is issued if a match is found since this means the key is uncategorized.
+         All keys should belong to a package or be generic/site-wide.
+    4. If there is still no match the default message is issued.
+
+    @author Jeff Davis (davis@arsdigita.com), Henry Minsky (hqm@arsdigita.com)
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @author Peter Marklund (peter@collaboraid.biz)
+    @see _
+    
+    @param locale  Locale (e.g., "en_US") or language (e.g., "en") string.
+    @param key     Unique identifier for this message. Will be the same identifier
+                   for each language
+    @return        The translated string for the message specified by the key in the language specified.
+    
+    @see lang::message::lookup
+} { 
+    return [lang::message::lookup $locale $key $default]
+}
+
+ad_proc -deprecated -warn lang_babel_translate { 
+    msg
+    lang
+} {
+    Translates an English string into a different language
+    using Babelfish.
+
+    @author            Henry Minsky (hqm@mit.edu)
+
+    @param msg         String to translate
+    @param lang        Abbreviation for lang in which to translate string
+    @return            Translated string
+
+    @see lang::message::translate
+} {
+    return [lang::message::translate $msg $lang]
+}     
+
Index: openacs-4/packages/acs-lang/tcl/lang-message-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-message-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-message-procs.xql	7 Oct 2002 14:32:45 -0000	1.1
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<queryset>
+
+  <fullquery name="lang::message::register.lang_message_null_update">
+    <querytext>
+      update lang_messages 
+      set    registered_p = 't',
+             message = null
+      where  locale = :locale 
+      and    key = :key
+    </querytext>
+  </fullquery>
+
+  <fullquery name="lang::message::register.lang_message_insert">      
+    <querytext>
+      insert into lang_messages (key, locale, message, registered_p)
+      values (:key, :locale, null, 't')
+    </querytext>
+  </fullquery>
+
+  <fullquery name="lang::message::cache.select_locale_keys">
+    <querytext>
+      select locale, key, message 
+      from   lang_messages
+      where  registered_p = 't'
+    </querytext>
+  </fullquery>
+
+</queryset>
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-procs-oracle.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.4 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-procs.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/lang-procs.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/tcl/lang-util-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/Attic/lang-util-procs-postgresql.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-util-procs-postgresql.xql	7 Oct 2002 14:32:46 -0000	1.1
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<queryset>
+   <rdbms><type>postgresql</type><version>7.1</version></rdbms>
+
+   <fullquery name="lang::util::nls_language_from_language.nls_language_from_language">      
+      <querytext>
+      
+        select nls_language
+        from   ad_locales 
+        where  language = :language
+        limit  1
+    
+      </querytext>
+   </fullquery>
+ 
+</queryset>
Index: openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl	7 Oct 2002 14:32:46 -0000	1.1
@@ -0,0 +1,443 @@
+#/packages/acs-lang/tcl/lang-util-procs.tcl
+ad_library {
+
+    Utility routines for translating pages. Many of these procs deal with
+    message keys embedded in strings with the #key# or the <#key text#> syntax.
+    <p>
+    This is free software distributed under the terms of the GNU Public
+    License.  Full text of the license is available from the GNU Project:
+    http://www.fsf.org/copyleft/gpl.html
+
+    @creation-date 10 September 2000
+    @author Jeff Davis (davis@arsdigita.com)
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @author Peter Marklund (peter@collaboraid.biz)
+    @author Lars Pind (lars@collaboraid.biz)
+    @cvs-id $Id: lang-util-procs.tcl,v 1.1 2002/10/07 14:32:46 lars Exp $
+}
+
+namespace eval lang::util {
+
+    ad_proc -public lang_sort {
+        field 
+        {locale {}}
+    } { 
+        Each locale can have a different alphabetical sort order. You can test
+        this proc with the following data:
+        <pre>
+        insert into lang_testsort values ('lama');
+        insert into lang_testsort values ('lhasa');
+        insert into lang_testsort values ('llama');
+        insert into lang_testsort values ('lzim');  
+        </pre>
+    
+        @author Jeff Davis (davis@arsdigita.com)
+    
+        @param field       Name of Oracle column
+        @param locale      Locale for sorting. 
+                           If locale is unspecified just return the column name
+        @return Language aware version of field for Oracle <em>ORDER BY</em> clause.
+    
+    } {
+        # Use west european for english since I think that will fold 
+        # cedilla etc into reasonable values...
+        set lang(en) "XWest_european"
+        set lang(de) "XGerman_din"
+        set lang(fr) "XFrench" 
+        set lang(es) "XSpanish" 
+        
+        if { [empty_string_p $locale] || ![info exists lang($locale)] } {
+            return $field
+        } else { 
+            return "NLSSORT($field,'NLS_SORT = $lang($locale)')"
+        }
+    }
+
+    ad_proc -private get_hash_indices { multilingual_string } {
+        Returns a list of two element lists containing 
+        the start and end indices of a #message_key# match in the multilingual string.
+        This proc is used by the localize proc.
+    
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+
+        set regexp_pattern {(?:^|[^\\])(\#[-a-zA-Z0-9_:\.]+\#)}
+        return [get_regexp_indices $multilingual_string $regexp_pattern]
+    }
+
+    ad_proc get_adp_message_regexp_pattern {} {
+        The regexp expression used by proc get_adp_message_indices and elsewhere
+        to extract temporary message catalog tags (<#...#>) from adp templates.
+        The first sub match of the expression is the whole tag, the second sub match
+        is the message key, and the third sub match is the message text in en_US locale.
+
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+        return {(<#\s*?([-a-zA-Z0-9_:\.]+)\s+([^<]+)#>)}
+    }
+
+    ad_proc get_adp_message_indices { adp_file_string } {
+        Given the contents of an adp file return the indices of the
+        start and end chars of embedded message keys on the syntax:
+    
+        <#package_key.message_key Some en_US text#>    
+    
+        @author Peter marklund (peter@collaboraid.biz)    
+    } {
+        return [lang::util::get_regexp_indices $adp_file_string [get_adp_message_regexp_pattern]]
+    }
+        
+    ad_proc -private get_regexp_indices { multilingual_string regexp_pattern } {
+        Returns a list of two element lists containing 
+        the start and end indices of what is captured by the first parenthesis in the
+        given regexp pattern in the multilingual string. The
+        regexp pattern must follow the syntax of the expression argument to the TCL regexp command.
+        It must also contain exactly one capturing parenthesis for the pieces of text that indices
+        are to be returned for.
+
+        @see get_hash_indices
+    
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+    
+        set multilingual_string_offset "0"
+        set offset_string $multilingual_string
+        set indices_list [list]
+
+        while { [regexp -indices $regexp_pattern $offset_string full_match_idx key_match_idx] } { 
+            
+            set start_idx [lindex $key_match_idx 0]
+            set end_idx [lindex $key_match_idx 1]
+
+            lappend indices_list [list [expr $multilingual_string_offset + $start_idx] \
+                    [expr $multilingual_string_offset + $end_idx]]
+            
+            set new_offset [expr $end_idx + 1]
+            set multilingual_string_offset [expr $multilingual_string_offset + $new_offset]
+            set offset_string [string range $offset_string $new_offset end]
+        }
+        
+        return $indices_list
+    }    
+
+    ad_proc extract_keys_from_adps { adp_files } {
+        Modify the given adp templates by replacing occurencies of
+    
+        <#package_key.message_key Some en_US text#>
+    
+        with #package_key.message_key# and create entries in the file
+        $package_root/catalog/$package_key.en_US.iso-8859-1.cat for
+        each of these keys.
+    
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+    
+        # First open the catalog file of the package to add new message keys to
+        if { [llength $adp_files] > 0 } {
+            set adp_file [lindex $adp_files 0]
+    
+            # Open the corresponding catalog file of the package for writing
+            # Create the catalog directory if it doesn't exist
+            regexp {^packages/([^/]+)} $adp_file full_match package_key
+            set catalog_dir "[acs_root_dir]/packages/$package_key/catalog"
+            if { ![file isdirectory $catalog_dir] } {
+                ns_log Notice "lang_extract_keys_from_adps: Creating new catalog directory $catalog_dir"
+                file mkdir $catalog_dir
+            }
+            set catalog_file_path "$catalog_dir/$package_key.en_US.iso-8859-1.cat"
+            ns_log Notice "lang_extract_keys_from_adps: opening catalog file $catalog_file_path for writing"
+            set catalog_file_id [open "$catalog_file_path" a+]
+            # The file may not end in a new line so add one
+            puts $catalog_file_id "\n"
+        } else {
+            # No files to process so return
+            return
+        }
+
+        # Use the original catalog file contents to determine if a key should
+        # be added to the catalog file or not
+        set original_catalog_file_contents [read $catalog_file_id]
+
+        # Keep track of the messages added to the catalog file
+        array set added_catalog_messages {}
+
+        # Loop over and process the adp files
+        foreach adp_file $adp_files {            
+
+            # We keep track of when we've written to the catalog file to be able
+            # to add a comment for each adp
+            set has_written_to_catalog_file_p "0"
+
+            set full_adp_path "[acs_root_dir]/$adp_file"
+            ns_log Notice "processing adp file $full_adp_path"
+    
+            # Make a backup of the adp file first
+            # Do not overwrite old backup files
+            if { [catch "file copy $full_adp_path \"${full_adp_path}.orig\"" errmsg] } {
+                ns_log Warning "The file $full_adp_path could not be backed up before message key extraction since backup file ${full_adp_path}.orig already exists"
+            }
+    
+            # Read the contents of the adp file
+            set file_contents [template::util::read_file $full_adp_path]
+            set modified_file_contents $file_contents
+    
+            # Loop over each message tag in the adp
+            # Get the indices of the first and last char of the <#...#> text snippets
+            set message_key_indices [lang::util::get_adp_message_indices $file_contents]
+            foreach index_pair $message_key_indices {
+
+                set tag_start_idx [lindex $index_pair 0]
+                set tag_end_idx [lindex $index_pair 1]
+                set message_tag "[string range $file_contents $tag_start_idx $tag_end_idx]"
+                
+                # Extract the message key and the text from the message tag
+                # The regexp on the message tag string should never fail as the message tag
+                # was extracted with a known regexp
+                if { ![regexp [lang::util::get_adp_message_regexp_pattern] $message_tag full_match message_tag message_key new_en_us_text] } {
+                    ns_log Error "Internal programming error: could not extract message key and text from the message tag $message_tag in file $adp_file. This means there is a mismatch with the regexp that extracted the message key."
+                    continue
+                }
+
+                # If the message key doesn't contain the package key prefix then add such a prefix
+                if { ![regexp {\.} $message_key match] } {
+                    set message_key "${package_key}.${message_key}"
+                }
+
+                # Make the key unique so that we can add it to the catalog file
+                set message_key_to_add [get_unique_key_to_add_to_catalog_file $original_catalog_file_contents [array get added_catalog_messages] $message_key $new_en_us_text]
+                if { ![empty_string_p $message_key_to_add] } {
+                    if { ![string equal $message_key_to_add $message_key] } {
+                        # The message key had to be changed to be made unique
+                        ns_log Warning "The message key $message_key was changed to $message_key_to_add to be made unique. If the value was mistyped and should have been the same as previously then you must manually remove the entry for $message_key_to_add from the catalog file and change the key in the adp $adp_file fom $message_key_to_add to $message_key"
+                    }
+
+                    set message_key $message_key_to_add
+                    ns_log Notice "adding message key $message_key to catalog file"
+
+                    if { !$has_written_to_catalog_file_p } {
+                        # Show which template the keys are for
+                        puts $catalog_file_id "# $adp_file"
+                    }
+
+                    puts $catalog_file_id "_mr en_US $message_key \{${new_en_us_text}\}"                    
+                    set added_catalog_messages($message_key) "$new_en_us_text"
+                    set has_written_to_catalog_file_p "1"
+                }  else {
+                    ns_log Notice "message key $message_key already exists in catalog file with same value, not adding"
+                }             
+
+                # Insert new or update existing message key
+                lang::message::register "en_US" $message_key $new_en_us_text
+    
+    
+                # Replace the message tag with the message key
+                regsub [lang::util::get_adp_message_regexp_pattern] $modified_file_contents "#${message_key}#" modified_file_contents
+            }
+    
+            # Update the adp with the replaced message keys
+            set adp_file_id [open $full_adp_path w]
+            puts $adp_file_id "$modified_file_contents"
+            close $adp_file_id
+        }    
+
+        # Close the catalog file
+        if { [info exists catalog_file_id] } {
+            close $catalog_file_id
+        }
+    }   
+
+    ad_proc -private get_unique_key_to_add_to_catalog_file {
+        original_catalog_file_contents
+        added_catalog_messages
+        message_key
+        new_en_us_text
+    } {
+        Returns a unique message key that can be added to the given catalog file
+        contents. If the message key is already in the file with the same value then
+        an empty string is returned indicating that no insertion is needed. If the
+        key already exists in the file with a different value then the key returned
+        will have an integer appended to it to make it unique.
+
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+
+        # Get any existing message from original catalog file
+        regexp "_mr\\s+\\S+\\s+${message_key}\\s+\{(\[^\}\]+)\}" $original_catalog_file_contents match existing_en_us_text
+        
+        # See if we already inserted the message
+        array set added_messages_array $added_catalog_messages 
+        if { ![info exists existing_en_us_text] } {
+            set existing_en_us_text [lindex [array get added_messages_array $message_key] 1]
+        }
+
+        if { [info exists existing_en_us_text] && ![empty_string_p $existing_en_us_text] } {
+
+            # The key already exists in the catalog file, check if the values are the same
+            if { [string equal $new_en_us_text $existing_en_us_text] } {
+                # Value is the same, no need to change the catalog file
+                set add_key_to_catalog_file_p "0"
+            } else {
+                # Value is different. Assume that the new text is correct but that the
+                # key needs to be changed to be unique                    
+                set unique_message_key "${message_key}_2"
+
+                set message_key_to_add [get_unique_key_to_add_to_catalog_file $original_catalog_file_contents [array get added_messages_array] $unique_message_key $new_en_us_text]
+                
+                return $message_key_to_add
+            }
+
+        } else {
+            # The message key is not already in the catalog file so add it
+            set add_key_to_catalog_file_p "1"
+        }
+
+        if { $add_key_to_catalog_file_p } {
+
+            return $message_key
+        } else {
+            # No key should be added to catalog file
+            return ""
+        }
+    }
+    
+    ad_proc -public localize { 
+        string_with_hashes
+    } {
+        Takes a string with embedded message keys on the format #message_key_name#
+        and returns the same string but with the message keys (and their surrounding hash
+        marks) replaced with the corresponding value in the message catalog. Message lookup
+        is done with the locale of the request. If message lookup fails for a certain key
+        then that key is not replaced.
+    
+        @author Peter marklund (peter@collaboraid.biz)
+    } {
+        set indices_list [get_hash_indices $string_with_hashes]
+        
+        set subst_string $string_with_hashes
+        foreach item_idx $indices_list {
+            # The replacement string starts and ends with a hash mark
+            set replacement_string [string range $string_with_hashes [lindex $item_idx 0] \
+                    [lindex $item_idx 1]]
+            set message_key [string range $replacement_string 1 [expr [string length $replacement_string] - 2]]
+            
+            # Attempt a message lookup
+            set message_value [_ [ad_locale request locale] $message_key "not_found"]
+            
+            # Do substitution if message lookup succeeded
+            if { ![string equal $message_value "not_found"] } {                
+                regsub $replacement_string $subst_string $message_value subst_string
+            }
+        }        
+        
+        return $subst_string
+    }
+
+    ad_proc -public charset_for_locale { 
+        locale 
+    } {
+        Returns the MIME charset name corresponding to a locale.
+    
+        @author        Henry Minsky (hqm@mit.edu)
+        @param locale  Name of a locale, as language_COUNTRY using ISO 639 and ISO 3166
+        @return        IANA MIME character set name
+    } {
+        return [db_string charset_for_locale {}]
+    }
+    
+    ad_proc -public default_locale_from_lang { 
+        language
+    } {
+        Returns the default locale for a language
+        
+        @author          Henry Minsky (hqm@mit.edu)
+        @param language  Name of a country, using ISO-3166 two letter code
+        @return          Default locale
+    } {
+        return [db_string default_locale_from_lang {}]
+    }
+
+    ad_proc -public nls_language_from_language { 
+        language 
+    } {
+        Returns the nls_language name for a language
+
+        @author          Henry Minsky (hqm@mit.edu)
+        @param language  Name of a country, using ISO-3166 two letter code
+        @return          The nls_language name of the language.
+    } {
+        return [db_string nls_language_from_language {}]
+    }
+
+
+}
+
+#####
+#
+# Compatibility procs
+#
+#####
+
+ad_proc -deprecated -warn lang_sort {
+    field 
+    {locale {}}
+} { 
+    Each locale can have a different alphabetical sort order. You can test
+    this proc with the following data:
+    <pre>
+    insert into lang_testsort values ('lama');
+    insert into lang_testsort values ('lhasa');
+    insert into lang_testsort values ('llama');
+    insert into lang_testsort values ('lzim');  
+    </pre>
+
+    @author Jeff Davis (davis@arsdigita.com)
+
+    @param field       Name of Oracle column
+    @param locale      Locale for sorting. 
+                       If locale is unspecified just return the column name
+    @return Language aware version of field for Oracle <em>ORDER BY</em> clause.
+
+    @see lang::util::sort
+} {
+    return [lang::util::sort $field $locale]
+}
+
+ad_proc -deprecated -warn ad_locale_charset_for_locale { 
+    locale 
+} {
+    Returns the MIME charset name corresponding to a locale.
+
+    @see           ad_locale
+    @author        Henry Minsky (hqm@mit.edu)
+    @param locale  Name of a locale, as language_COUNTRY using ISO 639 and ISO 3166
+    @return        IANA MIME character set name
+    @see           lang::util::charset_for_locale
+} {
+    return [lang::util::charset_for_locale $locale]
+}
+
+ad_proc -deprecated -warn ad_locale_locale_from_lang { 
+    language
+} {
+    Returns the default locale for a language
+    
+    @author          Henry Minsky (hqm@mit.edu)
+    @param language  Name of a country, using ISO-3166 two letter code
+    @return          Default locale
+    @see             lang::util::default_locale_from_lang
+} {
+    return [lang::util::default_locale_from_lang $language]
+}
+
+ad_proc -deprecated -warn ad_locale_language_name { 
+    language 
+} {
+    Returns the nls_language name for a language
+
+    @author          Henry Minsky (hqm@mit.edu)
+    @param language  Name of a country, using ISO-3166 two letter code
+    @return          The nls_language name of the language.
+    @see             lang::util::nls_language_from_language
+} {
+    return [lang::util::nls_language_from_language $language]
+}
Index: openacs-4/packages/acs-lang/tcl/lang-util-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-util-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/tcl/lang-util-procs.xql	7 Oct 2002 14:32:46 -0000	1.1
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<queryset>
+
+   <fullquery name="lang::util::charset_for_locale.charset_for_locale">      
+      <querytext>
+      
+        select mime_charset
+        from   ad_locales 
+        where  locale = :locale
+    
+      </querytext>
+   </fullquery>
+
+   <fullquery name="lang::util::default_locale_from_lang.default_locale_from_lang">
+      <querytext>
+      
+        select locale 
+        from   ad_locales 
+        where  language = :language
+        and    default_p = 't'
+    
+      </querytext>
+   </fullquery>
+
+</queryset>
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/tcl/locale-init.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/tcl/locale-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/Attic/locale-procs-oracle.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-lang/tcl/locale-procs-oracle.xql	2 May 2001 20:15:34 -0000	1.1
+++ openacs-4/packages/acs-lang/tcl/locale-procs-oracle.xql	7 Oct 2002 14:32:46 -0000	1.2
@@ -3,14 +3,12 @@
 <queryset>
    <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
 
-<fullquery name="ad_locale_system_tz_offset.system_offset">      
+   <fullquery name="lang::system::timezone_utc_offset.system_utc_offset">      
       <querytext>
       
-	select ( (sysdate - timezone.local_to_utc (:system_timezone, sysdate)) * 24 )
-	from dual
+	select ( (sysdate - timezone.local_to_utc (:system_timezone, sysdate)) * 24 ) from dual
     
       </querytext>
-</fullquery>
-
+   </fullquery>
  
 </queryset>
Index: openacs-4/packages/acs-lang/tcl/locale-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/Attic/locale-procs-postgresql.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/tcl/locale-procs-postgresql.xql	4 May 2001 19:29:07 -0000	1.2
+++ openacs-4/packages/acs-lang/tcl/locale-procs-postgresql.xql	7 Oct 2002 14:32:46 -0000	1.3
@@ -3,14 +3,12 @@
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
 
-<fullquery name="ad_locale_system_tz_offset.system_offset">      
+   <fullquery name="lang::system::timezone_utc_offset.system_utc_offset">
       <querytext>
       
 	select ( (current_time - timezone__local_to_utc (:system_timezone, current_time)) * 24 )
-	
     
       </querytext>
-</fullquery>
-
+   </fullquery>
  
 </queryset>
Index: openacs-4/packages/acs-lang/tcl/locale-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/locale-procs.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/tcl/locale-procs.tcl	29 Aug 2001 21:22:49 -0000	1.2
+++ openacs-4/packages/acs-lang/tcl/locale-procs.tcl	7 Oct 2002 14:32:46 -0000	1.3
@@ -9,44 +9,259 @@
 
     @creation-date 28 September 2000
     @author Henry Minsky (hqm@mit.edu)
+    @author Lars Pind (lars@pinds.com)
     @cvs-id $Id$
 }
 
+namespace eval lang::system {
 
-ad_proc -public ad_locale_set_system_timezone { timezone }  { Tell OpenACS 
-what timezone Oracle thinks it is running in. 
+    ad_proc -public locale {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get system locale setting for a given package instance.
+        
+        @param package_id The package for which you want to get the locale setting.
+        @param site_wide Set this if you want to get the site-wide locale setting.
+    } {
+        if { $site_wide_p } {
+            set package_id [apm_package_id_from_key "acs-lang"]
+            return [parameter::get -package_id $package_id -parameter SiteWideLocale]
+        } 
 
-  @param timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
-} {
-    set pid [apm_package_id_from_key "acs-lang"]
-    ad_parameter -set $timezone -package_id $pid SystemTimezone acs-lang 0
-}
+        if { [empty_string_p $package_id] } {
+            set package_id [ad_conn package_id]
+        }
 
+        # Pssst! We don't actually use this package thing, 
+        # but we'll probably do so later.
+        set locale {}
 
-ad_proc -public ad_locale_get_system_timezone { }  { Ask OpenACS 
-what it thinks Oracle's timezone is.
+        # If there's no package setting, use the site-wide setting
+        if { [empty_string_p $locale] } {
+            set locale [locale -site_wide]
+        } 
+        return $locale
+    }
 
-  @return  a timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
-} {
-    set pid [apm_package_id_from_key "acs-lang"]
-    return [ad_parameter -package_id $pid SystemTimezone acs-lang 0]
+    ad_proc -public set_locale {
+        {-package_id ""}
+        {-site_wide:boolean}
+        locale
+    } {
+        Set system locale setting for a given package instance, or the
+        site-wide system locale.
+        
+        @param package_id The package for which you want to set the locale setting.
+        @param site_wide Set this if you want to set the site-wide locale setting.
+        @param locale The new locale that you want to use as your system locale.
+    } {
+        if { $site_wide_p } {
+            set package_id [apm_package_id_from_key "acs-lang"]
+            parameter::set_value -package_id $package_id -parameter SiteWideLocale -value $locale
+        } else {
+            if { [empty_string_p $package_id] } {
+                set package_id [ad_conn package_id]
+            }
+            # Pssst! We don't actually use this package thing, 
+            # but we'll probably do so later.
+            set_locale -site_wide $locale
+        }
+    }
+
+    ad_proc -public language {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get system language setting for a given package instance.
+        
+        @param package_id The package for which you want to get the language setting.
+        @param site_wide Set this if you want to get the site-wide language setting.
+    } {
+        return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1]
+    }
+
+    ad_proc -public timezone {} {
+        Ask OpenACS what it thinks our timezone is.
+        
+        @return  a timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    } {
+        set package_id [apm_package_id_from_key "acs-lang"]
+        return [parameter::get -package_id $package_id -parameter SystemTimezone -default 0]
+    }
+        
+    ad_proc -public set_timezone { 
+        timezone
+    }  { 
+        Tell OpenACS what timezone we think it's running in.
+        
+        @param timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    } {
+        set package_id [apm_package_id_from_key "acs-lang"]
+        parameter::set_value -package_id $package_id -parameter SystemTimezone -value $timezone
+    }
+
+    ad_proc -public timezone_utc_offset { } {
+        @return number of hours to subtract from local (database) time to get UTC
+    } {
+        set system_timezone [timezone]
+        return [db_string system_utc_offset {}]
+    }
+
 }
 
+namespace eval lang::user {
 
-ad_proc -public ad_locale_system_tz_offset { } {
-    @return number of hours to subtract from local (Oracle) time to get UTC
-} {
-    set system_timezone [ad_locale_get_system_timezone]
-    return [db_string system_offset {
-	select ( (sysdate - timezone.local_to_utc (:system_timezone, sysdate)) * 24 )
-	from dual
-    }]
+    ad_proc -public locale {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get user locale preference for a given package instance.
+        This preliminary implementation only has one site-wide setting, though.
+        
+        @param package_id The package for which you want to get the locale preference.
+        @param site_wide Set this if you want to get the site-wide locale preference.
+    } {
+        set user_id [ad_conn user_id]
+        if { $user_id == 0 } {
+            return ""
+        }
+    
+        # Pssst! We don't actually use this package thing, 
+        # but we'll probably do so later.
+        if { $site_wide_p } {
+
+            set package_id [apm_package_id_from_key "acs-lang"]
+            return [db_string get_user_locale {} -default ""]
+
+        } elseif { [empty_string_p $package_id] } {
+            set package_id [ad_conn package_id]
+        }
+        set locale [db_string get_user_locale {} -default ""]
+
+        # If there's no package setting, use the site-wide setting
+        if { [empty_string_p $locale] } {
+            set locale [locale -site_wide]
+        } 
+        return $locale
+    }
+
+    ad_proc -public set_locale {
+        {-package_id ""}
+        {-site_wide:boolean}
+        locale
+    } {
+        Set system locale setting for a given package instance. 
+        This preliminary implementation only has one site-wide setting, though.
+        
+        @param package_id The package for which you want to set the locale setting.
+        @param site_wide Set this if you want to set the site-wide locale setting.
+        @param locale The new locale that you want to use as your system locale.
+    } {
+        set user_id [ad_conn user_id]
+        if { $user_id == 0 } {
+            return
+        }
+    
+        # Pssst! We don't actually use this package thing, 
+        # but we'll probably do so later.
+        if { $site_wide_p } {
+            set package_id [apm_package_id_from_key "acs-lang"]
+        } elseif { [empty_string_p $package_id] } {
+            set package_id [ad_conn package_id]
+        }
+
+        set user_locale_exists_p [db_string user_locale_exists_p {}]
+        if { $user_locale_exists_p } {
+            db_dml update_user_locale {}
+        } else {
+            db_dml insert_user_locale {}
+        }
+    }
+
+    ad_proc -public language {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get user language preference for a given package instance.
+        This preliminary implementation only has one site-wide setting, though.
+        
+        @param package_id The package for which you want to get the language setting.
+        @param site_wide Set this if you want to get the site-wide language setting.
+    } {
+        return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1]
+    }
+
+    ad_proc -public timezone {} {
+        Get the user's timezone. Defaults to system timezone if the user has no setting.
+        
+        @return  a timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    } {
+        # We probably don't want to keep this in client properties, since these are
+        # no longer permanent. We'll move this into a DB table at some point.
+        set timezone [ad_get_client_property -cache t "acs-lang" "timezone"]
+        if { [empty_string_p $timezone] } {
+            # No user timezone, return the system timezone
+            set timezone [parameter::get -parameter DefaultTimezone -package_id [apm_package_id_from_key acs-lang] -default "PST"]
+        }
+        return $timezone
+    }
+        
+    ad_proc -public set_timezone { 
+        timezone
+    }  { 
+        Set the user's timezone setting.
+        
+        @param timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    } {
+        ad_set_client_property -persistent t "acs-lang" timezone $timezone
+    }
+
 }
 
+namespace eval lang::conn {
 
+    ad_proc -public locale {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get the locale for this request, perhaps for a given package instance.
+        
+        @param package_id The package for which you want to get the locale.
+        @param site_wide Set this if you want to get the site-wide locale.
+    } {
+        set locale [lang::user::locale -package_id $package_id -site_wide=$site_wide_p]
+        if { [empty_string_p $locale] } {
+            set locale [lang::system::locale -package_id $package_id -site_wide=$site_wide_p]
+        }
+        return $locale
+    }
 
-ad_proc -public ad_locale {context item} {
+    ad_proc -public language {
+        {-package_id ""}
+        {-site_wide:boolean}
+    } {
+        Get the language for this request, perhaps for a given package instance.
+        
+        @param package_id The package for which you want to get the language.
+        @param site_wide Set this if you want to get the site-wide language.
+    } {
+        return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1]
+    }
+    
+}
 
+
+#####
+#
+# Backwards compatibility procs
+#
+#####
+
+ad_proc -deprecated -warn ad_locale {
+    context 
+    item
+} {
     Returns the value of a locale item in a particular context. For example, to 
     get the language, locale, and timezone preference for the current user:
 
@@ -78,120 +293,111 @@
                    You can change the implementation to add other items as required.
     @return        Value of the item in the specified context
 
+    @see lang::conn::locale
+    @see lang::user::locale
+    @see lang::user::language
+    @see lang::user::timezone
+    @see lang::util::charset_for_locale
 } {
     switch $context {
+        request {
+            return [lang::conn::locale -site_wide]
+        }
 	user {
-	    set locale [ad_get_client_property -cache t "acs-lang" locale]
-	    if {[empty_string_p $locale]} {
-		set locale [ad_parameter DefaultLocale acs-lang "en_US"]
-		ad_locale_set locale $locale
-		ad_locale_set lang  [string range $locale 0 1]
-		ad_locale_set timezone [ad_parameter DefaultTimezone acs-lang "PST"]
-	    }
 	    switch $item {
 		locale {
-		    return $locale
+		    return [lang::user::locale -site_wide]
 		}
 		language {
-		    return [string range $locale 0 1]
+		    return [lang::user::language -site_wide]
 		}
 		timezone {
-		    return [ad_get_client_property -cache t "acs-lang" "timezone"]
+		    return [lang::user::timezone]
 		}
 		default {
 		    error "unsupported option to ad_locale: $item"
 		}
 	    }
 	}
-	subsite {
-	    error "ad_locale: subsite context not yet implemented"
-	}
 	charset {
-	    return [ad_locale_charset_for_locale $item]
+	    return [lang::util::charset_for_locale $item]
 	}
-	fromabbrev {
-	    return [ad_locale_locale_from_abbrev $item]
-	}
 	default {
 	    error "ad_locale: unknown context $context"
 	}
     }
 }
 
-ad_proc -public ad_locale_set  { item value } {
+ad_proc -deprecated -warn ad_locale_set  { 
+    item 
+    value 
+} {
     Sets the user's preferred locale info as a session var
     <p>
     usage:
     <pre>
     ad_locale_set locale "en_US"
     ad_locale_set timezone "PST"
     </pre>
+    @see lang::user::set_locale
+    @see lang::user::set_timezone
 } {
-    set user_id [ad_get_user_id]
-    ad_set_client_property -persistent t "acs-lang" $item $value
+    switch $item {
+        locale {
+            lang::user::set_locale -site_wide $value
+        }
+        timezone {
+            lang::user::set_timezone $value
+        }
+        default {
+            error "Unknown item, $item"
+        }
+    }
 }
 
-ad_proc -public ad_locale_charset_for_locale { locale } {
-
-    Returns the MIME charset name corresponding to a locale.
-
-    @see           ad_locale
-    @author        Henry Minsky (hqm@mit.edu)
+ad_proc -deprecated -warn ad_locale_set_system_timezone { 
+    timezone
+}  { 
+    Tell OpenACS what timezone we think it's running in.
     
-    @param locale  Name of a locale, as language_COUNTRY using ISO 639 and ISO 3166
-
-    @return        IANA MIME character set name
-    
-
+    @param timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    @see lang::system::set_timezone
 } {
-    return [db_string charset_for_locale {
-	select mime_charset
-	  from ad_locales 
-	 where locale = :locale
-    }]
+    lang::system::set_timezone $timezone
 }
 
-ad_proc -public ad_locale_locale_from_lang { language } {
 
-    Returns the default locale for a language
+ad_proc -deprecated -warn ad_locale_get_system_timezone { }  { 
+    Ask OpenACS what it thinks our timezone is.
 
-    @see           ad_locale
-    @author        Henry Minsky (hqm@mit.edu)
-    
-    @param language  Name of a country, using ISO-3166 two letter code
+    @return  a timezone name from acs-reference package (e.g., Asia/Tokyo, America/New_York)
+    @see lang::system::timezone
+} {
+    return [lang::system::timezone]
+}
 
-    @return        IANA MIME character set name
-    
 
-
+ad_proc -deprecated -warn ad_locale_system_tz_offset { } {
+    @return number of hours to subtract from local (Oracle) time to get UTC
+    @see lang::system::timezone_utc_offset
 } {
-    return [db_string default_locale {
-	select locale 
-	  from ad_locales 
-	 where language = :language
-               and default_p = 't'
-    }]
+    return [lang::system::timezone_utc_offset]
 }
 
+ad_proc -deprecated -public ad_locale_get_label { locale } {
 
-ad_proc -public ad_locale_language_name { language } {
+    Returns the label (name) of locale
 
-    Returns the default locale for a language
+    @author	Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
 
-    @see           ad_locale
-    @author        Henry Minsky (hqm@mit.edu)
-    
-    @param language  Name of a country, using ISO-3166 two letter code
+    @param locale	Code for the locale, eg "en_US"
 
-    @return        IANA MIME character set name
-    
+    @return	String containing the label for the locale
 
-
 } {
-    return [db_string default_locale {
-	select nls_language
-	  from ad_locales 
-	 where language = :language
+    return [db_string select_locale_label {
+        select label 
+          from ad_locales
+         where locale = :locale
     }]
 }
-
Index: openacs-4/packages/acs-lang/tcl/locale-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/locale-procs.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-lang/tcl/locale-procs.xql	2 May 2001 20:15:34 -0000	1.1
+++ openacs-4/packages/acs-lang/tcl/locale-procs.xql	7 Oct 2002 14:32:46 -0000	1.2
@@ -1,39 +1,35 @@
 <?xml version="1.0"?>
 <queryset>
 
-<fullquery name="ad_locale_charset_for_locale.charset_for_locale">      
+   <fullquery name="lang::user::locale.get_user_locale">      
       <querytext>
-      
-	select mime_charset
-	  from ad_locales 
-	 where locale = :locale
-    
+        select locale 
+        from   ad_locale_user_prefs 
+        where  user_id = :user_id
       </querytext>
-</fullquery>
+   </fullquery>
 
- 
-<fullquery name="ad_locale_locale_from_lang.default_locale">      
+
+   <fullquery name="lang::user::set_locale.user_locale_exists_p">
       <querytext>
-      
-	select locale 
-	  from ad_locales 
-	 where language = :language
-               and default_p = 't'
-    
+        select count(*) 
+        from   ad_locale_user_prefs 
+        where  user_id = :user_id
       </querytext>
-</fullquery>
+   </fullquery>
 
- 
-<fullquery name="ad_locale_locale_from_lang.default_locale">      
+
+   <fullquery name="lang::user::set_locale.update_user_locale">
       <querytext>
-      
-	select locale 
-	  from ad_locales 
-	 where language = :language
-               and default_p = 't'
-    
+        update ad_locale_user_prefs set locale = :locale where user_id = :user_id
       </querytext>
-</fullquery>
+   </fullquery>
 
- 
+
+   <fullquery name="lang::user::set_locale.insert_user_locale">
+      <querytext>
+         insert into ad_locale_user_prefs (user_id, locale) values (:user_id, :locale)
+      </querytext>
+   </fullquery>
+
 </queryset>
Index: openacs-4/packages/acs-lang/tcl/localization-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/localization-procs.tcl,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/acs-lang/tcl/localization-procs.tcl	10 Sep 2002 22:22:09 -0000	1.3
+++ openacs-4/packages/acs-lang/tcl/localization-procs.tcl	7 Oct 2002 14:32:46 -0000	1.4
@@ -14,31 +14,17 @@
 }
 
 
-ad_proc -private ad_locale_repeat {str k} {
-
-    Repeats a string.
-    
-    @param str    String to repeat
-    @param k      Number of times to repeat
-    @return       Repeated string
+ad_proc -private ad_locale_escape_vars_if_not_null {
+    list
 } {
-    set out {}
-    for {set i 0} {$i < $k} {incr i} {
-       append out $str
-    }
-    return $out
-}
-
-ad_proc -private ad_locale_escape_vars_if_not_null {list} {
-
     Processes a list of variables before they are passed into
     a regexp command.
 
     @param list   List of variable names
 } {
     foreach lm $list {
 	upvar $lm foreign_var
-	if {[exists_and_not_null foreign_var]} {
+	if { [exists_and_not_null foreign_var] } {
 	    set foreign_var "\[$foreign_var\]"
 	}
     }
@@ -52,7 +38,7 @@
     Converts a number to its canonical 
     representation by stripping everything but the 
     decimal seperator and triming left 0's so it 
-    wont be octal. It can process the following types of numbers:
+    won't be octal. It can process the following types of numbers:
     <ul>
     <li>Just digits (allows leading zeros).
     <li>Digits with a valid thousands separator, used consistently (leading zeros not allowed)
@@ -167,7 +153,7 @@
     set group [lindex $grouping 0]
     
     while { 1 && $group > 0} { 
-        set re "$match[ad_locale_repeat $num_re $group])"
+        set re "$match[string repeat $num_re $group])"
         if { ![regsub -- $re $num "\\1$sep\\2" num] } { 
             break 
         } 
@@ -228,19 +214,15 @@
     @return            Formatted monetary amount
 } {
 
-    set row_returned [db_0or1row lc_currency_select {
-	SELECT fractional_digits
-               ,html_entity 
-          FROM currency_codes 
-         WHERE iso = :currency
-    }]
-    if {! $row_returned} {
+    set row_returned [db_0or1row lc_currency_select {}]
+
+    if { !$row_returned } {
 	ns_log Notice "Unsupported monetary currency, defaulting digits to 2"
 	set fractional_digits 2
 	set html_entity ""
     }
     
-    if {$label_p} {
+    if { $label_p } {
 	if {[string compare $style int] == 0} {
 	    set use_as_label $currency
 	} else {
@@ -522,11 +504,7 @@
 
     set local_time $time_value
     if {[catch {
-	set local_time [db_exec_plsql utc_to_local {
-	    begin
-	    :1 := to_char(timezone.utc_to_local(:tz, to_date(:time_value, 'YYYY-MM-DD HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS');
-	    end;
-	}]
+	set local_time [db_exec_plsql utc_to_local {}]
     } errmsg]
     } {
 	ns_log Notice "Query exploded on time conversion from UTC, probably just an invalid date, $time_value: $errmsg"
@@ -552,11 +530,7 @@
 } {
     set utc_time $time_value
     if {[catch {
-	set utc_time [db_exec_plsql local_to_utc {
-	    begin
-	    :1 := to_char(timezone.local_to_utc(:tz, to_date(:time_value, 'YYYY-MM-DD HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS');
-	    end;
-	}]
+	set utc_time [db_exec_plsql local_to_utc {}]
     } errmsg]
     } {
 	ns_log Notice "Query exploded on time conversion to UTC, probably just an invalid date, $time_value: $errmsg"
@@ -568,14 +542,13 @@
     }
 
     return $utc_time
-
 }
 
 ad_proc -public lc_list_all_timezones { } {
     @return list of pairs containing all  timezone names and offsets.
     Data drawn from acs-reference package timezones table
 } {
-    return [db_list_of_lists all_timezones {select unique tz, gmt_offset from timezones order by tz}]
+    return [db_list_of_lists all_timezones {}]
 }
 
 
@@ -631,4 +604,3 @@
 } {
     return [format "%0${n_desired_digits}d" $the_integer]
 }
-
Index: openacs-4/packages/acs-lang/tcl/localization-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/localization-procs.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-lang/tcl/localization-procs.xql	2 May 2001 20:15:34 -0000	1.1
+++ openacs-4/packages/acs-lang/tcl/localization-procs.xql	7 Oct 2002 14:32:46 -0000	1.2
@@ -1,23 +1,25 @@
 <?xml version="1.0"?>
 <queryset>
 
-<fullquery name="lc_monetary_currency.lc_currency_select">      
+   <fullquery name="lc_monetary_currency.lc_currency_select">      
       <querytext>
       
-	SELECT fractional_digits
-               ,html_entity 
-          FROM currency_codes 
-         WHERE iso = :currency
+	select fractional_digits,
+               html_entity 
+        from   currency_codes 
+        where  iso = :currency
     
       </querytext>
-</fullquery>
+   </fullquery>
 
  
-<fullquery name="lc_list_all_timezones.all_timezones">      
+   <fullquery name="lc_list_all_timezones.all_timezones">      
       <querytext>
-      select unique tz, gmt_offset from timezones order by tz
+
+        select unique tz, gmt_offset from timezones order by tz
+
       </querytext>
-</fullquery>
+   </fullquery>
 
  
 </queryset>
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/catalog-test.adp'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/catalog-test.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/www/change-locale-include.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/change-locale-include.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/change-locale-include.adp	7 Oct 2002 14:32:47 -0000	1.1
@@ -0,0 +1,20 @@
+Locale for this request: <%= [ad_conn locale] %><br />
+
+<table width="100%">
+<tr>
+<td>
+<formtemplate id="locale_form"></formtemplate>
+</td>
+
+<!-- Cannot use this stuff as not all message keys have been looked up at this point
+<if @message_debug_html@ not nil>
+<td>
+Using message Keys:
+<p>
+@message_debug_html@
+</p>
+</td>
+</if>
+-->
+</tr>
+</table>
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/change-locale-include.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/change-locale-include.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/change-locale-include.tcl	7 Oct 2002 14:32:47 -0000	1.1
@@ -0,0 +1,56 @@
+# Tracer Bullet:
+# We use this include to change the site wide locale as well as the preferred locale for
+# a user
+# @author Peter Marklund (peter@collaboraid.biz)
+
+set user_id [ad_conn user_id]
+
+form create locale_form -action "/acs-lang/change-locale"
+
+set locale_option_list [list]
+db_foreach locale_loop { select locale, label from ad_locales } {
+    lappend locale_option_list [list $label $locale]
+}
+
+set user_locale [lang::user::locale]
+
+set site_wide_locale [lang::system::locale]
+
+element create locale_form return_url \
+        -datatype text \
+        -widget hidden \
+        -value "[ad_conn url]?[ad_conn query]"
+
+element create locale_form site_wide_locale \
+        -datatype text \
+        -widget select \
+        -label "Site Wide Locale" \
+        -options $locale_option_list \
+        -value $site_wide_locale
+
+if { $user_id != "0" } {
+    element create locale_form user_locale \
+        -datatype text \
+        -widget select \
+        -label "User Locale Preference" \
+        -options $locale_option_list \
+        -value $user_locale
+} else {
+    element create locale_form user_preference_inform \
+            -datatype text \
+            -widget inform \
+            -label  "User Locale Preference" \
+            -value "Please log in to specify a user preference"
+}
+
+#global message_debug_map
+
+set message_debug_html ""
+#if { [info exists message_debug_map] } {
+
+#    set message_debug_html "<ul>"
+#    foreach item $message_debug_map {
+#        append message_debug_html "<li>[lindex $item 0] - [lindex $item 1]</li>"
+#    }
+#    append message_debug_html "</ul>"
+#}
Index: openacs-4/packages/acs-lang/www/change-locale.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/change-locale.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/change-locale.tcl	7 Oct 2002 14:32:47 -0000	1.1
@@ -0,0 +1,12 @@
+ad_page_contract {
+
+} {
+    {user_locale ""}
+    site_wide_locale
+    return_url
+}
+
+lang::user::set_locale $user_locale
+lang::system::set_locale $site_wide_locale
+
+ad_returnredirect $return_url
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/compile.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/format-test-oracle.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/format-test-postgresql.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/format-test.adp'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/format-test.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/index.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/index.adp	7 Oct 2002 14:32:47 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+  <property name="title">@instance_name@</property>
+  <property name="context_bar">@context_bar@</property>
+
+<include src="/packages/acs-lang/www/change-locale-include">
+  
\ No newline at end of file
Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/index.html'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/index.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/index.tcl	7 Oct 2002 14:32:47 -0000	1.1
@@ -0,0 +1,13 @@
+ad_page_contract {
+    Localization home
+}
+
+set instance_name [ad_conn instance_name]
+set context_bar [ad_context_bar]
+
+#
+# Get user pref setting
+#
+
+set locale [ad_locale user locale]
+set language [ad_locale user language]
Index: openacs-4/packages/acs-lang/www/locale-set.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/Attic/locale-set.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-lang/www/locale-set.tcl	20 Apr 2001 20:51:08 -0000	1.1
+++ openacs-4/packages/acs-lang/www/locale-set.tcl	7 Oct 2002 14:32:47 -0000	1.2
@@ -8,15 +8,11 @@
     @cvs-id $Id$
 } {
     locale
-    { redirect_url {} }
+    {redirect_url {[ns_set iget [ns_conn headers] referer]}}
 }
 
 # set the locale property
 ad_locale_set locale $locale
 
-if [empty_string_p $redirect_url] {
-    set redirect_url  [ns_set iget [ns_conn headers] referer]
-}
-
 ad_returnredirect $redirect_url
 
Index: openacs-4/packages/acs-lang/www/set-system-timezone.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/Attic/set-system-timezone.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/acs-lang/www/set-system-timezone.tcl	29 Aug 2001 21:22:49 -0000	1.2
+++ openacs-4/packages/acs-lang/www/set-system-timezone.tcl	7 Oct 2002 14:32:47 -0000	1.3
@@ -19,10 +19,8 @@
 <hr>
 
 
-OpenACS currently believes that the 
-[string totitle [nsv_get ad_database_type .]] database 
-is running in the timezone
-<b>[ad_locale_get_system_timezone]</b>
+ACS currently believes that Oracle is running in the
+timezone <b>[ad_locale_get_system_timezone]</b>
 <p>
 
 If this is correct, then the offset between the time returned by
@@ -52,9 +50,8 @@
 append page "
 <hr>
 
-You can use the form below to tell OpenACS what timezone the 
-[string totitle [nsv_get ad_database_type .]] database is operating in.
-(There does not appear to be a nice way to ask the database this question automatically).
+You can use the form below to tell ACS what timezone Oracle is operating in.
+(There does not appear to be a nice way to ask Oracle this question automatically).
 <p>
 
 <form action=set-system-timezone method=get>
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/show-catalog.adp'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/show-catalog.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/show.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/test-oracle.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/test-postgresql.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/test.adp'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/test.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/timezone-oracle.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/timezone-postgresql.xql'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/timezone.adp'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/timezone.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-lang/www/tz-test.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/acs-lang/www/admin/display-grouped-messages.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/display-grouped-messages.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/display-grouped-messages.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,112 @@
+<master src="master" />
+ <property name="title">Messages Administration</property>
+
+<h2>Localized Messages</h2>
+
+@context_bar@
+
+<hr />
+
+<div>
+
+<p>Your locale is <strong>@locale_label@</strong> [ <tt>@locale_user@</tt> ]</p>
+
+<if @missing_translation_group:rowcount@ eq 0>
+
+  <p>Note from the system: <strong>NO</strong> messages need to be translated. <emphasis>Job well done</emphasis> <tt>:-)</tt></p>
+
+</if>
+
+<table cellpadding="2" cellspacing="4" border="0" width="100%">
+ <tr>
+  <td valign="top">
+
+   <!-- Left Side -->
+
+   <table cellpadding="0" cellspacing="0" border="0" width="100%">
+    <tr>
+     <td style="background: #CCCCCC">
+      <table cellpadding="2" cellspacing="1" border="0" width="100%">
+       <tr valign="middle" style="background: #CCCCFF">
+        <th colspan="2">Need Translation</th>
+       </tr>
+       <tr style="background: #FFFFFF">
+        <td align="left">
+         <table cellpadding="0" cellspacing="0" border="0">
+          <tr>
+           <td style="background: #CCCCCC">
+            <table cellpadding="4" cellspacing="1" border="0">
+             <tr valign="middle" style="background: #FFFFE4">
+              <th>Grouping (category)</th>
+              <th>Action</th>
+             </tr>
+             <multiple name="missing_translation_group">
+             <tr style="background: #EEEEEE">
+              <td>@missing_translation_group.grouper_key@</td>
+              <td>
+               (<span class="edit-anchor"><a href="display-localized-messages?grouper_key=@missing_translation_group.grouper_key_encoded@&amp;locales=@missing_translation_group.locale_encoded@&translated_p=0">edit</a></span>)
+               <if @new_allowed_p@ eq 1>
+                (<span class="edit-anchor"><a href="localized-message-new?grouper_key=@missing_translation_group.grouper_key_encoded@&amp;locales=@missing_translation_group.locale_encoded@">new</a></span>)
+               </if>
+              </td>
+             </tr>
+             </multiple>
+            </table>
+           </td>
+          </tr>
+         </table>
+        </td>
+       </tr>
+      </table>
+     </td>
+    </tr>
+   </table>
+  </td>
+  <td align="center" valign="top">
+   <!-- Right Side -->
+   <table cellpadding="0" cellspacing="0" border="0" width="100%">
+    <tr>
+     <td style="background: #CCCCCC">
+      <table cellpadding="2" cellspacing="1" border="0" width="100%">
+       <tr style="background: #CCCCFF">
+        <th colspan="2">
+         Already translated
+        </th>
+       </tr>
+       <tr style="background: #FFFFFF">
+        <td align="left">
+         <table cellpadding="0" cellspacing="0" border="0">
+          <tr>
+           <td style="background: #CCCCCC">
+            <table cellpadding="4" cellspacing="1" border="0">
+             <tr valign="middle" style="background: #FFFFE4">
+              <th>Grouping (category)</th>
+              <th>Action</th>
+             </tr>
+             <multiple name="translated_messages_group">
+             <tr style="background: #EEEEEE">
+              <td>@translated_messages_group.grouper_key@</td>
+              <td>
+               (<span class="edit-anchor"><a href="display-localized-messages?grouper_key=@translated_messages_group.grouper_key_encoded@&amp;locales=@translated_messages_group.locale_encoded@&translated_p=1">edit</a></span>)
+               <if @new_allowed_p@ eq 1>
+                (<span class="edit-anchor"><a href="localized-message-new?grouper_key=@translated_messages_group.grouper_key_encoded@&amp;locales=@translated_messages_group.locale_encoded@">new</a></span>)
+               </if>
+              </td>
+             </tr>
+             </multiple>
+            </table>
+           </td>
+          </tr>
+         </table>
+        </td>
+       </tr>
+      </table>
+     </td>
+    </tr>
+   </table>
+  </td>
+ </tr>
+</table>
+
+</div>
+
Index: openacs-4/packages/acs-lang/www/admin/display-grouped-messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/display-grouped-messages.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/display-grouped-messages.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,103 @@
+# /packages/gp-lang/www/gpadmin/display-grouped-messages.tcl
+ad_page_contract {
+
+    Displays the categories of messages (grouped by the key string that
+    goes before the first "." in it).
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 26 October 2001
+    @cvs-id $Id: display-grouped-messages.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    locales:optional
+} -properties {
+}
+
+set return_url "index?tab=[ns_urlencode localized-messages]"
+set context_bar [ad_context_bar [list $return_url "Locales & Messages"] "Listing"]
+set default_locale [ad_parameter DefaultLocale]
+set default_locale en_US
+
+# We look for all the languages of the current NRO
+
+request create -params {
+    locale -datatype text -optional 
+}
+
+if { [info exists locales] } {
+    set locale_user $locales
+} else {
+    if { [exists_and_not_null locale] } {
+        set locale_user $locales
+     } else {
+         set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+     }
+}
+#  AS - disabling this because it doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+# We query the database for all the messages for the specific locale
+# translated or not but selecting only the first element in the key
+# using the distinct in each reduces the number of rows that we have
+# to process from within TCL. As you might already know from the docs,
+# the format of the key is 'grouper.key' where grouper is some string
+# that can identify a package or a specific set of templates; grouper
+# cannot contain dots.
+
+# Query to get all the messages that DO NOT have a translation to the
+# language selected
+
+set grouper_msg_not_translated "
+select 
+  distinct(substr(key, 1, instr(key, '.')-1)) as grouper_key
+from 
+  lang_messages lm1 
+where 
+  lm1.locale = :default_locale and 
+  not exists (
+    select 1 
+    from lang_messages lm2 
+    where lm2.locale = :locale_user and 
+    lm1.key = lm2.key
+  )"
+
+# Query that get all the messages that HAVE a translation to
+# the language selected
+set grouper_msg_translated "
+select
+  distinct(substr(lm1.key, 1, instr(lm1.key, '.')-1)) as grouper_key
+from
+  lang_messages lm1,
+  lang_messages lm2
+where
+  lm1.locale = :default_locale and
+  lm2.locale = :locale_user and
+  lm1.key = lm2.key"
+
+template::multirow create missing_translation_group grouper_key grouper_key_encoded locale_encoded
+template::multirow create translated_messages_group grouper_key grouper_key_encoded locale_encoded
+
+db_foreach select_messages_not_translated $grouper_msg_not_translated {
+    template::multirow append missing_translation_group $grouper_key [ns_urlencode $grouper_key] [ns_urlencode $locale_user]
+}
+
+db_foreach select_messages_translated $grouper_msg_translated {
+    template::multirow append translated_messages_group $grouper_key [ns_urlencode $grouper_key] [ns_urlencode $locale_user]
+}
+
+db_1row select_locale_lable {
+    select label as locale_label from ad_locales where locale = :locale_user }
+
+if { $locale_user == $default_locale } {
+
+    # This is the default locale, then allow the 'new' action
+    set new_allowed_p 1
+
+} else {
+
+    set new_allowed_p 0
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/display-localized-messages.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/display-localized-messages.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/display-localized-messages.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,81 @@
+<master src="master" />
+<property name="title">Messages Administration</property>
+
+<h2>Localized Messages</h2>
+@context_bar@
+
+<hr />
+
+<div>
+
+<p>You are editing locale: <strong>@locale_label@</strong> [ <tt>@locale_user@</tt> ]</p>
+
+<if @missing_translation:rowcount@ eq 0>
+
+</if>
+
+<else>
+
+<p>Messages that <strong>need</strong> translation.</p>
+
+<table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+  <td style="background: #CCCCCC">
+   <table cellpadding="4" cellspacing="1" border="0">
+    <tr style="background: #FFFFe4">
+     <th>Key</th>
+     <th>Original Message</th>
+     <th>Translated Message</th>
+     <th>Action</th>
+    </tr>
+    <multiple name="missing_translation">
+    <tr style="background: #EEEEEE">
+     <td>@missing_translation.key@</td>
+     <td>@missing_translation.message@</td>
+     <td>Translation Missing</td>
+     <td>
+      (<span class="edit-anchor"><a href="edit-localized-message?key=@missing_translation.escaped_key@&locales=@missing_translation.escaped_language@&translated_p=0">edit</a></span>)
+     </td>
+    </tr>
+    </multiple>
+   </table>
+  </td>
+ </tr>
+</table>
+
+</else>
+
+<if @translated_messages:rowcount@ eq 0>
+
+</if>
+
+<else>
+
+<p>Messages that <strong>are</strong> translated.</p>
+
+<table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+  <td style="background: #CCCCCC">
+   <table cellpadding="4" cellspacing="1" border="0">
+    <tr style="background: #FFFFe4">
+     <th>Key</th>
+     <th>Original Message</th>
+     <th>Translated Message</th>
+     <th>Action</th>
+    </tr>
+    <multiple name="translated_messages">
+    <tr style="background: #EEEEEE">
+     <td>@translated_messages.key@</td>
+     <td>@translated_messages.default_message@</td>
+     <td>@translated_messages.translated_message@</td>
+     <td>(<span class="edit-anchor"><a href="edit-localized-message?key=@translated_messages.escaped_key@&locales=@translated_messages.escaped_language@&translated_p=1">edit</a></span>)</td>
+    </tr>
+    </multiple>
+   </table>
+  </td>
+ </tr>
+</table>
+
+</else>
+
+</div>
Index: openacs-4/packages/acs-lang/www/admin/display-localized-messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/display-localized-messages.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/display-localized-messages.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,91 @@
+ad_page_contract {
+
+    Displays the localized messages from the database for translation
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 26 October 2001
+    @cvs-id $Id: display-localized-messages.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    locales
+    translated_p
+} -properties {
+}
+
+set tab [ns_urlencode "localized-messages"]
+set return_url "display-grouped-messages?tab=$tab&locales=$locales"
+set context_bar [ad_context_bar [list "index?tab=$tab" "Locales & Messages"] [list $return_url Listing] "Messages"]
+set default_locale [ad_parameter DefaultLocale]
+set default_locale en_US
+
+# Christian: this should be in ad_page_contract - right?
+
+request create -params {
+    locales -datatype text 
+    grouper_key -datatype text 
+}
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+#  AS - disabling, doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set escaped_locale [ns_urlencode $locale_user]
+
+# Query to get all the messages that DO NOT have a translation to the
+# language selected
+set cat_msg_not_translated "
+select 
+  key, 
+  message 
+from 
+  lang_messages lm1 
+where 
+  lm1.locale = :default_locale and
+  substr(lm1.key, 1, instr(lm1.key, '.') - 1) = :grouper_key and
+  not exists (
+    select 1 
+    from lang_messages lm2 
+    where lm2.locale = :locale_user and 
+    lm1.key = lm2.key
+  )"
+
+# Query that get all the messages that HAVE a translation to
+# the language selected
+# 
+set cat_msg_translated "
+select
+  lm1.key as key,
+  lm1.message as default_message,
+  lm2.message as translated_message
+from
+  lang_messages lm1,
+  lang_messages lm2
+where
+  lm1.locale = :default_locale and
+  substr(lm1.key, 1, instr(lm1.key, '.') - 1) = :grouper_key and
+  lm2.locale = :locale_user and
+  lm1.key = lm2.key"
+
+template::multirow create missing_translation key locale message escaped_key escaped_language
+
+template::multirow create translated_messages key locale default_message translated_message escaped_key escaped_language
+
+if { ! $translated_p } {
+    db_foreach select_messages_not_translated $cat_msg_not_translated {
+        template::multirow append missing_translation $key $locale_user $message [ns_urlencode $key] [ns_urlencode $locale_user]
+    }
+} else {
+    db_foreach select_messages_translated $cat_msg_translated {
+        template::multirow append translated_messages $key $locale_user $default_message $translated_message [ns_urlencode $key] [ns_urlencode $locale_user]
+    }
+}
+
+db_1row select_locale_lable {
+    select label as locale_label from ad_locales where locale = :locale_user }
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/edit-localized-message-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/edit-localized-message-2.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/edit-localized-message-2.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,134 @@
+# /packages/gp-lang/www/gpadmin/edit-localized-message-2.tcl
+ad_page_contract {
+
+    When editing a localized message, if the user chooses to upload a new
+    image to replace the current one, this is the script that handles the
+    upload.
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 27 May 2002
+    @cvs-id $Id: edit-localized-message-2.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+
+} {
+    upload_file:trim
+    return_url
+    key
+    locales
+} -properties {
+}
+
+# check the permission
+set package_id [ad_conn package_id]
+set permission_p [ad_permission_p $package_id nro_admin]
+
+if { !$permission_p } {
+    ad_returnredirect "/gp-admin"
+}
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+# TODO: make the error processing better ... I don't really like these 
+# ad_return_warning errors. BEM
+
+if { ![info exists upload_file] || [empty_string_p $upload_file] } {
+
+    # Oops. There is no file beeing uploaded.
+    ad_return_warning "error" "You should select a file to upload..."
+    ad_script_abort
+
+} else {
+
+    set tmp_filename [ns_queryget upload_file.tmpfile]
+    set file_extension [string tolower [file extension $upload_file]]
+    # remove the first "." from the file extension
+    regsub "\." $file_extension "" file_extension
+
+    # TODO: Support more graphic file formats. For the time being
+    # we only work with jpg, gif or png
+    if { ![regexp {^(jpeg|jpg|gif|png)$} $file_extension] } {
+        append error_message "The only file formats supported are JPG, GIF or PNG.
+        <br />Use the BACK button to submit another file"
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+    }
+
+    set guessed_file_type [ns_guesstype $upload_file]
+    set n_bytes [file size $tmp_filename]
+
+    # TODO: Make some parameter for the maximum size (in bytes) for these
+    # images. For the time being, we use a hardwired 100k
+    if { $n_bytes > ( 100 * 1024 ) } {
+
+        # The size is too big!
+        set error_message "The size of the image you are uploading is too big.
+            The maximum size allowed is 100KB."
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+
+    }
+
+    # strip off the C:\directories... crud and just get the file name
+    if ![regexp {([^/\\]+)$} $upload_file match client_filename] {
+        # couldn't find a match
+        set client_filename $upload_file
+    }
+
+    # We keep the following few lines just in case we need to do some
+    # size checks in the future.
+
+    set what_aolserver_told_us ""
+    if { $file_extension == "jpeg" || $file_extension == "jpg" } {
+        catch { set what_aolserver_told_us [ns_jpegsize $tmp_filename] }
+    } elseif { $file_extension == "gif" } {
+        catch { set what_aolserver_told_us [ns_gifsize $tmp_filename] }
+    }
+
+    # the AOLserver jpegsize command has some bugs where the height comes
+    # through as 1 or 2
+
+    if { ![empty_string_p $what_aolserver_told_us] && [lindex $what_aolserver_told_us 0] > 10 && \
+        [lindex $what_aolserver_told_us 1] > 10 } {
+
+        set original_width [lindex $what_aolserver_told_us 0]
+        set original_height [lindex $what_aolserver_told_us 1]
+
+    } else {
+
+        set original_width ""
+        set original_height ""
+
+    }
+
+    # The name of the file is the message created by the user
+    set localized_message [_ $locale_user $key]
+    set message_file_extension [file extension $localized_message]
+    regsub "\." $message_file_extension "" message_file_extension
+    if { $file_extension != $message_file_extension } {
+        set error_message "You have to upload a file with the <strong>same extension</strong>
+            as the one you stated in the message."
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+    }
+     
+
+    set apm_package_id [util_memoize {get_acs_object_id apm_service} 900]
+    set ImageFolderPath [ad_parameter -package_id $apm_package_id ImageFolderPath]
+
+    set destination_path "${ImageFolderPath}/${localized_message}"
+
+    # Copy the file uploaded to its location in the filesystem
+    # If there was another version of the file there, overwrite it without
+    # any notice.
+    file copy -force -- $tmp_filename $destination_path
+
+}
+
+db_release_unused_handles
+
+# If we get here it's because everything went fine... Do we really believe that? ;)
+
+ns_returnredirect $return_url
Index: openacs-4/packages/acs-lang/www/admin/edit-localized-message.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/edit-localized-message.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/edit-localized-message.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,26 @@
+<master src="master">
+ <property name="title">Edit a message</property>
+ <property name="header_stuff">@header_stuff@</property>
+
+<h2>Edit Localized Messages</h2>
+@context_bar@
+
+<hr />
+
+<div>
+
+<if @locale_label@ nil>
+
+  <p class="error">Please, submit a valid locale.</p>
+
+</if>
+<else>
+
+  <p>Locale: <strong>@locale_label@</strong> [ <tt>@locale_user@</tt> ]</p>
+  <p>Key: <span style="background: #CCFFCC"><strong>@key@</strong></span></p>
+
+<formtemplate id="message_editing"></formtemplate>
+
+</else>
+
+</div>
Index: openacs-4/packages/acs-lang/www/admin/edit-localized-message.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/edit-localized-message.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/edit-localized-message.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,146 @@
+ad_page_contract {
+
+    Displays the localized message from the database for translation (displays
+    an individual message)
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 30 October 2001
+    @cvs-id $Id: edit-localized-message.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+
+} {
+    locales
+    {translated_p}
+    key
+} -properties {
+}
+
+request create
+request set_param key -datatype keyword -optional
+request set_param locales -datatype keyword -optional
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set return_url "display-localized-messages?grouper_key="
+
+# we get the grouper (the first string before the first '.' in the key)
+set grouper_key [string range $key 0 [expr ([string first "." $key] - 1)]]
+
+append return_url [ns_urlencode $grouper_key]
+append return_url "&locales=[ns_urlencode $locales]&translated_p=$translated_p"
+
+set tab [ns_urlencode "localized-messages"]
+
+set context_bar [ad_context_bar [list "index?tab=$tab" "Locales & Messages"] \
+    [list "display-grouped-messages?tab=$tab&locales=$locales" "Listing"] \
+    [list $return_url "Messages"] "Edit"]
+
+
+# This has an ugly smell: But let's hardcode the default to en_US
+
+set default_locale en_US
+
+# The part that deals with images is removed - so all messages are treated
+# as simple text.
+
+template::form create message_editing
+
+template::element create message_editing original_message \
+    -label "Original Message" -datatype text -widget inform
+
+template::element create message_editing message -label "Message" \
+    -datatype text -widget textarea -html { rows 6 cols 40 }
+
+# The two hidden tags that we need to pass on the key and language to the
+# processing of the form
+
+template::element create message_editing key -label "key" -datatype text -widget hidden
+
+template::element create message_editing locales -label "locale" -datatype text -widget hidden
+
+template::element create message_editing translated_p -label "translated_p" -datatype text -widget hidden -value $translated_p
+
+ set locale_label [ad_locale_get_label $locale_user]
+
+# Header Stuff ... We make sure that this page doesn't get cached.
+set header_stuff "<meta http-equiv=\"Pragma\" content=\"no-cache\" />" 
+
+if { [template::form is_request message_editing] } {
+
+    set sql_select_original_message "
+        select message
+        from lang_messages
+        where key = :key and locale = :default_locale "
+
+    set sql_select_translated_message "
+        select message as translated_message
+        from lang_messages
+        where key = :key and locale = :locale_user"
+
+    # Let's get the original message (in english)
+    db_1row select_original_message $sql_select_original_message
+
+    # let's get the translated message (we use 0or1row since the message
+    # might not exists
+    db_0or1row select_translated_message $sql_select_translated_message
+
+    if { [exists_and_not_null translated_message] } {
+
+        template::element set_properties message_editing message -value $translated_message
+
+    } else {
+
+        template::element set_properties message_editing message -value "No Translation Available"
+
+    }
+   
+    template::element set_properties message_editing key -value $key
+    template::element set_properties message_editing locales -value $locale_user
+    template::element set_properties message_editing original_message -value $message
+
+} else {
+
+    # We are not processing a request, therefor it's a submission. Get the values
+    # from the form and validate them
+
+    template::form get_values message_editing
+    if { $message == "" } {
+
+        template::element set_error message_editing message "Message is required"
+        set sql_select_original_message "
+            select message
+            from lang_messages
+            where key = :key and locale = :default_locale "
+        db_1row select_original_message $sql_select_original_message
+
+        template::element set_properties message_editing original_message -value $message
+
+    }
+
+}
+
+if { [template::form is_valid message_editing] } {
+
+    # We get the values from the form
+    template::form get_values message_editing key
+    template::form get_values message_editing locales
+    template::form get_values message_editing message
+
+    # We use the gp-lang registration of a translation. Simple, eh?
+    _mr $locales $key $message
+
+    # Even if the country code is 2 chars, we avoid problems...
+    set escaped_locale [ns_urlencode $locales]
+
+    template::forward $return_url
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/index.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/index.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,40 @@
+<master src="master">
+  <property name="title">Administration of Localized Messages</property>
+
+<h2>@instance_name@</h2>
+
+@context_bar@
+
+<hr />
+
+<div>
+
+<include src="locales-tabs" tab="@tab@" show_locales_p="@show_locales_p@">
+
+<if @tab@ eq "home">
+
+ <!-- Start home tab -->
+ <p>Maybe we should display something useful for the user here ... </p>
+ <!-- End home tab -->
+
+</if>
+
+<if @tab@ eq "locales">
+
+ <!-- Start locales tab -->
+ <include src="locales" tab="@tab@">
+ <!-- End locales tab -->
+
+</if>
+
+<if @tab@ eq "localized-messages">
+
+ <!-- Start localized-messages tab -->
+ <include src="localized-messages" tab="@tab@">
+ <!-- End localized-messages tab -->
+
+</if>
+
+</div>
+
+<a href="load-catalog-files">Load all Catalog Files</a>. This will overwrite any values in the database (the catalog files take precedence).
Index: openacs-4/packages/acs-lang/www/admin/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/index.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/index.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,24 @@
+# /packages/gp-lang/www/gpadmin/index.tcl
+
+ad_page_contract {
+
+    Administration of the localized messages
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 19 October 2001
+    @cvs-id $Id: index.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    {tab "locales"}
+}
+
+set locale_user [ad_locale user locale]
+set instance_name [ad_conn instance_name]
+set context_bar [ad_context_bar [ad_conn instance_name]]
+
+if { [ad_permission_p 0 admin] } {
+    set show_locales_p "t"
+} else {
+    set show_locales_p "f"
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/load-catalog-files.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/load-catalog-files.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/load-catalog-files.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,11 @@
+ad_page_contract {
+    Load all catalog files.
+
+    @author Peter Marklund (peter@collaboraid.biz)
+    @creation-date 2002-10-07
+    @cvs-id $Id: load-catalog-files.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+}
+
+lang::catalog::load_all
+
+ad_returnredirect "index"
Index: openacs-4/packages/acs-lang/www/admin/locale-delete-confirm.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/locale-delete-confirm.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-delete-confirm.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,13 @@
+<master src="master">
+<property name="title">Administration of Localized Messages</property>
+
+<h2>Delete locale</h2>
+@context_bar@
+<hr />
+
+<p style="color: red; font-weight: bold">Are you sure you want to proceed?</p>
+<p />
+<form action="locale-delete" method="post">
+@confirm_data@
+<input type="submit" value="Delete..." />
+</form>
Index: openacs-4/packages/acs-lang/www/admin/locale-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-delete.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-delete.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,11 @@
+<master src="master">
+<property name="title">Administration of Localized Messages</property>
+
+<h2>Delete locale</h2>
+@context_bar@
+<hr />
+
+<p />
+<p>Deleting locale <strong>@locale_label@</strong> [ <tt>@locales@</tt> ]</p>
+<formtemplate id="locale_deleting"></formtemplate>
+
Index: openacs-4/packages/acs-lang/www/admin/locale-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-delete.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-delete.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,100 @@
+# /packages/gp-lang/www/gpadmin/locale-delete.tcl
+
+ad_page_contract {
+
+    Deletes a locale
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 19 march 2002
+    @cvs-id $Id: locale-delete.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    locales
+} -properties {
+}
+
+# Get the locale for the user so that we 'spit' the content back in the
+# proper locale
+set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set context_bar [ad_context_bar "Deleting Locales"]
+
+form create locale_deleting
+
+# It's a request, not a submission of the form
+
+element create locale_deleting country -label "Country (2 digit ISO-code)" \
+        -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_deleting language -label "Language (2 digit ISO-code)" \
+        -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_deleting label -label "Label" -datatype text
+
+element create locale_deleting nls_language -label "NLS Language" \
+    -datatype text -widget text
+
+element create locale_deleting nls_territory -label "NLS Territory" \
+    -datatype text -widget text
+
+element create locale_deleting nls_charset -label "NLS Charset" \
+    -datatype text -widget text
+
+element create locale_deleting mime_charset \
+    -label "MIME Charset" -datatype text
+
+element create locale_deleting default_p -label "Default" \
+    -datatype text -widget hidden  
+
+element create locale_deleting locales -p label "Locales" \
+    -datatype text -widget hidden -value $locales
+
+if { [form is_request locale_deleting] } {
+
+    # Finish building the form to present to the user
+    db_1row select_details_locale "select locale as locale_locale,
+            language as locale_language, country as locale_country,
+            label as locale_label, nls_language as locale_nls_language,
+            nls_territory as locale_nls_territory, nls_charset as locale_nls_charset,
+            mime_charset as locale_mime_charset, default_p as locale_default_p
+        from ad_locales
+        where locale = :locales"
+    element set_properties locale_deleting label -value $locale_label
+    element set_properties locale_deleting language -value $locale_language
+    element set_properties locale_deleting country -value $locale_country
+    element set_properties locale_deleting nls_language -value $locale_nls_language
+    element set_properties locale_deleting nls_territory -value $locale_nls_territory
+    element set_properties locale_deleting nls_charset -value $locale_nls_charset
+    element set_properties locale_deleting mime_charset -value $locale_mime_charset
+    element set_properties locale_deleting default_p -value $locale_default_p
+
+}
+
+if { [ns_queryexists form:confirm] } {
+
+    db_transaction {
+
+        db_dml delete_locale "delete from ad_locales where locale = :locales"
+
+    }
+
+    forward "index?tab=locales"
+
+}
+
+if { [form is_valid locale_deleting] } {
+
+    # We are receiving a valid submission
+    set confirm_data [form export]
+
+    append confirm_data "<input type=\"hidden\" name=\"form:confirm\" value=\"confirm\" />"
+
+    set_file "[file dir $__adp_stub]/locale-delete-confirm"
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/locale-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-edit.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-edit.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,12 @@
+<master src="master">
+<property name="title">Administration of Localized Messages</property>
+
+<h2>Edit locale</h2>
+@context_bar@
+<hr />
+
+<p>Please update the necesary fields and press &quot;Submit&quot;</p>
+<p />
+<p>Editing locale <strong>@locale_label@</strong> [ <tt>@locales@</tt> ]</p>
+<formtemplate id="locale_editing"></formtemplate>
+
Index: openacs-4/packages/acs-lang/www/admin/locale-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-edit.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-edit.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,160 @@
+ad_page_contract {
+
+    Edits a locale
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+
+    Modified by Christian Hvid
+
+    @creation-date 19 march 2002
+    @cvs-id $Id: locale-edit.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    locales
+} -properties {
+}
+
+# Get the locale for the user so that we 'spit' the content back in the
+# proper locale
+
+set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set context_bar [ad_context_bar [list "index?tab=locales" "Locales"] "Editing Locale"]
+
+form create locale_editing
+
+# It's a request, not a submission of the form
+
+#
+# LARS:
+# Hm.. this is Oracle-specific. Need to figure out what to do with this for PostgreSQL.
+#
+
+# The v$nls_valid_values view contains all the valid NLS values
+# for the oracle instance. It is up to the user to select the correct
+# values (combinations of language, territories and character sets. More
+# information on this view can be found in the docs at http://tahiti.oracle.com/
+# look for the PDF file of Oracle 8i "national language support guide"
+
+catch {
+    set nls_values_list [db_list_of_lists select_nls_values {select parameter, value 
+    from v$nls_valid_values order by parameter, value}]
+
+    foreach nls_value $nls_values_list {
+        set value [lindex $nls_value 1]
+        switch [lindex $nls_value 0] {
+            LANGUAGE {
+                lappend list_nls_language "\"$value\" \"$value\""
+            }
+            TERRITORY {
+                lappend list_nls_territory "\"$value\" \"$value\""
+            }
+            CHARACTERSET {
+                lappend list_nls_charset "\"$value\" \"$value\""
+            }
+        }
+    }
+}
+
+
+# Greenpeace had a table of contries and languages and their two-digit ISO-code
+# but not so in ACS-LANG - here you must provide the two-digit ISO-code
+
+element create locale_editing country -label "Country (2 digit ISO-code)" \
+        -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_editing language -label "Language (2 digit ISO-code)" \
+        -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_editing label -label "Label" -datatype text
+
+if { [info exists list_nls_language] } {
+    element create locale_editing nls_language -label "NLS Language" \
+            -datatype text -widget select -options $list_nls_language
+
+    element create locale_editing nls_territory -label "NLS Territory" \
+            -datatype text -widget select -options $list_nls_territory
+    
+    element create locale_editing nls_charset -label "NLS Charset" \
+            -datatype text -widget select -options $list_nls_charset
+} else {
+    element create locale_editing nls_language -label "NLS Language" \
+            -datatype text -widget text
+
+    element create locale_editing nls_territory -label "NLS Territory" \
+            -datatype text -widget text
+    
+    element create locale_editing nls_charset -label "NLS Charset" \
+            -datatype text -widget text
+}
+
+element create locale_editing mime_charset \
+    -label "MIME Charset" -datatype text
+
+element create locale_editing default_p -label "Default" \
+    -datatype text -widget hidden  
+
+element create locale_editing locales -p label "Locales" \
+    -datatype text -widget hidden -value $locales
+
+if { [form is_request locale_editing] } {
+
+    # Finish building the form to present to the user
+    db_1row select_details_locale "select locale as locale_locale,
+            language as locale_language, country as locale_country,
+            label as locale_label, nls_language as locale_nls_language,
+            nls_territory as locale_nls_territory, nls_charset as locale_nls_charset,
+            mime_charset as locale_mime_charset, default_p as locale_default_p
+        from ad_locales
+        where locale = :locales"
+    element set_properties locale_editing label -value $locale_label
+    element set_properties locale_editing language -value $locale_language
+    element set_properties locale_editing country -value $locale_country
+    element set_properties locale_editing nls_language -value $locale_nls_language
+    element set_properties locale_editing nls_territory -value $locale_nls_territory
+    element set_properties locale_editing nls_charset -value $locale_nls_charset
+    element set_properties locale_editing mime_charset -value $locale_mime_charset
+    element set_properties locale_editing default_p -value $locale_default_p
+
+} else {
+
+    # If we are not building a request form, we are processing a submission.
+    # Get the values from the form and validate them
+
+    form get_values locale_editing
+
+    set locale_label [ad_locale_get_label $locales]
+
+    if { $label == "" } {
+        element set_error locale_editing label "Label is required"
+    }
+    if { $mime_charset == "" } {
+        element set_error locale_editing mime_charset "Mime charset is required"
+    }
+
+}
+
+if { [form is_valid locale_editing] } {
+
+    # We are receiving a valid submission
+    form get_values locale_editing
+
+    db_transaction {
+
+        db_dml update_locale "update ad_locales set
+            language = :language, country = :country, label = :label,
+            nls_language = :nls_language, nls_territory = :nls_territory,
+            nls_charset = :nls_charset, mime_charset = :mime_charset,
+            default_p = :default_p
+            where locale = :locales"
+
+    }
+    forward "index?tab=locales"
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/locale-make-default.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-make-default.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-make-default.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,33 @@
+# /packages/gp-lang/www/gpadmin/locale-make-default.tcl
+
+ad_page_contract {
+
+    Makes a locale the default for its language
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 19 march 2002
+    @cvs-id $Id: locale-make-default.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+    locales
+} -properties {
+}
+
+# If have first to revert the other locales to default_p = f
+db_transaction {
+
+    set language_from_locale [db_string select_lang_from_locale "select
+        language from ad_locales where locale = :locales"]
+
+    db_dml make_locales_not_default "update ad_locales set default_p = 'f'
+        where language = :language_from_locale and default_p = 't'"
+
+    db_dml make_locales_default "update ad_locales set default_p = 't'
+        where locale = :locales"
+
+    util_memoize_flush [list ad_locale_locale_from_lang $locales]
+
+}
+
+template::forward "index?tab=locales"
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/locale-new.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-new.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-new.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,11 @@
+<master src="master">
+<property name="title">Administration of Localized Messages</property>
+
+<h2>Create new locale</h2>
+@context_bar@
+<hr />
+
+<p>Please, fill in the fields to create a new locale.</p>
+<p />
+<formtemplate id="locale_creation"></formtemplate>
+
Index: openacs-4/packages/acs-lang/www/admin/locale-new.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-new.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locale-new.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,136 @@
+# /packages/gp-lang/www/gpadmin/locale-new.tcl
+
+ad_page_contract {
+
+    Creates a new locale
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 15 march 2002
+    @cvs-id $Id: locale-new.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+} -properties {
+}
+
+# Get the users locale
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set context_bar [ad_context_bar "Creation of Locales"]
+
+form create locale_creation 
+
+# The v$nls_valid_values view contains all the valid NLS values
+# for the oracle instance. It is up to the user to select the correct
+# values (combinations of language, territories and character sets. More
+# information on this view can be found in the docs at http://tahiti.oracle.com/
+# look for the PDF file of Oracle 8i "national language support guide"
+
+catch {
+    set nls_values_list [db_list_of_lists select_nls_values {select parameter, value from v$nls_valid_values order by parameter, value}]
+
+    foreach nls_value $nls_values_list {
+        set value [lindex $nls_value 1]
+        switch [lindex $nls_value 0] {
+            LANGUAGE {
+                lappend list_nls_language "\"$value\" \"$value\""
+            }
+            TERRITORY {
+                lappend list_nls_territory "\"$value\" \"$value\""
+            }
+            CHARACTERSET {
+                lappend list_nls_charset "\"$value\" \"$value\""
+            }
+        }
+    }
+}
+
+element create locale_creation country -label "Country (2 digit ISO-code)" \
+    -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_creation language -label "Language (2 digit ISO-code)" \
+    -datatype text -widget text -html { maxLength 2 size 2 }
+
+element create locale_creation label -label "Label" -datatype text
+
+if { [info exists list_nls_language] } {
+
+    element create locale_creation nls_language -label "NLS Language" \
+            -datatype text -widget select -options $list_nls_language
+    
+    element create locale_creation nls_territory -label "NLS Territory" \
+            -datatype text -widget select -options $list_nls_territory
+    
+    element create locale_creation nls_charset -label "NLS Charset" \
+            -datatype text -widget select -options $list_nls_charset
+
+} else {
+
+    element create locale_creation nls_language -label "NLS Language" \
+            -datatype text -widget text
+    
+    element create locale_creation nls_territory -label "NLS Territory" \
+            -datatype text -widget text
+    
+    element create locale_creation nls_charset -label "NLS Charset" \
+            -datatype text -widget text
+}
+    
+element create locale_creation mime_charset \
+    -label "MIME Charset" -datatype text
+
+if { [form is_request locale_creation] } {
+
+    # Finish building the form to present to the user
+    # Since it's a standard form and no special values need to
+    # set up, we do nothing! :)
+
+} else {
+
+    # If we are not building a request form, we are processing a submission.
+    # Get the values from the form and validate them
+
+    form get_values locale_creation
+
+}
+
+if { [form is_valid locale_creation] } {
+
+    # We are receiving a valid submission
+    form get_values locale_creation
+
+    append locale $language "_" $country
+
+    db_transaction {
+
+        # If there is already a default for this language, then it will remain
+        # the current one. We don't change that.
+        set default_p "f"
+
+        # We first make sure that there is no default for this language
+        set is_default_p [db_string select_default "select count(*) from
+            ad_locales where language = :language and default_p = 't'"]
+        if { $is_default_p == "0" } {
+            # There is a no default for this language
+            set default_p "t"
+        }
+
+        db_dml insert_locale "insert into ad_locales (
+            locale, language, country, variant, label, nls_language,
+            nls_territory, nls_charset, mime_charset, default_p) values (
+            :locale, :language, :country, NULL, :label, :nls_language,
+            :nls_territory, :nls_charset, :mime_charset, :default_p)"
+
+    }
+    forward "index?tab=locales"
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/locales-tabs.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locales-tabs.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locales-tabs.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,26 @@
+<!-- Start Tab bar -->
+<table border="0" cellspacing="0" cellpadding="0">
+  <tr>
+    <td>&nbsp;</td>
+      <multiple name="tabs">
+        <if @tabs.key@ eq @tab@>
+          <td class="tab_selected">&nbsp;@tabs.name@&nbsp;</td>
+        </if>
+        <else>
+          <td>&nbsp;<a href="@tabs.url@">@tabs.name@</a>&nbsp;</td>
+        </else>
+      </multiple>
+    <td width="100%">&nbsp;</td>
+  </tr>
+  <tr style="background: #333366;">
+    <td colspan="<%=[expr {${tabs:rowcount}+2}]%>">
+      <table border=0 cellspacing=0 cellpadding=0>
+        <tr>
+          <td height="5">
+          </td>
+        </tr>
+      </table>
+    </td>
+  </tr>
+</table>
+<!-- End Tab bar -->
Index: openacs-4/packages/acs-lang/www/admin/locales-tabs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/locales-tabs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locales-tabs.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,36 @@
+#
+# Tabs for workflow-page
+#
+# Input:
+#   tab
+#   locales
+#   show_locales_p
+#
+# Data sources:
+#   tabs:multirow name url
+#
+# Author: Lars Pind (lars@pinds.com)
+# Author: Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+# Creation-date: Feb 26, 2001
+# Cvs-id: $Id: locales-tabs.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+#
+
+multirow create tabs name key url 
+
+if { $show_locales_p == "t" } {
+
+    set list_tabs [list { Locales locales } { Messages localized-messages } ]
+
+} else {
+
+    set list_tabs [list { Messages localized-messages } ]
+
+}
+
+foreach loop_tab $list_tabs {
+    multirow append tabs [lindex $loop_tab 0] [lindex $loop_tab 1] ".?[export_vars -url {locales {tab {[lindex $loop_tab 1]}}}]"
+}
+
+#   { Timing timing } 
+#   { Actions actions } 
+
Index: openacs-4/packages/acs-lang/www/admin/locales.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/locales.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locales.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,29 @@
+<p>List of Locales</p>
+<table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+  <td style="background: #CCCCCC">
+   <table cellpadding="4" cellspacing="1" border="0">
+    <tr style="background: #FFFFe4">
+     <th>Locale</th>
+     <th>Label</th>
+     <th>Default</th>
+     <th>Action</th>
+    </tr>
+    <multiple name="locales">
+     <tr style="background: #EEEEEE">
+      <td>@locales.locale@</td>
+      <td>@locales.locale_label@</td>
+      <td>
+       <if @locales.default_p@ eq "t">Yes</if>
+       <else>No (<a href="locale-make-default?locales=@locales.escaped_locale@"><span class="small">make default</span></a>)</else>
+      </td>
+      <td>(<a href="locale-edit?locales=@locales.escaped_locale@">edit</a>)&nbsp;
+          (<a href="locale-delete?locales=@locales.escaped_locale@">delete</a>)
+      </td>
+     </tr>
+    </multiple>
+   </table>
+  </td>
+ </tr>
+</table>
+<p>(<a href="locale-new">New locale</a>)</p>
Index: openacs-4/packages/acs-lang/www/admin/locales.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/locales.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/locales.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,36 @@
+# /packages/gp-lang/www/gpadmin/locales.tcl
+ad_page_contract {
+    Locales administration (creation, edition, deletion)
+
+    @author Bruno Mattarollo (bruno.mattarollo@ams.greenpeace.org)
+    @creation-date March 14, 2002
+    @cvs-id $Id: locales.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} {
+} -properties {
+}
+
+# Check the locale from the user
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+set context_bar [ad_context_bar "Locales Administration"]
+
+db_multirow -extend { escaped_locale } locales select_locales {
+    select l.locale as locale,
+           l.label as locale_label,
+           l.default_p as default_p
+    from ad_locales l
+    order by locale_label
+} {
+    set escaped_locale [ns_urlencode $locale]
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/localized-message-new-2.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/localized-message-new-2.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-message-new-2.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,28 @@
+<master src="master">
+<property name="title">Edit a message</property>
+
+<h2>New Localized Messages - Upload a file</h2>
+
+@context_bar@
+
+<hr />
+
+<div>
+
+<if @locale_label@ nil>
+
+  <p class="error">Please, submit a valid locale.</p>
+
+</if>
+<else>
+
+  <p>Locale: <strong>@locale_label@</strong> [ <tt>@locale_user@</tt> ]</p>
+
+  <formtemplate id="message_file_upload"></formtemplate>
+
+  <p style="font-size: 9pt; color: red;">The message has been modified to make it
+  unique. Don't worry if it's not the same filename you will be uploading.</p>
+
+</else>
+
+</div>
Index: openacs-4/packages/acs-lang/www/admin/localized-message-new-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/localized-message-new-2.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-message-new-2.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,90 @@
+# /packages/gp-lang/www/gpadmin/localized-message-new-2.tcl
+ad_page_contract {
+
+    Displays the form for the user to upload a file that is refered
+    from a localized message
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 15 April 2002
+    @cvs-id $Id: localized-message-new-2.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+
+} {
+    locales
+    key
+} -properties {
+}
+
+# check the permission
+set package_id [ad_conn package_id]
+set permission_p [ad_permission_p $package_id nro_admin]
+
+if { !$permission_p } {
+    ad_returnredirect "/gp-admin"
+}
+
+# We check that this request is coming for the system wide default
+# locale. If not, we can't allow the creation of a new localized 
+# message.
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+set default_locale [ad_parameter DefaultLocale]
+
+if { $locale_user != $default_locale } {
+
+   # ooops!
+   # We should let the user know about this ... shouldn't we? noooooo... :)
+   set encoded_locale [ns_urlencode $locale_user]
+   ad_returnredirect "display-grouped-messages?locales=$encoded_locale"
+
+}
+
+set locale_label [ad_locale_get_label $locale_user]
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+append return_url "display-grouped-messages?locales=" [ns_urlencode $locale_user]
+
+set tab [ns_urlencode "localized-messages"]
+
+set context_bar [ad_context_bar [list "index?tab=$tab" "Locales & Messages"] \
+    [list "display-grouped-messages?tab=$tab&locales=$locales" "Listing"] \
+    "Upload file"]
+
+template::form create message_file_upload -action localized-message-new-3 \
+    -html {enctype multipart/form-data}
+
+template::element create message_file_upload locales -label "Locale" \
+    -datatype text -widget hidden -value $locale_user
+
+template::element create message_file_upload key -label "key" \
+    -datatype text -widget hidden -value $key
+
+template::element create message_file_upload key_display -label "Key" \
+    -datatype text -widget inform
+
+template::element create message_file_upload message_display -label "Message" \
+    -datatype text -widget inform
+
+template::element create message_file_upload upload_file -label "Image file" \
+    -datatype text -widget file
+
+template::element create message_file_upload return_url -label "Return URL" \
+    -datatype text -widget hidden
+
+if { [template::form is_request message_file_upload] } {
+
+    template::element set_properties message_file_upload message_display -value [_ $locale_user $key]
+    template::element set_properties message_file_upload key_display -value $key
+    template::element set_properties message_file_upload return_url -value $return_url
+
+} 
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/localized-message-new-3.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/localized-message-new-3.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-message-new-3.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,134 @@
+# /packages/gp-lang/www/gpadmin/localized-message-new-3.tcl
+ad_page_contract {
+
+    When a new localized message is created, and the key refers to the name
+    of an image, this file is called to upload the file to the server 
+    and store it on a predetermined location.
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 17 April 2002
+    @cvs-id $Id: localized-message-new-3.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+
+} {
+    upload_file:trim
+    return_url
+    key
+    locales
+} -properties {
+}
+
+# check the permission
+set package_id [ad_conn package_id]
+set permission_p [ad_permission_p $package_id nro_admin]
+
+if { !$permission_p } {
+    ad_returnredirect "/gp-admin"
+}
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+# TODO: make the error processing better ... I don't really like these 
+# ad_return_warning errors. BEM
+
+if { ![info exists upload_file] || [empty_string_p $upload_file] } {
+
+    # Oops. There is no file beeing uploaded.
+    ad_return_warning "error" "You should select a file to upload..."
+    ad_script_abort
+
+} else {
+
+    set tmp_filename [ns_queryget upload_file.tmpfile]
+    set file_extension [string tolower [file extension $upload_file]]
+    # remove the first "." from the file extension
+    regsub "\." $file_extension "" file_extension
+
+    # TODO: Support more graphic file formats. For the time being
+    # we only work with jpg, gif or png
+    if { ![regexp {^(jpeg|jpg|gif|png)$} $file_extension] } {
+        append error_message "The only file formats supported are JPG, GIF or PNG.
+        <br />Use the BACK button to submit another file"
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+    }
+
+    set guessed_file_type [ns_guesstype $upload_file]
+    set n_bytes [file size $tmp_filename]
+
+    # TODO: Make some parameter for the maximum size (in bytes) for these
+    # images. For the time being, we use a hardwired 100k
+    if { $n_bytes > ( 100 * 1024 ) } {
+
+        # The size is too big!
+        set error_message "The size of the image you are uploading is too big.
+            The maximum size allowed is 100KB."
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+
+    }
+
+    # strip off the C:\directories... crud and just get the file name
+    if ![regexp {([^/\\]+)$} $upload_file match client_filename] {
+        # couldn't find a match
+        set client_filename $upload_file
+    }
+
+    # We keep the following few lines just in case we need to do some
+    # size checks in the future.
+
+    set what_aolserver_told_us ""
+    if { $file_extension == "jpeg" || $file_extension == "jpg" } {
+        catch { set what_aolserver_told_us [ns_jpegsize $tmp_filename] }
+    } elseif { $file_extension == "gif" } {
+        catch { set what_aolserver_told_us [ns_gifsize $tmp_filename] }
+    }
+
+    # the AOLserver jpegsize command has some bugs where the height comes
+    # through as 1 or 2
+
+    if { ![empty_string_p $what_aolserver_told_us] && [lindex $what_aolserver_told_us 0] > 10 && \
+        [lindex $what_aolserver_told_us 1] > 10 } {
+
+        set original_width [lindex $what_aolserver_told_us 0]
+        set original_height [lindex $what_aolserver_told_us 1]
+
+    } else {
+
+        set original_width ""
+        set original_height ""
+
+    }
+
+    # The name of the file is the message created by the user
+    set localized_message [_ $locale_user $key]
+    set message_file_extension [file extension $localized_message]
+    regsub "\." $message_file_extension "" message_file_extension
+    if { $file_extension != $message_file_extension } {
+        set error_message "You have to upload a file with the <strong>same extension</strong>
+            as the one you stated in the message."
+        ad_return_warning "Error" $error_message
+        ad_script_abort
+    }
+     
+
+    set apm_package_id [util_memoize {get_acs_object_id apm_service} 900]
+    set ImageFolderPath [ad_parameter -package_id $apm_package_id ImageFolderPath]
+
+    set destination_path "${ImageFolderPath}/${localized_message}"
+
+    # Copy the file uploaded to its location in the filesystem
+    # If there was another version of the file there, overwrite it without
+    # any notice.
+    file copy -force -- $tmp_filename $destination_path
+
+}
+
+db_release_unused_handles
+
+# If we get here it's because everything went fine... Do we really believe that? ;)
+
+ns_returnredirect $return_url
Index: openacs-4/packages/acs-lang/www/admin/localized-message-new.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/localized-message-new.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-message-new.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,29 @@
+<master src="master">
+ <property name="title">Edit a message</property>
+
+<h2>New Localized Messages</h2>
+
+@context_bar@
+
+<hr />
+
+<div>
+
+<if @locale_label@ nil>
+
+  <p class="error">Please, submit a valid locale.</p>
+
+</if>
+<else>
+
+  <p>Locale: <strong>@locale_label@</strong> [ <tt>@locale_user@</tt> ]</p>
+
+  <formtemplate id="message_new"></formtemplate>
+
+  <p style="font-size: 9pt; color: red">If the localized message is an image (like
+  the spinning globe for example) the &quote;message&quote; must be the filename.
+  The system will change the filename to make it unique.</p>
+
+</else>
+
+</div>
Index: openacs-4/packages/acs-lang/www/admin/localized-message-new.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/localized-message-new.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-message-new.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,182 @@
+# /packages/gp-lang/www/gpadmin/localized-message-new.tcl
+ad_page_contract {
+
+    Displays the form for the creation of a new localized message.
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 15 April 2002
+    @cvs-id $Id: localized-message-new.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+
+} {
+    locales
+    grouper_key
+} -properties {
+}
+
+# check the permission
+set package_id [ad_conn package_id]
+set permission_p [ad_permission_p $package_id nro_admin]
+
+if { !$permission_p } {
+    ad_returnredirect "/gp-admin"
+}
+
+# We check that this request is coming for the system wide default
+# locale. If not, we can't allow the creation of a new localized 
+# message.
+
+if { [exists_and_not_null locales] } {
+    set locale_user $locales
+} else {
+    set locale_user [ad_locale_locale_from_lang [ad_locale user language]]
+}
+
+set default_locale [ad_parameter DefaultLocale]
+
+if { $locale_user != $default_locale } {
+
+   # ooops!
+   # We should let the user know about this ... shouldn't we? noooooo... :)
+   set encoded_locale [ns_urlencode $locale_user]
+   ad_returnredirect "display-grouped-messages?locales=$encoded_locale"
+
+}
+
+set locale_label [ad_locale_get_label $locale_user]
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+append return_url "display-grouped-messages?locales=" [ns_urlencode $locale_user]
+
+set tab [ns_urlencode "localized-messages"]
+
+set context_bar [ad_context_bar [list "index?tab=$tab" "Locales & Messages"] \
+    [list "display-grouped-messages?tab=$tab&locales=$locales" "Listing"] \
+    "New"]
+
+template::form create message_new
+
+template::element create message_new grouper_key_display -label "categorizer" -datatype text \
+    -widget inform -value $grouper_key
+
+template::element create message_new key -label "key" -datatype text -widget text
+
+template::element create message_new message -label "Message" -datatype text \
+    -widget textarea -html { rows 6 cols 40 }
+
+template::element create message_new is_image_p -label "Is this an image?" \
+    -datatype text -widget radio -options { {"yes" "t"} {"no" "f"} }
+
+template::element create message_new grouper_key -label "grouper_key" \
+    -datatype text -widget hidden
+
+# The two hidden tags that we need to pass on the key and language to the
+# processing of the form
+template::element create message_new locales -label "locale" -datatype text -widget hidden
+
+if { [template::form is_request message_new] } {
+
+    template::element set_properties message_new grouper_key -value $grouper_key
+    template::element set_properties message_new locales -value $locale_user
+    template::element set_properties message_new is_image_p -value "f"
+
+} else {
+
+    # We are not getting a request, so it's a post. Get and validate
+    # the values
+
+    template::form get_values message_new
+
+    # We have to check the format of the key submitted by the user,
+    # We can't accept whitespaces or tabs, only alphanumerical and "-",
+    # "_" or "." characters. The 1st character can't be a "."
+    if { [regexp {[^[:alnum:]\_\-\.\?]} $key] } {
+
+        # We matched for a forbidden character
+        template::element set_error message_new key \
+            "Key can only have alphanumeric or \"-\", \"_\", \".\" or \"?\" characters"
+
+    } 
+
+    if { [string length $key] >= 80 } {
+
+        # Oops. The length of the key is too high.
+        template::element set_error message_new key \
+            "Key can only have less than 80 characters"
+
+    }
+
+    # If the user selected the radio button saying that this is an image,
+    # we make sure that the message contains a correct filename (no spaces
+    # and the file extension is either jpeg, jpg, gif or png)
+    if { $is_image_p == "t" } {
+        set message_tmp [string tolower $message]
+        if { ![regexp {([[:alnum:]\_\-]+)(\.jpeg|\.jpg|\.gif|\.png)$} $message_tmp] } {
+            # If we are here it's because the regular expression didn't match
+            # It seems like the user is creating a wrongly formatted message
+            template::element set_error message_new message \
+                "If uploading an image, the message must be the filename. We can only
+                accept GIF, JPG or PNG at the moment."
+        }
+    }
+} 
+
+if { [template::form is_valid message_new] } {
+
+    # We get the values from the form
+    template::form get_values message_new grouper_key
+    template::form get_values message_new key
+    template::form get_values message_new locales
+    template::form get_values message_new message
+    template::form get_values message_new is_image_p
+
+    # Let's create the proper key
+    append real_key $grouper_key "." $key
+
+    # We use the gp-lang registration of a translation. Simple, eh?
+    if { $is_image_p == "t" } {
+
+        # Since the user will be uploading in the next few screens an image and
+        # the message will be the filename we use to store the file in the
+        # filesystem, to make it unique, we prepend the key and the locale to
+        # the file.
+
+        set message_lowercase [string tolower $message]
+
+        append message_to_store $real_key "_" $locales "_" $message_lowercase
+
+        _mr $locales $real_key $message_to_store
+
+    } elseif { $is_image_p == "f" } {
+
+        # Since the user is not uploading an image, we don't mess around
+        # with the message.
+
+        _mr $locales $real_key $message
+
+    }
+
+    set escaped_locale [ns_urlencode $locales]
+
+    db_release_unused_handles
+
+    # We check if the user told us that this was an image, if it is we
+    # redirect him/her to the second step where he/she can upload the
+    # image. If not, we send the user back to the listing of grouped
+    # messages for this locale.
+
+    if { $is_image_p == "t" } {
+
+        set return_url "localized-message-new-2?key="
+        append return_url [ns_urlencode $real_key] "&locales=" $escaped_locale
+
+    } 
+
+    template::forward $return_url
+
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/localized-messages.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/localized-messages.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-messages.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,19 @@
+<p>Select a locale to edit messages</p>
+<table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+  <td style="background: #CCCCCC">
+   <table cellpadding="4" cellspacing="1" border="0">
+    <tr style="background: #FFFFe4">
+     <th>Locale</th>
+     <th>Label</th>
+    </tr>
+    <multiple name="locales">
+     <tr style="background: #EEEEEE">
+      <td>@locales.locale@</td>
+      <td><a href="display-grouped-messages?locales=@locales.escaped_locale@">@locales.locale_name@</a></td>
+     </tr>
+    </multiple>
+   </table>
+  </td>
+ </tr>
+</table>
Index: openacs-4/packages/acs-lang/www/admin/localized-messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/localized-messages.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/localized-messages.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,23 @@
+ad_page_contract {
+
+    Administration of the localized messages
+
+    @author Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
+    @creation-date 19 October 2001
+    @cvs-id $Id: localized-messages.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+}
+
+#  AS - doesn't work
+#  set encoding_charset [ad_locale charset $locale_user]
+#  ns_setformencoding $encoding_charset
+#  ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=$encoding_charset"
+
+db_multirow -extend { escaped_locale } locales select_locale_list {
+    select locale as locale,
+           label as locale_name
+    from   ad_locales
+} {
+    set escaped_locale [ns_urlencode $locale]
+}
+
+db_release_unused_handles
Index: openacs-4/packages/acs-lang/www/admin/master.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/master.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/master.adp	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=@encoding_charset@" />
+<link rel="stylesheet" type="text/css" href="/css/gp-lang.css" />
+<title>@title@</title>
+<if @header_stuff@ not nil>
+ @header_stuff@
+</if>
+</head>
+<body>
+
+<slave />
+
+</body>
+</html>
Index: openacs-4/packages/acs-lang/www/admin/master.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/Attic/master.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/master.tcl	7 Oct 2002 14:32:48 -0000	1.1
@@ -0,0 +1,16 @@
+ad_page_contract {
+    Master template for gp-lang admin pages.
+
+    @ author Alex Sokoloff <alex_sokoloff@yahoo.com>
+    @ creation-date 20020910
+    @ cvs-id $Id: master.tcl,v 1.1 2002/10/07 14:32:48 lars Exp $
+} -properties {
+    encoding_charset:onevalue
+}
+
+#set encoding_charset [gp_determine_charset]
+
+# LARS:
+set encoding_charset ""
+
+ad_return_template
Index: openacs-4/packages/acs-lang/www/admin/test/catalog-test.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/catalog-test.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/catalog-test.adp	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,71 @@
+<%
+    ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=iso-8859-1"	
+%>
+@header@
+<h3>@title@</h3>
+@context_bar@
+<hr>
+<p>
+[ad_locale user locale] ==> @locale@
+<br>
+[ad_locale user language] ==> @language@
+<br>
+[ad_locale_language_name @language@] ==> @language_name@
+<p>
+
+
+<b>Test 1</b>
+<p>
+<em>Verify that the message catalog loader ran
+successfully at server startup.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><th>Word to lookup</th><th>Language</th><th>Results of catalog lookup</th></tr>
+<tr><td>English</td><td>English</td><td>@english@</td></tr>
+<tr><td>French</td><td>French</td><td>@french@</td></tr>
+<tr><td>Spanish</td><td>Spanish</td><td>@spanish@</td></tr>
+<tr><td>German</td><td>German</td><td>@german@</td></tr>
+</table>
+<p>
+
+<b>Test 2</b>
+<p>
+<em>Verify that the &lt;trn&gt; ADP tag works when the user's preferred
+language is set to 
+<a href="locale-set?locale=en_US">English</a>,
+<a href="locale-set?locale=fr_FR">French</a>,
+<a href="locale-set?locale=es_ES">Spanish</a>,
+or <a href="locale-set?locale=de_DE">German</a></em>.
+<p>
+
+Test of inline  adp tags:
+<table cellspacing=0 cellpadding=4 border=1>
+  <tr>
+    <th>Word to lookup</th>
+    <th>&lt;TRN&gt;</th>
+    <th>\#...#</th>
+  </tr>
+  <tr>
+    <td>English</td>
+    <td><trn key="test.English">English</trn></td>
+    <td>#test.English#</td>
+  </tr>
+  <tr>
+    <td>French</td>
+    <td><trn key="test.French">French</trn></td>
+    <td>#test.French#</td>
+  </tr>
+  <tr>
+    <td>Spanish</td>
+    <td><trn key="test.Spanish">Spanish</trn></td>
+    <td>#test.Spanish#</td>
+  </tr>
+  <tr>
+    <td>German</td>
+    <td><trn key="test.German">German</trn></td>
+    <td>#test.German#</td></td>
+  </tr>
+</table>
+<p>
+
+@footer@
Index: openacs-4/packages/acs-lang/www/admin/test/catalog-test.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/catalog-test.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/catalog-test.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,33 @@
+#/packages/lang/www/test.tcl
+ad_page_contract {
+
+    Tests procedures in the lang package
+
+    @author John Lowry (lowry@ardigita.com)
+    @creation-date 29 September 2000
+    @cvs-id $Id: catalog-test.tcl,v 1.1 2002/10/07 14:32:49 lars Exp $
+} { }
+
+set title "Test acs-lang package message catalog and locale API"
+set header [ad_header $title]
+set context_bar [ad_context_bar "Message Catalog Test"]
+set footer [ad_footer]
+
+# Test 1 verifies that the message catalog has loaded successfully
+set english [_ en test.English]
+set french  [_ fr test.French]
+set spanish [_ es test.Spanish]
+set german  [_ de test.German]
+
+
+set locale [ad_locale user locale]
+#set locale "ja_JP"
+
+set language [ad_locale user language]
+#set language ja
+
+set language_name [ad_locale_language_name $language]
+
+
+
+ad_return_template
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/admin/test/compile.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/compile.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/compile.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,16 @@
+set file [ns_queryget file]
+
+if { [regexp {\.\.|^/} $file] } {
+
+  set compiled "Only files within this directory may be shown."
+
+} else {
+ 
+  # [ns_url2file [ns_conn url]]  fails under request processor !
+  # the file for URL pkg/page may be in packages/pkg/www/page, not www/pkg/page
+  set dir [file dirname [ad_conn file]]
+  set compiled [ns_quotehtml [template::adp_compile -file $dir/$file]]
+}
+
+ns_return 200 text/html "<pre>$compiled</pre>"
+  set dir [file dirname [ns_url2file [ns_conn url]]]
Index: openacs-4/packages/acs-lang/www/admin/test/format-test-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/format-test-oracle.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/format-test-oracle.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<queryset>
+   <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
+
+<fullquery name="lang_system_time_select">      
+      <querytext>
+      SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/packages/acs-lang/www/admin/test/format-test-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/format-test-postgresql.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/format-test-postgresql.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<queryset>
+<rdbms><type>postgresql</type><version>7.1</version></rdbms>
+ 
+<fullquery name="lang_system_time_select">
+    <querytext>
+	SELECT to_char(current_time, 'YYYY-MM-DD HH24:MI:SS') AS system_time
+    </querytext>
+</fullquery>
+	        
+</queryset>
+	                            
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/admin/test/format-test.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/format-test.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/format-test.adp	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,38 @@
+<%
+    ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=iso-8859-1"	
+%>
+@header@
+<h3>@title@</h3>
+<a href="/pvt/home">Your Workspace</a> : Testing the locale-dependent formatting API
+<hr>
+<p>
+
+<b>Test 5</b>
+<p>
+<em>Verify the results of localization routines.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+            <tr><th>Routine</th><th>en_US locale</th>
+                <th>en_FR locale</th></tr>
+            <tr><td>Displaying a number</td>
+                <td>@us_number@</td>
+                <td>@fr_number@</td></tr>
+            <tr><td>Parsing a number</td>
+                <td>@us_parse@</td>
+                <td>@fr_parse@</td></tr>
+            <tr><td rowspan=2 valign=top>Displaying a monetary amount</td>
+                <td>@us_currency@</td>
+                <td>@fr_currency@</td></tr>
+            <tr><td>@us_label@</td>
+                <td>@fr_label@</td></tr>
+            <tr><td>Displaying a date</td>
+                <td>@us_time@</td>
+                <td>@fr_time@</td></tr>
+            </table>
+<p>
+
+@footer@
+
+
+
+
Index: openacs-4/packages/acs-lang/www/admin/test/format-test.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/format-test.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/format-test.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,30 @@
+#/packages/lang/www/test.tcl
+ad_page_contract {
+
+    Tests procedures in the lang package
+
+    @author John Lowry (lowry@ardigita.com)
+    @creation-date 29 September 2000
+    @cvs-id $Id: format-test.tcl,v 1.1 2002/10/07 14:32:49 lars Exp $
+} { }
+
+set title "Test acs-lang package formatting routines"
+set header [ad_header $title]
+# set navbar [ad_context_bar "Test"]
+set footer [ad_footer]
+
+db_1row lang_system_time_select "SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual"
+
+# Test 5 checks the localization routines
+set us_number [lc_numeric 123456.789 {} en_US]
+set fr_number [lc_numeric 123456.789 {} fr_FR]
+set us_parse [lc_parse_number 123,456.789 en_US]
+set fr_parse [lc_parse_number "123 456,789" fr_FR]
+set us_currency [lc_monetary_currency -label_p 1 -style local 123.4 USD en_US]
+set fr_currency [lc_monetary_currency -label_p 1 -style local 123.4 USD fr_FR]
+set us_label [lc_monetary_currency -label_p 1 -style local 1234 FRF en_US]
+set fr_label [lc_monetary_currency -label_p 1 -style local 1234 FRF fr_FR]
+set us_time [lc_time_fmt $system_time "%c" en_US]
+set fr_time [lc_time_fmt $system_time "%c" fr_FR]
+
+ad_return_template
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/admin/test/index.html
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/index.html,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/index.html	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,22 @@
+<html>
+<head>
+<title>ACS I18N Tests</title>
+</head>
+<body>
+
+<h1>ACS I18N Tests</h1>
+
+Note, the timezone and currency formatting tests require the
+<tt>acs-reference</tt> package to be loaded.
+
+<ul>
+<li><a href=catalog-test>Test the message catalog and locales mechanism</a>
+<p>
+<li><a href=timezone>Test the timezones database</a>
+<p>
+<li><a href=format-test>Test date and number formatting database</a>
+<p>
+<li><a href=show-catalog>List Message Catalog Data</a>
+<p>
+
+</ul>
Index: openacs-4/packages/acs-lang/www/admin/test/index.html~
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/index.html~,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/index.html~	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,39 @@
+<html>
+<head>
+<title>ACS I18N Tests</title>
+</head>
+<body>
+
+<h1>Administration</h1>
+<ul>
+<li><a href=set-system-timezone>Set ACS System Timezone</a>
+</ul>
+<p>
+
+<h1>ACS I18N Tests</h1>
+
+Note, the timezone and currency formatting tests require the
+<tt>acs-reference</tt> package to be loaded.
+
+<ul>
+<li><a href=catalog-test>Test the message catalog and locales mechanism</a>
+<p>
+<li><a href=timezone>Test the timezones database</a>
+<p>
+<li><a href=format-test>Test date and number formatting database</a>
+<p>
+<li><a href=show-catalog>List Message Catalog Data</a>
+<p>
+
+
+</ul>
+
+<h3>Documentation</h3>
+
+<p>
+<a href=doc/i18n-requirements.html>Requirements Document</a>
+<p>
+<a href=doc/i18n-design.html>Design Document</a>
+<p>
+<a href=doc/acs4-patches.txt</a> Patches to ACS 4</a> to allow authoring and output of scripts and templates in non-ISO-8859-1  character sets.
+
Index: openacs-4/packages/acs-lang/www/admin/test/show-catalog.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/show-catalog.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/show-catalog.adp	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,24 @@
+<%
+    ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=utf-8"	
+%>
+
+
+<master>
+Message Catalog
+<table border=1>
+<tr>
+<th></th>
+<th>Lang</th>
+<th>Message</th>
+</tr>
+<multiple name=catalog>
+<tr><th bgcolor=#cccccc colspan=3 align=left>@catalog.key@</td></tr>
+<group column=key>
+<tr>
+<td width=20></td>
+<td> @catalog.locale@</td>
+<td> @catalog.message@</td>
+</tr>
+</group>
+</multiple>
+</table>
Index: openacs-4/packages/acs-lang/www/admin/test/show-catalog.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/show-catalog.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/show-catalog.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,24 @@
+#/packages/acs-lang/www/show-catalog.tcl
+ad_page_contract {
+
+    List contents of message catalog
+
+    @author Henry Minsky (hqm@ardigita.com)
+    @creation-date 29 September 2000
+    @cvs-id $Id: show-catalog.tcl,v 1.1 2002/10/07 14:32:49 lars Exp $
+} { }
+
+set title "Show Message Catalog"
+set header [ad_header $title]
+# set navbar [ad_context_bar "Show Message Catalog "]
+set footer [ad_footer]
+
+# Test 3 checks that the timezone tables are installed
+# Need this data to check that test 4 works
+set cat_sql "SELECT key, locale, message, registered_p
+               FROM lang_messages
+              ORDER BY key, locale"
+
+db_multirow catalog catalog_data $cat_sql
+
+ad_return_template
Index: openacs-4/packages/acs-lang/www/admin/test/show.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/show.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/show.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,16 @@
+set file [ns_queryget file]
+
+if { [regexp {\.\.|^/} $file] } {
+
+  set output "Only files within this directory may be shown."
+
+} else {
+ 
+  # [ns_url2file [ns_conn url]]  fails under request processor !
+  # the file for URL pkg/page may be in packages/pkg/www/page, not www/pkg/page
+  set dir [file dirname [ad_conn file]]
+  set text [ns_quotehtml [template::util::read_file $dir/$file]]
+  set output "<pre>$text</pre>"
+}
+
+ns_return 200 text/html $output
Index: openacs-4/packages/acs-lang/www/admin/test/test-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/test-oracle.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/test-oracle.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<queryset>
+   <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
+
+<fullquery name="lang_system_time_select">      
+      <querytext>
+      SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/packages/acs-lang/www/admin/test/test-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/test-postgresql.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/test-postgresql.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<queryset>
+   <rdbms><type>postgresql</type><version>7.1</version></rdbms>
+
+<fullquery name="lang_system_time_select">      
+      <querytext>
+      SELECT to_char(current_time, 'YYYY-MM-DD HH24:MI:SS') AS system_time
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/packages/acs-lang/www/admin/test/test.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/test.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/test.adp	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,96 @@
+<%
+    ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=iso-8859-1"	
+%>
+@header@
+<h3>@title@</h3>
+<a href="/pvt/home">Your Workspace</a> : Testing the language and localization API
+<hr>
+<p>
+<b>Test 1</b>
+<p>
+<em>Verify that the message catalog loader ran
+successfully at server startup.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><th>Word to lookup</th><th>Language</th><th>Results of catalog lookup</th></tr>
+<tr><td>English</td><td>English</td><td>@english@</td></tr>
+<tr><td>French</td><td>French</td><td>@french@</td></tr>
+<tr><td>Spanish</td><td>Spanish</td><td>@spanish@</td></tr>
+<tr><td>German</td><td>German</td><td>@german@</td></tr>
+</table>
+<p>
+
+<b>Test 2</b>
+<p>
+<em>Verify that the &lt;trn&gt; ADP tag works when the user's preferred
+language is set to 
+<a href="locale-set?locale=en">English</a>,
+<a href="locale-set?locale=fr">French</a>,
+<a href="locale-set?locale=es">Spanish</a>,
+or <a href="locale-set?locale=de">German</a></em>.
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><th>Word to lookup</th><th>Result when user's preferred language is @language@</tr>
+<tr><td>English</td><td>@trn_english@</td></tr>
+<tr><td>French</td><td>@trn_french@</tr>
+<tr><td>Spanish</td><td>@trn_spanish@</td></tr>
+<tr><td>German</td><td>@trn_german@</td></td></tr>
+</table>
+<p>
+
+<b>Test 3</b>
+<p>
+<em>Verify that data required to convert from local times for Europe/Paris into Universal Time
+is loaded into the database.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><th>Timezone</th><th>Start date</th><th>End date</th><th>UTC offset</th>
+<multiple name=tz_results>
+<tr><td>@tz_results.timezone@</td><td>@tz_results.local_start@</td>
+<td>@tz_results.local_end@</td><td align=right>@tz_results.utc_offset@</td></tr>
+</multiple>
+</table>
+<p>
+
+<b>Test 4</b>
+<p>
+<em>Verify that the conversions between UTC and local time work correctly.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><td>Oracle sysdate (should be UTC)</td><td>@system_time@</td></tr>
+<tr><td>Local time in Europe/Paris</td><td>@paris_time@</td></tr>
+<tr><td>UTC time (converted from Paris time)</td><td>@local_time@</tr>
+<tr><td>Local time in Tokyo, Japan</td><td>@tokyo_time@</td></tr>
+<tr><td>UTC time (converted from Tokyo time)</td><td>@tokyo_utc_time@</tr>
+</table>
+<p>
+
+<b>Test 5</b>
+<p>
+<em>Verify the results of localization routines.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+            <tr><th>Routine</th><th>en_US locale</th>
+                <th>en_FR locale</th></tr>
+            <tr><td>Displaying a number</td>
+                <td>@us_number@</td>
+                <td>@fr_number@</td></tr>
+            <tr><td>Parsing a number</td>
+                <td>@us_parse@</td>
+                <td>@fr_parse@</td></tr>
+            <tr><td rowspan=2 valign=top>Displaying a monetary amount</td>
+                <td>@us_currency@</td>
+                <td>@fr_currency@</td></tr>
+            <tr><td>@us_label@</td>
+                <td>@fr_label@</td></tr>
+            <tr><td>Displaying a date</td>
+                <td>@us_time@</td>
+                <td>@fr_time@</td></tr>
+            </table>
+<p>
+
+@footer@
+
+
+
+
Index: openacs-4/packages/acs-lang/www/admin/test/test.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/test.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/test.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,78 @@
+#/packages/lang/www/test.tcl
+ad_page_contract {
+
+    Tests procedures in the lang package
+
+    @author John Lowry (lowry@ardigita.com)
+    @creation-date 29 September 2000
+    @cvs-id $Id: test.tcl,v 1.1 2002/10/07 14:32:49 lars Exp $
+} { }
+
+set title "Test lang package"
+set header [ad_header $title]
+# set navbar [ad_context_bar "Test"]
+set footer [ad_footer]
+
+# Test 1 verifies that the message catalog has loaded successfully
+set english [_ en test.English]
+set french [_ fr test.French]
+set spanish [_ es test.Spanish]
+set german [_ de test.German]
+
+#set lang [ad_locale user language]
+set lang [ad_get_client_property lang locale]
+if {[empty_string_p $lang]} {
+    set lang "en"
+}
+
+db_1row lang_get_lang_name "SELECT nls_language as language FROM ad_locales WHERE language = :lang"
+if [empty_string_p $language] {
+    set language English
+}
+
+# Test 2 checks the locale cookie to display in user's preferred language.
+# We cannot embed the tags in the template because they will not get run each time.
+# So we won't see the results of changing the locale cookie immediately.
+set trn_english [ns_adp_parse "<trn key=\"test.English\">English</trn>"]
+set trn_french [ns_adp_parse "<trn key=\"test.French\">French</trn>"]
+set trn_spanish [ns_adp_parse "<trn key=\"test.Spanish\">Spanish</trn>"]
+set trn_german [ns_adp_parse "<trn key=\"test.German\">German</trn>"]
+
+# Test 3 checks that the timezone tables are installed
+# Need this data to check that test 4 works
+set tz_sql "SELECT tz as timezone
+                   ,local_start
+                   ,local_end
+                   ,ROUND(timezones.gmt_offset * 24) as utc_offset
+              FROM timezone_rules, timezones
+             WHERE timezones.tz = 'Europe/Paris'
+                   and timezone_rules.tz_id = timezones.tz_id
+               AND local_start > sysdate - 365
+               AND local_end < sysdate + 365
+          ORDER BY local_start"
+db_multirow tz_results lang_tz_get_data $tz_sql
+
+# Test 4 checks that we can convert from local time to UTC
+db_1row lang_system_time_select "SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual"
+
+set paris_time [lc_time_utc_to_local $system_time "Europe/Paris"]
+set local_time [lc_time_local_to_utc $paris_time "Europe/Paris"]
+
+
+set tokyo_time [lc_time_utc_to_local $system_time "Asia/Tokyo"]
+set tokyo_utc_time [lc_time_local_to_utc $paris_time "Asia/Tokyo"]
+
+
+# Test 5 checks the localization routines
+set us_number [lc_numeric 123456.789 {} en_US]
+set fr_number [lc_numeric 123456.789 {} fr_FR]
+set us_parse [lc_parse_number 123,456.789 en_US]
+set fr_parse [lc_parse_number "123 456,789" fr_FR]
+set us_currency [lc_monetary_currency -label_p 1 -style local 123.4 USD en_US]
+set fr_currency [lc_monetary_currency -label_p 1 -style local 123.4 USD fr_FR]
+set us_label [lc_monetary_currency -label_p 1 -style local 1234 FRF en_US]
+set fr_label [lc_monetary_currency -label_p 1 -style local 1234 FRF fr_FR]
+set us_time [lc_time_fmt $system_time "%c" en_US]
+set fr_time [lc_time_fmt $system_time "%c" fr_FR]
+
+ad_return_template
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/admin/test/timezone-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/timezone-oracle.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/timezone-oracle.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<queryset>
+   <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
+
+<fullquery name="lang_system_time_select">      
+      <querytext>
+      SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/packages/acs-lang/www/admin/test/timezone-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/timezone-postgresql.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/timezone-postgresql.xql	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<queryset>
+<rdbms><type>postgresql</type><version>7.1</version></rdbms>
+ 
+<fullquery name="lang_system_time_select">
+    <querytext>
+	select to_char(current_time, 'YYYY-MM-DD HH24:MI:SS') AS system_time
+    </querytext>
+</fullquery>
+	        
+</queryset>
+	                            
\ No newline at end of file
Index: openacs-4/packages/acs-lang/www/admin/test/timezone.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/timezone.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/timezone.adp	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,59 @@
+<%
+    ns_set put [ns_conn outputheaders] "content-type" "text/html; charset=iso-8859-1"	
+%>
+@header@
+<h3>@title@</h3>
+<a href="/pvt/home">Your Workspace</a> : Testing the timezone API
+<hr>
+<p>
+
+
+<b>Test 3</b>
+<p>
+<em>Verify that data required to convert from local times for Europe/Paris into Universal Time
+is loaded into the database.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr><th>Timezone</th><th>Start date</th><th>End date</th><th>UTC offset</th>
+<multiple name=tz_results>
+<tr><td>@tz_results.timezone@</td><td>@tz_results.local_start@</td>
+<td>@tz_results.local_end@</td><td align=right>@tz_results.utc_offset@</td></tr>
+</multiple>
+</table>
+<p>
+
+<b>Test 4</b>
+<p>
+<em>Verify that the conversions between UTC and local time work correctly.</em>
+<p>
+<table cellspacing=0 cellpadding=4 border=1>
+<tr bgcolor=#cc00ff><th>Locale</th><th>Time</th><th>Test Passed?</th></tr>
+<tr bgcolor=#cc00ff><td>Oracle sysdate (should be UTC)</td><td>@system_time@</td><td>&nbsp;</td></tr>
+<tr colspan=4><td>&nbsp; </td></tr>
+<tr bgcolor=#cccccc><td>Local time in America/New_York</td><td>@NYC_time@</td><td>&nbsp; </td></tr>
+<tr><td>UTC time (converted from New York time)</td><td>@NYC_utc_time@</td><td>@NYC_p@</tr>
+
+<tr colspan=4><td>&nbsp; </td></tr>
+<tr bgcolor=#cccccc><td>Local time in America/Los_Angeles</td><td>@LA_time@</td> <td>&nbsp; </td></tr>
+<tr><td>UTC time (converted from Los Angeles time)</td><td>@LA_utc_time@</td><td>@LA_p@</td></tr>
+
+<tr colspan=4><td>&nbsp; </td></tr>
+
+<tr bgcolor=#cccccc><td>Local time in Europe/Paris</td><td>@paris_time@</td><td>&nbsp; </td> </tr>
+<tr><td>UTC time (converted from Paris time)</td><td>@paris_utc_time@</td><td>@paris_p@</td></tr>
+
+<tr colspan=4><td>&nbsp; </td></tr>
+
+<tr bgcolor=#cccccc><td>Local time in Asia/Tokyo</td><td>@tokyo_time@</td><td>&nbsp; </td> </tr>
+<tr><td>UTC time (converted from Tokyo time)</td><td>@tokyo_utc_time@</td><td>@tokyo_p@</td></tr>
+
+</table>
+<p>
+
+
+
+@footer@
+
+
+
+
Index: openacs-4/packages/acs-lang/www/admin/test/timezone.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/timezone.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/timezone.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,69 @@
+#/packages/lang/www/test.tcl
+ad_page_contract {
+
+    Tests procedures in the lang package
+
+    @author John Lowry (lowry@ardigita.com)
+    @creation-date 29 September 2000
+    @cvs-id $Id: timezone.tcl,v 1.1 2002/10/07 14:32:49 lars Exp $
+} { }
+
+set title "Test acs-lang package timezones"
+set header [ad_header $title]
+# set navbar [ad_context_bar "Test"]
+set footer [ad_footer]
+
+
+# Test 3 checks that the timezone tables are installed
+# Need this data to check that test 4 works
+set tz_sql "SELECT tz as timezone
+                   ,local_start
+                   ,local_end
+                   ,ROUND(timezones.gmt_offset * 24) as utc_offset
+              FROM timezone_rules, timezones
+             WHERE timezones.tz = 'Europe/Paris'
+                   and timezone_rules.tz_id = timezones.tz_id
+               AND local_start > sysdate - 365
+               AND local_end < sysdate + 365
+          ORDER BY local_start"
+db_multirow tz_results lang_tz_get_data $tz_sql
+
+# Test 4 checks that we can convert from local time to UTC
+db_1row lang_system_time_select "SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS system_time FROM dual"
+
+set NYC_time [lc_time_utc_to_local $system_time "America/New_York"]
+set NYC_utc_time [lc_time_local_to_utc $NYC_time "America/New_York"]
+if {[string compare $system_time $NYC_utc_time] == 0} {
+    set NYC_p "OK"
+} else {
+    set NYC_p "<font color=red>FAILED</font>"
+}
+
+
+set LA_time [lc_time_utc_to_local $system_time "America/Los_Angeles"]
+set LA_utc_time [lc_time_local_to_utc $LA_time "America/Los_Angeles"]
+if {[string compare $system_time $LA_utc_time] == 0} {
+    set LA_p "OK"
+} else {
+    set LA_p "<font color=red>FAILED</font>"
+}
+
+set paris_time [lc_time_utc_to_local $system_time "Europe/Paris"]
+set paris_utc_time [lc_time_local_to_utc $paris_time "Europe/Paris"]
+if {[string compare $system_time $paris_utc_time] == 0} {
+    set paris_p "OK"
+} else {
+    set paris_p "<font color=red>FAILED</font>"
+}
+
+set tokyo_time [lc_time_utc_to_local $system_time "Asia/Tokyo"]
+set tokyo_utc_time [lc_time_local_to_utc $tokyo_time "Asia/Tokyo"]
+if {[string compare $system_time $tokyo_utc_time] == 0} {
+    set tokyo_p "OK"
+} else {
+    set tokyo_p "<font color=red>FAILED</font>"
+}
+
+
+ad_return_template
+
Index: openacs-4/packages/acs-lang/www/admin/test/tz-test.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/test/Attic/tz-test.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-lang/www/admin/test/tz-test.tcl	7 Oct 2002 14:32:49 -0000	1.1
@@ -0,0 +1,34 @@
+
+ad_page_contract {
+ Test system timezone offset mechanism
+
+} {
+}
+
+
+
+append page "
+ad_locale_system_timezone = [ad_locale_get_system_timezone]
+ad_locale_system_tz_offset = [ad_locale_system_tz_offset]
+<p>
+
+"
+
+set widget "<select name=gmt_offset>"
+
+foreach {tz} [lc_list_all_timezones] {
+    append widget "<option value=\"$tz\">$tz</option>"
+}
+
+append widget "</select>"
+
+append page "
+<form action=tz-test method=get>
+Timezone $widget
+<p>
+<input type=submit>
+</form>
+"
+
+doc_return 200 text/html $page
+