(better late than never
)
My system: SuSE 10.0, kernel 2.6.13, KDE 3.4, bash 3.00, locales ru_RU.UTF-8, ru_RU.koi8r, ru_RU.cp1251
Assume you are in ru_RU.UTF-8 and want to verify either ru_RU.koi8r or ru_RU.cp1251 installed
Via
bash. Create executable test-locale.sh
PHP Code:
#!/bin/bash
if [ "$#" != 1 ] ; then echo "Usage: $0 charmap"; exit; fi
if ! locale -a | fgrep -q $1; then echo "Unknown charmap"; exit 1; fi
if ! rpm -qa | fgrep -q recode; then echo "recode utility not found"; exit 2; fi
CHR1=`echo А | recode ..$1/ 2> /dev/null` # 1st national letter in upper case
CHR2=`echo Я | recode ..$1/ 2> /dev/null` # last national letter in upper case
CHR3=`echo Ё | recode ..$1/ 2> /dev/null` # any national letter in upper case that is inside range [CHR1-CHR2] lexically, but out of in ASCII (C or POSIX locale)
DATE=`echo Января | recode ..$1/ 2> /dev/null` # "January" word's national equivalent cased accordingly
LANG=ru_RU.$1
if [[ "$CHR3" == [[:upper:]] ]] ; then echo "LC_CTYPE is OK" ; else echo "LC_CTYPE is broken" ; fi
if [[ "$CHR3" == [${CHR1}-${CHR2}] ]] ; then echo "LC_COLLATE is OK" ; else echo "LC_COLLATE is broken" ; fi
if [ "$DATE" == "`date -d \"Jan 1 2000\" +\"%B\"`" ] ; then echo "LC_TIME is OK" ; else echo "LC_TIME is broken" ; fi
Try:
./test-locale.sh cp1251
./test-locale.sh koi8r
./test-locale.sh utf8
Via
Perl Create executable test-locale.pl
PHP Code:
#!/usr/bin/perl
# Usage: ./test-locale.pl codepage
use locale;
use POSIX qw (setlocale LC_ALL);
use POSIX qw (strftime);
use Unicode::Map8;
use Unicode::String qw (utf8);
if (0 != $ARGV[0]) {print "Usage: test-locale.pl codepage\n"; exit;}
$codepage=$ARGV[0];
my $str = Unicode::Map8 -> new ($codepage);
$uc_ch = $str->to8 (utf8 ("П") -> utf16); // any national letter in upper case
$lc_ch = $str->to8 (utf8 ("п") -> utf16); // the same letter in lower case
$month = $str->to8 (utf8 ("Января") -> utf16); // "January" word's national equivalent cased accordingly
print setlocale (LC_ALL, "ru_RU." . $codepage) . "\n";
if ($uc_ch ne $lc_ch && $uc_ch == uc ($lc_ch)) {print "LC_CTYPE is OK\n";} else {print "LC_CTYPE is broken\n";}
if ($month == strftime ("%B", 0, 0, 0, 1, 0, 0)) {print "LC_TIME is OK\n";} else {print "LC_TIME is broken\n";}
Try:
./test-locale.pl koi8-r
./test-locale.pl koi8r
./test-locale.pl cp1251
Via
PHP. Create executable test-locale.php
PHP Code:
#!/usr/bin/php
<?
if (2 != $argc) {exit ("Usage: test-locale.php codepage\n");}
$codepage=$argv[1];
$uc_ch = mb_convert_encoding ("П", $codepage, "UTF-8"); // any national letter in upper case
$lc_ch = mb_convert_encoding ("п", $codepage, "UTF-8"); // the same letter in lower case
$month = mb_convert_encoding ("Января", $codepage, "UTF-8"); // "January" word's national equivalent cased accordingly
print setlocale (LC_ALL, "ru_RU." . $codepage) . "\n";
if ($uc_ch !== $lc_ch && $uc_ch === strtoupper ($lc_ch)) {print "LC_CTYPE is OK\n";} else {print "LC_CTYPE is broken\n";}
if ($month === strftime ("%B", strtotime("1 January 2000"))) {print "LC_TIME is OK\n";} else {print "LC_TIME is broken\n";}
?>
Note: to test UTF8 check "mbstring.func_overload" php.ini option
Try:
./test-locale.php koi8-r
./test-locale.php koi8r
./test-locale.php cp1251
./test-locale.php utf8