[PEAR-BUG] Req #10371 [Opn->WFx]: Enhance fallback for I18Nv2::setLocale()

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=10371&edit=1

 ID:               10371
 Updated by:       [email protected]
 Reported By:      derernst at gmx dot ch
 Summary:          Enhance fallback for I18Nv2::setLocale()
-Status:           Open
+Status:           Wont fix
 Type:             Feature/Change Request
 Package:          I18Nv2
 Package Version:  0.11.4
 PHP Version:      5.1.6
 Roadmap Versions: 
 New Comment:

-Status: Open
+Status: Wont fix
Hello and thank you for the feedback. Unfortunately this package is no
longer 
maintained excepting bugs and security issues, but the PECL intl package
covers it all.


Previous Comments:
------------------------------------------------------------------------

[2007-07-20 07:28:52] derernst

Trying to make the app work on Windows; I needed to add a windows
fallback to the alternatives array:

$windows = &I18Nv2::getStaticProperty('windows');
if (isset($windows[$loc])) {
  $alternatives[] = $windows[$loc];
}

------------------------------------------------------------------------

[2007-03-14 10:22:57] derernst

Sorry there is a mistake in my code: the second occurrence of 
$lng.strtoupper($enc)
should actually be:
$lng.strtolower($enc)

------------------------------------------------------------------------

[2007-03-14 10:11:37] derernst

Description:
------------
I encountered that on a system locale strings 'en_GB' and 'en_GB.utf-8'
can fail, while 'en_GB.UTF-8' works. This made me think of adding some
fallback functionality to I18Nv2::setLocale() that checks alternative
locale strings with encoding in uppercase and lowercase, with and
without country code. I added the below code after line 72 of
I18Nv2.php.

I think that enhancing locale handling towards auto-detection and better
fallback can help make I18Nv2 a very powerful tool for applications that
are intended to work cross-platform and in shared hosting environments -
in all cases where the system configuration and application languages
are not known at coding time. (See also requests #10369 and #7885.)

Test script:
---------------
if (!$syslocale) {
    // extract locale and encoding info
    $split = explode('.', $setlocale, 2);
    $loc = $split[0];
    $enc = isset($split[1]) ? '.'.$split[1] : '';
    // extract language info without country
    $split = explode('_', $loc, 2);
    $lng = $split[0];
    // compose possible alternative locales
    $alternatives = array(
        $loc.strtoupper($enc),
        $loc.strtolower($enc),
        $lng.strtoupper($enc),
        $lng.strtoupper($enc),
        $loc,
        $lng
    );
    // try to set locales
    if (version_compare(phpversion(), '4.3.0', '>=')) {
        $syslocale = setlocale($cat, $alternatives);
    } 
    else {
        foreach ($alternatives as $alternative) {
            if ($syslocale = setlocale($cat, $alternative)) {
                break;
            }
        }
    }
}

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=10371&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.