summaryrefslogtreecommitdiff
path: root/lib/Locale/Codes
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-02-18 15:26:32 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-18 15:26:32 +0000
commit6b6e008c33e4c468fb6c1356921c16cdf5c73b26 (patch)
tree70024a466c10c41fd1f6b84ae5483517e6e0c919 /lib/Locale/Codes
parent0567e97b24a8aeac19fc0e3660c1bc2b954120ca (diff)
downloadperl-6b6e008c33e4c468fb6c1356921c16cdf5c73b26.tar.gz
Upgrade to Locale::Codes 2.00.
p4raw-id: //depot/perl@14746
Diffstat (limited to 'lib/Locale/Codes')
-rw-r--r--lib/Locale/Codes/ChangeLog88
-rw-r--r--lib/Locale/Codes/README47
-rw-r--r--lib/Locale/Codes/t/all.t221
-rw-r--r--lib/Locale/Codes/t/country.t24
-rw-r--r--lib/Locale/Codes/t/script.t106
5 files changed, 478 insertions, 8 deletions
diff --git a/lib/Locale/Codes/ChangeLog b/lib/Locale/Codes/ChangeLog
new file mode 100644
index 0000000000..d8a1837359
--- /dev/null
+++ b/lib/Locale/Codes/ChangeLog
@@ -0,0 +1,88 @@
+
+ ChangeLog for Locale-Codes Distribution
+
+2.00 2002-02-17 neilb
+
+ * Created Locale::Script which provides an interface to the
+ ISO codes for identification of scripts (writing scripts,
+ rather than perl style scripts). The codes are defined
+ by ISO 15924, which is currently in final draft.
+ Thanks to Jarkko for pointing out this new standard.
+ All three code sets are supported, and a test-suite added.
+
+ * Added support for country name variants to Locale::Country,
+ so that
+ country2code('USA')
+ country2code('United States')
+ country2code('United States of America')
+ will all return 'us'.
+ This had been in the LIMITATIONS section since the first version.
+ Patch from TJ Mather <tjmather@tjmather.com> with additional
+ variants from me. Added test-cases for these.
+
+ * Added VERSION to Locale::Constants. Thanks to Jarkko for
+ pointing that it was missing.
+
+ * Should really have bumped major version with previous release,
+ since there was a change to the API.
+
+1.06 2001-03-04 neilb
+
+ Added Locale::Constants, which defines three symbols
+ for identifying which codeset is being used:
+
+ LOCALE_CODE_ALPHA_2
+ LOCALE_CODE_ALPHA_3
+ LOCALE_CODE_NUMERIC
+
+ Updated Locale::Country to support all three code sets
+ defined by ISO 3166. This was requested by Keith Wall.
+ I haven't added multiple codeset support to the other
+ modules yet - I'll wait until someone asks for them.
+
+1.05 Feb 2001
+
+ Added Locale::Currency, contribution from Michael Hennecke.
+ Added testsuite for it (t/currency.t) and added testcases
+ to t/all.t for the all_* functions.
+
+1.04 Dec 2000
+
+ Fixed very minor typos from 1.03!
+
+1.03 Dec 2000
+
+ Updated Locale::Country:
+ - fixed spelling of a few countries
+ - added link to a relevant page from CIA world factbook
+
+ Updated Locale::Language:
+ - fixed typo in the documentation (ISO 939 should be 639)
+
+1.02 May 2000
+
+ Updated Locale::Country and Locale::Language to reflect changes
+ in the relevant ISO standards. These mainly reflect languages
+ which are new to the relevant standard, and changes in the
+ spelling of some country names.
+
+ Added official URLs for the standards to the SEE ALSO sections
+ of the doc for each module.
+
+ Thanks to Jarkko Hietaniemi for pointing me at the pages
+ with latest versions of ISO 3166 and 639.
+
+1.00 March 1998
+
+ Added Locale::Country::_alias_code() so that 'uk' can be added
+ as the code for "United Kingdom", if you want it.
+ This was prompted by Ed Jordan <ed@chronos.net>
+
+ Added a new testsuite for handling this case, and extended the
+ existing test-suite to include testing of the case where
+ 'uk' hasn't been defined as a valid code.
+
+0.003 May 1997
+
+ First public release to CPAN
+
diff --git a/lib/Locale/Codes/README b/lib/Locale/Codes/README
new file mode 100644
index 0000000000..20d174f354
--- /dev/null
+++ b/lib/Locale/Codes/README
@@ -0,0 +1,47 @@
+
+ Locale-Codes Distribution
+ v2.00
+
+This distribution contains four Perl modules which can be used to process
+ISO codes for identifying languages, countries, scripts,
+and currencies & funds.
+
+ Locale::Language
+ Two letter codes for language identification (ISO 639).
+ For example, 'en' is the code for 'English'.
+
+ Locale::Country
+ Codes for country identification (ISO 3166). This module
+ supports the three different code sets defined by the
+ standard: alpha-2, alpha-3, and numeric codes.
+ For example, 'bo' is the code for 'Bolivia'.
+
+ Locale::Currency
+ Three letter codes for currency and fund identification (ISO 4217).
+ For example, 'sek' is the code for 'Swedish Krona'.
+
+ Locale::Script
+ Codes for script identification (ISO 15924). This module supports
+ the three different code sets defined by the standard:
+ alpha-2, alpha-3, and numeric codes.
+
+To install these modules, you should just have to run the following:
+
+ % perl Makefile.PL
+ % make
+ % make test
+ % make install
+
+The modules are documented using pod. When you "make install", you
+will get three man-pages: Locale::Language, Locale::Country,
+Locale::Currency, Locale::Script.
+
+The first version of Locale::Currency was written by Michael Hennecke,
+with modifications for inclusion by me. Kudos to Michael.
+
+Please let me know if you experience any problems with these modules,
+or have any ideas for additions.
+
+
+Neil Bowers
+<neil@bowers.com>
diff --git a/lib/Locale/Codes/t/all.t b/lib/Locale/Codes/t/all.t
index ed93c5a856..6c751aacaa 100644
--- a/lib/Locale/Codes/t/all.t
+++ b/lib/Locale/Codes/t/all.t
@@ -4,6 +4,7 @@
# Locale::Country
# Locale::Language
# Locale::Currency
+# Locale::Script
#
# There are four tests. We get a list of all codes, convert to
# language/country/currency, # convert back to code,
@@ -19,8 +20,9 @@ BEGIN {
use Locale::Country;
use Locale::Language;
use Locale::Currency;
+use Locale::Script;
-print "1..12\n";
+print "1..20\n";
my $code;
my $language;
@@ -28,6 +30,7 @@ my $country;
my $ok;
my $reverse;
my $currency;
+my $script;
#-----------------------------------------------------------------------
@@ -364,3 +367,219 @@ foreach $currency (all_currency_names())
}
}
print ($ok ? "ok 12\n" : "not ok 12\n");
+
+#=======================================================================
+#
+# Locale::Script tests
+#
+#=======================================================================
+
+#-----------------------------------------------------------------------
+# Old API - without codeset specified, default to ALPHA_2
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $code (all_script_codes())
+{
+ $script = code2script($code);
+ if (!defined $script)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = script2code($script);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $code)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 13\n" : "not ok 13\n");
+
+#-----------------------------------------------------------------------
+# code to script, back to code, for ALPHA2
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $code (all_script_codes(LOCALE_CODE_ALPHA_2))
+{
+ $script = code2script($code, LOCALE_CODE_ALPHA_2);
+ if (!defined $script)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = script2code($script, LOCALE_CODE_ALPHA_2);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $code)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 14\n" : "not ok 14\n");
+
+#-----------------------------------------------------------------------
+# code to script, back to code, for ALPHA3
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $code (all_script_codes(LOCALE_CODE_ALPHA_3))
+{
+ $script = code2script($code, LOCALE_CODE_ALPHA_3);
+ if (!defined $script)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = script2code($script, LOCALE_CODE_ALPHA_3);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $code)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 15\n" : "not ok 15\n");
+
+#-----------------------------------------------------------------------
+# code to script, back to code, for NUMERIC
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $code (all_script_codes(LOCALE_CODE_NUMERIC))
+{
+ $script = code2script($code, LOCALE_CODE_NUMERIC);
+ if (!defined $script)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = script2code($script, LOCALE_CODE_NUMERIC);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $code)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 16\n" : "not ok 16\n");
+
+
+#-----------------------------------------------------------------------
+# Old API - script to code, back to script, using default of ALPHA_2
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $script (all_script_names())
+{
+ $code = script2code($script);
+ if (!defined $code)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = code2script($code);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $script)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 17\n" : "not ok 17\n");
+
+#-----------------------------------------------------------------------
+# script to code, back to script, using LOCALE_CODE_ALPHA_2
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $script (all_script_names())
+{
+ $code = script2code($script, LOCALE_CODE_ALPHA_2);
+ if (!defined $code)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = code2script($code, LOCALE_CODE_ALPHA_2);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $script)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 18\n" : "not ok 18\n");
+
+#-----------------------------------------------------------------------
+# script to code, back to script, using LOCALE_CODE_ALPHA_3
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $script (all_script_names())
+{
+ $code = script2code($script, LOCALE_CODE_ALPHA_3);
+ if (!defined $code)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = code2script($code, LOCALE_CODE_ALPHA_3);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $script)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 19\n" : "not ok 19\n");
+
+#-----------------------------------------------------------------------
+# script to code, back to script, using LOCALE_CODE_NUMERIC
+#-----------------------------------------------------------------------
+$ok = 1;
+foreach $script (all_script_names())
+{
+ $code = script2code($script, LOCALE_CODE_NUMERIC);
+ if (!defined $code)
+ {
+ $ok = 0;
+ last;
+ }
+ $reverse = code2script($code, LOCALE_CODE_NUMERIC);
+ if (!defined $reverse)
+ {
+ $ok = 0;
+ last;
+ }
+ if ($reverse ne $script)
+ {
+ $ok = 0;
+ last;
+ }
+}
+print ($ok ? "ok 20\n" : "not ok 20\n");
+
diff --git a/lib/Locale/Codes/t/country.t b/lib/Locale/Codes/t/country.t
index 4234d1e6a7..0953da1e8a 100644
--- a/lib/Locale/Codes/t/country.t
+++ b/lib/Locale/Codes/t/country.t
@@ -60,13 +60,23 @@ use Locale::Country;
['!defined country2code("Banana")', 0], # illegal country name
#---- some successful examples -----------------------------------------
- ['country2code("japan") eq "jp"', 0],
- ['country2code("japan") ne "ja"', 0],
- ['country2code("Japan") eq "jp"', 0],
- ['country2code("United States") eq "us"', 0],
- ['country2code("United Kingdom") eq "gb"', 0],
- ['country2code("Andorra") eq "ad"', 0], # first in DATA segment
- ['country2code("Zimbabwe") eq "zw"', 0], # last in DATA segment
+ ['country2code("japan") eq "jp"', 0],
+ ['country2code("japan") ne "ja"', 0],
+ ['country2code("Japan") eq "jp"', 0],
+ ['country2code("United States") eq "us"', 0],
+ ['country2code("United Kingdom") eq "gb"', 0],
+ ['country2code("Andorra") eq "ad"', 0], # first in DATA
+ ['country2code("Zimbabwe") eq "zw"', 0], # last in DATA
+ ['country2code("Iran") eq "ir"', 0], # alias
+ ['country2code("North Korea") eq "kp"', 0], # alias
+ ['country2code("South Korea") eq "kr"', 0], # alias
+ ['country2code("Libya") eq "ly"', 0], # alias
+ ['country2code("Syria") eq "sy"', 0], # alias
+ ['country2code("Svalbard") eq "sj"', 0], # alias
+ ['country2code("Jan Mayen") eq "sj"', 0], # alias
+ ['country2code("USA") eq "us"', 0], # alias
+ ['country2code("United States of America") eq "us"', 0], # alias
+ ['country2code("Great Britain") eq "gb"', 0], # alias
#================================================
# TESTS FOR country_code2code
diff --git a/lib/Locale/Codes/t/script.t b/lib/Locale/Codes/t/script.t
new file mode 100644
index 0000000000..989b778f82
--- /dev/null
+++ b/lib/Locale/Codes/t/script.t
@@ -0,0 +1,106 @@
+#!./perl
+#
+# script.t - tests for Locale::Script
+#
+
+use Locale::Script;
+
+#-----------------------------------------------------------------------
+# This is an array of tests specs. Each spec is [TEST, OK_TO_DIE]
+# Each TEST is eval'd as an expression.
+# If it evaluates to FALSE, then "not ok N" is printed for the test,
+# otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked.
+# If it is true (1), the test is treated as passing, otherwise it failed.
+#-----------------------------------------------------------------------
+@TESTS =
+(
+ #================================================
+ # TESTS FOR code2script
+ #================================================
+
+ #---- selection of examples which should all result in undef -----------
+ ['!defined code2script()', 0], # no argument
+ ['!defined code2script(undef)', 0], # undef argument
+ ['!defined code2script("aa")', 0], # illegal code
+ ['!defined code2script("aa", LOCALE_CODE_ALPHA_2)', 0], # illegal code
+ ['!defined code2script("aa", LOCALE_CODE_ALPHA_3)', 0], # illegal code
+ ['!defined code2script("aa", LOCALE_CODE_NUMERIC)', 0], # illegal code
+
+ #---- some successful examples -----------------------------------------
+ ['code2script("BO") eq "Tibetan"', 0],
+ ['code2script("Bo") eq "Tibetan"', 0],
+ ['code2script("bo") eq "Tibetan"', 0],
+ ['code2script("bo", LOCALE_CODE_ALPHA_2) eq "Tibetan"', 0],
+ ['code2script("bod", LOCALE_CODE_ALPHA_3) eq "Tibetan"', 0],
+ ['code2script("330", LOCALE_CODE_NUMERIC) eq "Tibetan"', 0],
+
+ ['code2script("yi", LOCALE_CODE_ALPHA_2) eq "Yi"', 0], # last in DATA
+ ['code2script("Yii", LOCALE_CODE_ALPHA_3) eq "Yi"', 0],
+ ['code2script("460", LOCALE_CODE_NUMERIC) eq "Yi"', 0],
+
+ ['code2script("am") eq "Aramaic"', 0], # first in DATA segment
+
+
+ #================================================
+ # TESTS FOR script2code
+ #================================================
+
+ #---- selection of examples which should all result in undef -----------
+ ['!defined code2script("BO", LOCALE_CODE_ALPHA_3)', 0],
+ ['!defined code2script("BO", LOCALE_CODE_NUMERIC)', 0],
+ ['!defined script2code()', 0], # no argument
+ ['!defined script2code(undef)', 0], # undef argument
+ ['!defined script2code("Banana")', 0], # illegal script name
+
+ #---- some successful examples -----------------------------------------
+ ['script2code("meroitic") eq "me"', 0],
+ ['script2code("burmese") eq "my"', 0],
+ ['script2code("Pahlavi") eq "ph"', 0],
+ ['script2code("Vai", LOCALE_CODE_ALPHA_3) eq "vai"', 0],
+ ['script2code("Tamil", LOCALE_CODE_NUMERIC) eq "346"', 0],
+ ['script2code("Latin") eq "la"', 0],
+ ['script2code("Latin", LOCALE_CODE_ALPHA_3) eq "lat"', 0],
+
+ #================================================
+ # TESTS FOR script_code2code
+ #================================================
+
+ #---- selection of examples which should all result in undef -----------
+ ['!defined script_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
+ ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
+ ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
+ ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2)', 1],
+ ['!defined script_code2code()', 1], # no argument
+ ['!defined script_code2code(undef)', 1], # undef argument
+
+ #---- some successful examples -----------------------------------------
+ ['script_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bod"', 0],
+ ['script_code2code("bod", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
+ ['script_code2code("Phx", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "ph"', 0],
+ ['script_code2code("295", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "pqd"', 0],
+ ['script_code2code(170, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "tna"', 0],
+ ['script_code2code("rr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "620"', 0],
+
+);
+
+print "1..", int(@TESTS), "\n";
+
+$testid = 1;
+foreach $test (@TESTS)
+{
+ eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
+ if ($@)
+ {
+ if (!$test->[1])
+ {
+ print "not ok $testid\n";
+ }
+ else
+ {
+ print "ok $testid\n";
+ }
+ }
+ ++$testid;
+}
+
+exit 0;