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 -N -r1.55 -r1.56 --- openacs-4/packages/acs-lang/acs-lang.info 11 Jul 2009 23:47:24 -0000 1.55 +++ openacs-4/packages/acs-lang/acs-lang.info 8 Jan 2010 17:39:58 -0000 1.56 @@ -7,7 +7,7 @@ t t - + Peter Marklund OpenACS Internationalization Support. 2009-06-19 @@ -18,13 +18,16 @@ request processor hooks, templating, accessing and managing the message catalog, and locale-specific formatting functions for localizing dates, times, monetary amounts etc. - + + + + Index: openacs-4/packages/acs-lang/sql/oracle/ad-locales-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/ad-locales-drop.sql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/acs-lang/sql/oracle/ad-locales-drop.sql 24 Feb 2004 12:03:08 -0000 1.3 +++ openacs-4/packages/acs-lang/sql/oracle/ad-locales-drop.sql 8 Jan 2010 17:39:58 -0000 1.4 @@ -16,4 +16,5 @@ drop table ad_locale_user_prefs; drop view enabled_locales; drop table ad_locales; - +drop table language_codes; +drop table country_codes; 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 -N -r1.34 -r1.35 --- openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql 7 Jun 2008 20:28:53 -0000 1.34 +++ openacs-4/packages/acs-lang/sql/oracle/ad-locales.sql 8 Jan 2010 17:39:58 -0000 1.35 @@ -13,6 +13,23 @@ -- * that gets loaded on server startup, and hence should not get updated. -- **************************************************************************** +-- The language and country codes tables are filled by after_install +-- and after_upgrade apm callbacks +-- using the iso-3166-1-countries.txt and iso-639-2_utf-8.txt files + +create table language_codes ( + iso_639_2 char(3) constraint language_codes_pk primary key, + iso_639_1 char(2), + label varchar(200) +); +comment on table language_codes is 'Contains ISO-639-2 language codes and their corresponding ISO-639-1 when it exists.'; + +create table country_codes ( + label varchar(200), + country char(2) constraint country_codes_pk primary key +); +comment on table country_codes is 'Contains ISO-3166 country codes'; + create table ad_locales ( locale varchar2(30) constraint ad_locales_locale_pk @@ -41,13 +58,13 @@ ); comment on table ad_locales is ' - An ACS locale is identified by a language and country. + An OpenACS locale is identified by a language and country. Locale definitions in Oracle consist of a language, and optionally territory and character set. (Languages are associated with default territories and character sets when not defined). The formats for numbers, currency, dates, etc. are determined by the territory. - language is two letter abbrev is ISO 639 language code - country is two letter abbrev is ISO 3166 country code + language is the shortest ISO 639 code (lowercase). + country is two letter (uppercase) abbrev is ISO 3166 country code mime_charset is IANA charset name nls_charset is Oracle charset name '; @@ -220,12 +237,12 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ar_EG', 'Arabic (EG)', 'AR', 'EG', 'ARABIC', 'EGYPT', 'AR8ISO8859P6', 'ISO-8859-6', 'f', 'f'); + values ('ar_EG', 'Arabic (EG)', 'ar', 'EG', 'ARABIC', 'EGYPT', 'AR8ISO8859P6', 'ISO-8859-6', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ar_LB', 'Arabic (LB)', 'AR', 'LB', 'ARABIC', 'LEBANON', 'AR8ISO8859P6', 'ISO-8859-6', 't', 'f'); + values ('ar_LB', 'Arabic (LB)', 'ar', 'LB', 'ARABIC', 'LEBANON', 'AR8ISO8859P6', 'ISO-8859-6', 't', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, @@ -295,7 +312,7 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ind_ID', 'Bahasa Indonesia (ID)', 'in', 'ID', 'INDONESIAN', 'INDONESIA', 'WEB8ISO8559P1', 'ISO-8559-1', 't', 'f'); + values ('ind_ID', 'Bahasa Indonesia (ID)', 'id', 'ID', 'INDONESIAN', 'INDONESIA', 'WEB8ISO8559P1', 'ISO-8559-1', 't', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, @@ -330,12 +347,12 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('zh_HK', 'Simplified Chinese (HK)', 'hk', 'ZH', 'Simplified Chinese (Hong Kong)', 'Hong Kong', 'UTF8', 'UTF-8', 'f', 'f'); + values ('zh_HK', 'Simplified Chinese (HK)', 'zh', 'HK', 'Simplified Chinese (Hong Kong)', 'Hong Kong', 'UTF8', 'UTF-8', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('cz_CZ', 'Czech (CZ)', 'cz', 'CZ', 'Czech (Czech Republic)', 'Czech Republic', 'EE8ISO8859P2', 'ISO-8859-2', 'f', 'f'); + values ('cz_CZ', 'Czech (CZ)', 'cs', 'CZ', 'Czech (Czech Republic)', 'Czech Republic', 'EE8ISO8859P2', 'ISO-8859-2', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, Index: openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d1-5.6.0d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d1-5.6.0d2.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d1-5.6.0d2.sql 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,6 @@ +-- Fix wrong data in ad_locales + +update ad_locales set language = 'ar' where language = 'AR'; +update ad_locales set language = 'ind' where locale = 'ind_ID'; +update ad_locales set language = 'cs' where locale = 'cz_CZ'; +update ad_locales set language = 'zh', country = 'HK' where locale = 'zh_HK'; Index: openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d2-5.6.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d2-5.6.0d3.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/sql/oracle/upgrade/upgrade-5.6.0d2-5.6.0d3.sql 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,34 @@ +-- Create tables for languages and countries +-- +-- The tables are filled by after_install and after_upgrade apm callbacks +-- using the iso-3166-1-countries.txt and iso-639-2_utf-8.txt files + + +create table language_codes ( + iso_639_2 char(3) constraint language_codes_pk primary key, + iso_639_1 char(2), + label varchar(200) +); + +comment on table language_codes is 'Contains ISO-639-2 language codes and their corresponding ISO-639-1 when it exists.'; + +create table country_codes ( + label varchar(200), + country char(2) constraint country_codes_pk primary key +); + +comment on table country_codes is 'Contains ISO-3166 country codes'; + +-- update comment on ad_locales to be more accurate about how to +-- create new locales. +comment on table ad_locales is ' + An OpenACS locale is identified by a language and country. + Locale definitions in Oracle consist of a language, and optionally + territory and character set. (Languages are associated with default + territories and character sets when not defined). The formats + for numbers, currency, dates, etc. are determined by the territory. + language is the shortest ISO 639 code (lowercase). + country is two letter (uppercase) abbrev is ISO 3166 country code + mime_charset is IANA charset name + nls_charset is Oracle charset name +'; Index: openacs-4/packages/acs-lang/sql/postgresql/ad-locales-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/ad-locales-drop.sql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/acs-lang/sql/postgresql/ad-locales-drop.sql 24 Feb 2004 12:03:09 -0000 1.3 +++ openacs-4/packages/acs-lang/sql/postgresql/ad-locales-drop.sql 8 Jan 2010 17:39:58 -0000 1.4 @@ -16,4 +16,5 @@ drop table ad_locale_user_prefs; drop view enabled_locales; drop table ad_locales; - +drop table language_codes; +drop table country_codes; 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 -N -r1.30 -r1.31 --- openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql 7 Jun 2008 20:28:54 -0000 1.30 +++ openacs-4/packages/acs-lang/sql/postgresql/ad-locales.sql 8 Jan 2010 17:39:58 -0000 1.31 @@ -15,6 +15,23 @@ begin; +-- The language and country codes tables are filled by after_install +-- and after_upgrade apm callbacks +-- using the iso-3166-1-countries.txt and iso-639-2_utf-8.txt files + +create table language_codes ( + iso_639_2 char(3) constraint language_codes_pk primary key, + iso_639_1 char(2), + label varchar(200) +); +comment on table language_codes is 'Contains ISO-639-2 language codes and their corresponding ISO-639-1 when it exists.'; + +create table country_codes ( + label varchar(200), + country char(2) constraint country_codes_pk primary key +); +comment on table country_codes is 'Contains ISO-3166 country codes'; + create table ad_locales ( locale varchar(30) constraint ad_locales_locale_pk @@ -49,8 +66,8 @@ territory and character set. (Languages are associated with default territories and character sets when not defined). The formats for numbers, currency, dates, etc. are determined by the territory. - language is two letter abbrev is ISO 639 language code - country is two letter abbrev is ISO 3166 country code + language is the shortest ISO 639 code (lowercase). + country is two letter (uppercase) abbrev is ISO 3166 country code mime_charset is IANA charset name nls_charset is Oracle charset name '; @@ -226,12 +243,12 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ar_EG', 'Arabic (EG)', 'AR', 'EG', 'ARABIC', 'EGYPT', 'AR8ISO8859P6', 'ISO-8859-6', 'f', 'f'); + values ('ar_EG', 'Arabic (EG)', 'ar', 'EG', 'ARABIC', 'EGYPT', 'AR8ISO8859P6', 'ISO-8859-6', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ar_LB', 'Arabic (LB)', 'AR', 'LB', 'ARABIC', 'LEBANON', 'AR8ISO8859P6', 'ISO-8859-6', 't', 'f'); + values ('ar_LB', 'Arabic (LB)', 'ar', 'LB', 'ARABIC', 'LEBANON', 'AR8ISO8859P6', 'ISO-8859-6', 't', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, @@ -301,7 +318,7 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('ind_ID', 'Bahasa Indonesia (ID)', 'in', 'ID', 'INDONESIAN', 'INDONESIA', 'WEB8ISO8559P1', 'ISO-8559-1', 't', 'f'); + values ('ind_ID', 'Bahasa Indonesia (ID)', 'id', 'ID', 'INDONESIAN', 'INDONESIA', 'WEB8ISO8559P1', 'ISO-8559-1', 't', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, @@ -336,12 +353,12 @@ insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('zh_HK', 'Chinese, Simplified (HK)', 'hk', 'ZH', 'Simplified Chinese (Hong Kong)', 'Hong Kong', 'UTF8', 'UTF-8', 'f', 'f'); + values ('zh_HK', 'Chinese, Simplified (HK)', 'zh', 'HK', 'Simplified Chinese (Hong Kong)', 'Hong Kong', 'UTF8', 'UTF-8', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, nls_charset, mime_charset, default_p, enabled_p) - values ('cz_CZ', 'Czech (CZ)', 'cz', 'CZ', 'Czech (Czech Republic)', 'Czech Republic', 'EE8ISO8859P2', 'ISO-8859-2', 'f', 'f'); + values ('cz_CZ', 'Czech (CZ)', 'cs', 'CZ', 'Czech (Czech Republic)', 'Czech Republic', 'EE8ISO8859P2', 'ISO-8859-2', 'f', 'f'); insert into ad_locales (locale, label, language, country, nls_language, nls_territory, Index: openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d1-5.6.0d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d1-5.6.0d2.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d1-5.6.0d2.sql 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,6 @@ +-- Fix wrong data in ad_locales + +update ad_locales set language = 'ar' where language = 'AR'; +update ad_locales set language = 'ind' where locale = 'ind_ID'; +update ad_locales set language = 'cs' where locale = 'cz_CZ'; +update ad_locales set language = 'zh', country = 'HK' where locale = 'zh_HK'; Index: openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d2-5.6.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d2-5.6.0d3.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.6.0d2-5.6.0d3.sql 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,34 @@ +-- Create tables for languages and countries +-- +-- The tables are filled by after_install and after_upgrade apm callbacks +-- using the iso-3166-1-countries.txt and iso-639-2_utf-8.txt files + + +create table language_codes ( + iso_639_2 char(3) constraint language_codes_pk primary key, + iso_639_1 char(2), + label varchar(200) +); + +comment on table language_codes is 'Contains ISO-639-2 language codes and their corresponding ISO-639-1 when it exists.'; + +create table country_codes ( + label varchar(200), + country char(2) constraint country_codes_pk primary key +); + +comment on table country_codes is 'Contains ISO-3166 country codes'; + +-- update comment on ad_locales to be more accurate about how to +-- create new locales. +comment on table ad_locales is ' + An OpenACS locale is identified by a language and country. + Locale definitions in Oracle consist of a language, and optionally + territory and character set. (Languages are associated with default + territories and character sets when not defined). The formats + for numbers, currency, dates, etc. are determined by the territory. + language is the shortest ISO 639 code (lowercase). + country is two letter (uppercase) abbrev is ISO 3166 country code + mime_charset is IANA charset name + nls_charset is Oracle charset name +'; Index: openacs-4/packages/acs-lang/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/apm-callback-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/tcl/apm-callback-procs.tcl 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,140 @@ +# /packages/acs-lang/tcl/apm-callback-procs.tcl + +ad_library { + + APM callbacks library + + @creation-date August 2009 + @author Emmanuelle Raffenne (eraffenne@gmail.com) + @cvs-id $Id: apm-callback-procs.tcl,v 1.1 2010/01/08 17:39:58 emmar Exp $ + +} + +namespace eval lang {} +namespace eval lang::apm {} + +ad_proc -private lang::apm::after_install { +} { + Add ISO-639-2 codes to ad_locales +} { + lang::apm::add_language_codes + lang::apm::add_country_codes +} + +ad_proc -private lang::apm::after_upgrade { + {-from_version_name:required} + {-to_version_name:required} +} { + After upgrade callback for acs-lang +} { + apm_upgrade_logic \ + -from_version_name $from_version_name \ + -to_version_name $to_version_name \ + -spec { + 5.6.0d2 5.6.0d3 { + lang::apm::add_language_codes + lang::apm::add_country_codes + } + } +} + +## Helper procs + +ad_proc -private lang::apm::add_language_codes { +} { + Fills language_codes with ISO-639-2 codes + + The ISO-639-2 codes are in a text file located at + acs-lang/resources directory. The file was downloaded from + http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt + + Separator is "|" and the columns are: + +
    +
  • ISO 639-2 Bibliographic code (used if terminology one is empty)
  • +
  • ISO 639-2 Terminology code (used if exists)
  • +
  • ISO 639-1 code (2 digits)
  • +
  • Language name in english
  • +
  • Language name in french (ignored)
  • +
+ +} { + + set filename "[acs_root_dir]/packages/acs-lang/resources/iso-639-2_utf-8.txt" + + set channel [open $filename] + set data [read $channel] + close $channel + + set row_list [split $data "\n"] + foreach row $row_list { + + if { $row eq "" } { + continue + } + + set col_list [split $row "|"] + + # Set iso-639-2 code to terminology if exists, otherwise + # uses the bibliography one (see RFC 4646) + + set iso2b [lindex $col_list 0] + set iso2 [lindex $col_list 1] + set iso1 [lindex $col_list 2] + set label [lindex $col_list 3] + + if { $iso2 eq "" } { + set iso2 $iso2b + } + + db_dml insert_iso639 { + insert into language_codes + (iso_639_2, iso_639_1, label) + values + (:iso2, :iso1, :label) + } + } +} + +ad_proc -private lang::apm::add_country_codes { +} { + Fills country_codes with ISO-3166 codes + + The ISO-3166 codes are in a text file located at + acs-lang/resources directory. The file was downloaded from + http://www.iso.org/iso/list-en1-semic-3.txt + + Separator is ";" and the columns are: + +
    +
  • Country name in english
  • +
  • ISO 3166 code
  • +
+ +} { + + set filename "[acs_root_dir]/packages/acs-lang/resources/iso-3166-1-countries.txt" + + set channel [open $filename] + set data [read $channel] + close $channel + + set row_list [split $data "\n"] + foreach row $row_list { + + if { $row eq "" } { + continue + } + + set col_list [split $row ";"] + set label [lindex $col_list 0] + set country [lindex $col_list 1] + + db_dml insert_iso3166 { + insert into country_codes + (label, country) + values + (:label, :country) + } + } +} 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 -N -r1.45 -r1.46 --- openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 14 May 2007 20:30:22 -0000 1.45 +++ openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 8 Jan 2010 17:39:58 -0000 1.46 @@ -834,3 +834,75 @@ } return $edit_url } + +ad_proc -public lang::util::iso6392_from_language { + -language:required +} { + + Returns the ISO-639-2 code for a language. + + @param language Language, using ISO-639 code (2 or 3 chars) + @return The ISO-639-2 terminology code for the language + +} { + + set iso6392_code "" + set lang_len [string length $language] + if { $lang_len eq 2 } { + # input is iso-639-1 language code + + set iso6392_code [db_string get_iso2_code_from_iso1 {} -default ""] + + } elseif { $lang_len eq 3 } { + # input is iso-639-2 language code + # we check in the table in case the language code is wrong + + set iso6392_code [db_string get_iso2_code_from_iso2 {} -default ""] + } + + return $iso6392_code +} + +ad_proc -public lang::util::iso6392_from_locale { + -locale:required +} { + + Returns the ISO-639-2 code for a locale. + + @param locale Locale to get the language ISO-639-2 code for + @return The ISO-639-2 language code for the locale + +} { + + # Don't use string range since 3 digits languages may be used + set language [lindex [split $locale "_"] 0] + return [lang::util::iso6392_from_language -language $language] +} + +ad_proc -public lang::util::language_label { + -language:required +} { + + Returns the ISO-639 label for a language code. + + @param language Language, using ISO-639 code (2 or 3 chars) + @return The ISO-639 label for the language + +} { + + set lang_label "" + set lang_len [string length $language] + if { $lang_len eq 2 } { + # input is iso-639-1 language code + + set lang_label [db_string get_label_from_iso1 {} -default ""] + + } elseif { $lang_len eq 3 } { + # input is iso-639-2 language code + # we check in the table in case the language code is wrong + + set lang_label [db_string get_label_from_iso2 {} -default ""] + } + + return $lang_label +} 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 -N -r1.6 -r1.7 --- openacs-4/packages/acs-lang/tcl/lang-util-procs.xql 4 Oct 2005 02:38:55 -0000 1.6 +++ openacs-4/packages/acs-lang/tcl/lang-util-procs.xql 8 Jan 2010 17:39:58 -0000 1.7 @@ -41,4 +41,44 @@ + + + + select iso_639_2 + from language_codes + where iso_639_1 = :language + + + + + + + + select iso_639_2 + from language_codes + where iso_639_2 = :language + + + + + + + + select label + from language_codes + where iso_639_1 = :language + + + + + + + + select label + from language_codes + where iso_639_2 = :language + + + + 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 -N -r1.36 -r1.37 --- openacs-4/packages/acs-lang/tcl/locale-procs.tcl 21 Oct 2008 17:19:05 -0000 1.36 +++ openacs-4/packages/acs-lang/tcl/locale-procs.tcl 8 Jan 2010 17:39:58 -0000 1.37 @@ -127,13 +127,25 @@ ad_proc -public lang::system::language { {-package_id ""} {-site_wide:boolean} + {-iso6392: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. + @param iso6392 Set this if you want to force iso-639-2 code (3 digits) + + @return 3 chars language code if iso6392 is set, left part of locale otherwise + } { - return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1] + set locale [locale -package_id $package_id -site_wide=$site_wide_p] + set sys_lang [lindex [split $locale "_"] 0] + + if { $iso6392_p } { + return [lang::util::iso6392_from_language -language $sys_lang] + } else { + return $sys_lang + } } ad_proc -public lang::system::timezone {} { @@ -314,6 +326,7 @@ if { $locale eq "" } { set locale $system_locale } + return $locale } @@ -404,14 +417,27 @@ ad_proc -public lang::user::language { {-package_id ""} {-site_wide:boolean} + {-iso6392: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. + @param iso6392 Set this if you want to force iso-639-2 code (3 digits) + + @return 3 chars language code if iso6392 is set, left part of locale otherwise + } { - return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1] + + set locale [locale -package_id $package_id -site_wide=$site_wide_p] + set user_lang [lindex [split $locale "_"] 0] + + if { $iso6392_p } { + return [lang::util::iso6392_from_language -language $user_lang] + } else { + return $user_lang + } } @@ -613,13 +639,25 @@ ad_proc -public lang::conn::language { {-package_id ""} {-site_wide:boolean} + {-iso6392: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. + @param iso6392 Set this if you want to force the iso-639-2 code + + @return 3 chars language code if iso6392 is set, left part of locale otherwise } { - return [string range [locale -package_id $package_id -site_wide=$site_wide_p] 0 1] + + set locale [locale -package_id $package_id -site_wide=$site_wide_p] + set conn_lang [lindex [split $locale "_"] 0] + + if { $iso6392_p } { + return [lang::util::iso6392_from_language -language $conn_lang] + } else { + return $conn_lang + } } ad_proc -public lang::conn::charset { 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 -N -r1.7 -r1.8 --- openacs-4/packages/acs-lang/www/admin/locale-new.adp 14 Aug 2003 16:06:20 -0000 1.7 +++ openacs-4/packages/acs-lang/www/admin/locale-new.adp 8 Jan 2010 17:39:58 -0000 1.8 @@ -4,6 +4,6 @@ locale_creation.country

Please fill in the fields to create a new locale.

-

+ 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 -N -r1.4 -r1.5 --- openacs-4/packages/acs-lang/www/admin/locale-new.tcl 14 Aug 2003 16:06:20 -0000 1.4 +++ openacs-4/packages/acs-lang/www/admin/locale-new.tcl 8 Jan 2010 17:39:58 -0000 1.5 @@ -42,14 +42,20 @@ } } -element create locale_creation country -label "Country (2 digit ISO 3166 code)" \ - -datatype text -widget text -html { maxLength 2 size 2 } +set countries_list [db_list_of_lists select_countries {}] +element create locale_creation country \ + -label "Country" \ + -datatype text \ + -widget select \ + -options $countries_list -element create locale_creation language -label "Language (2 digit ISO 639-1 code, or 3 digit ISO 639-2 code)" \ - -datatype text -widget text -html { maxLength 3 size 3 } +set languages_list [db_list_of_lists select_languages {}] +element create locale_creation language \ + -label "Language" \ + -datatype text \ + -widget select \ + -options $languages_list -element create locale_creation label -label "Label" -datatype text - if { [info exists list_nls_language] } { element create locale_creation nls_language -label "NLS Language" \ @@ -74,7 +80,7 @@ } element create locale_creation mime_charset \ - -label "MIME Charset" -datatype text + -label "MIME Charset" -datatype text -value "UTF8" if { [form is_request locale_creation] } { @@ -96,6 +102,8 @@ # We are receiving a valid submission form get_values locale_creation + # label is built from language and country + set label "[lang::util::language_label -language $language] ($country)" append locale $language "_" $country db_transaction { @@ -105,19 +113,13 @@ 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'"] + set is_default_p [db_string select_default {}] 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, enabled_p) values ( - :locale, :language, :country, NULL, :label, :nls_language, - :nls_territory, :nls_charset, :mime_charset, :default_p, 'f')" - + db_dml insert_locale {} } forward "index?tab=locales" Index: openacs-4/packages/acs-lang/www/admin/locale-new.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/locale-new.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/www/admin/locale-new.xql 8 Jan 2010 17:39:58 -0000 1.1 @@ -0,0 +1,41 @@ + + + + + + + select label, country + from country_codes + order by label + + + + + + select label, coalesce(iso_639_1, iso_639_2) + from language_codes + order by label + + + + + + select count(*) + from ad_locales + where language = :language and default_p = 't' + + + + + + insert into ad_locales ( + locale, language, country, variant, label, nls_language, + nls_territory, nls_charset, mime_charset, default_p, enabled_p + ) values ( + :locale, :language, :country, NULL, :label, :nls_language, + :nls_territory, :nls_charset, :mime_charset, :default_p, 'f' + ) + + + +