<?php
/**
* @package        PK_Library
* @subpackage    Utilities
* @copyright    None
* @author        Paul Kemper <pkemper@novell.com>
* @version        1.00.0005 2007-11-27
*
* 1.00.0005        Using wshShell to get to HKEY_USERS\.DEFAULT locale settings and adding currency support
*
* NOTES:
* This is not an idea solution. Reading the HKEY_USERS\.DEFAULT items will return
* the locale that is selected at Windows install time.
* Changing the regional settings will not have any effect, nor will setlocale() have
* any effects on the results.
*/

/**
* Creating item indices if they do not exist
*/

// LC_TIME category constants
if ( !defined('ABDAY_1') ) define( 'ABDAY_1', 0x20000 );
if ( !defined('ABDAY_2') ) define( 'ABDAY_2', 0x20001 );
if ( !defined('ABDAY_3') ) define( 'ABDAY_3', 0x20002 );
if ( !defined('ABDAY_4') ) define( 'ABDAY_4', 0x20003 );
if ( !defined('ABDAY_5') ) define( 'ABDAY_5', 0x20004 );
if ( !defined('ABDAY_6') ) define( 'ABDAY_6', 0x20005 );
if ( !defined('ABDAY_7') ) define( 'ABDAY_7', 0x20006 );

if ( !defined('DAY_1') ) define( 'DAY_1', 0x20007 );
if ( !defined('DAY_2') ) define( 'DAY_2', 0x20008 );
if ( !defined('DAY_3') ) define( 'DAY_3', 0x20009 );
if ( !defined('DAY_4') ) define( 'DAY_4', 0x2000a );
if ( !defined('DAY_5') ) define( 'DAY_5', 0x2000b );
if ( !defined('DAY_6') ) define( 'DAY_6', 0x2000c );
if ( !defined('DAY_7') ) define( 'DAY_7', 0x2000d );

if ( !defined('ABMON_1') ) define( 'ABMON_1', 0x2000e );
if ( !defined('ABMON_2') ) define( 'ABMON_2', 0x2000f );
if ( !defined('ABMON_3') ) define( 'ABMON_3', 0x20010 );
if ( !defined('ABMON_4') ) define( 'ABMON_4', 0x20011 );
if ( !defined('ABMON_5') ) define( 'ABMON_5', 0x20012 );
if ( !defined('ABMON_6') ) define( 'ABMON_6', 0x20013 );
if ( !defined('ABMON_7') ) define( 'ABMON_7', 0x20014 );
if ( !defined('ABMON_8') ) define( 'ABMON_8', 0x20015 );
if ( !defined('ABMON_9') ) define( 'ABMON_9', 0x20016 );
if ( !defined('ABMON_10') ) define( 'ABMON_10', 0x20017 );
if ( !defined('ABMON_11') ) define( 'ABMON_11', 0x20018 );
if ( !defined('ABMON_12') ) define( 'ABMON_12', 0x20019 );

if ( !defined('MON_1') ) define( 'MON_1', 0x2001a );
if ( !defined('MON_2') ) define( 'MON_2', 0x2001b );
if ( !defined('MON_3') ) define( 'MON_3', 0x2001c );
if ( !defined('MON_4') ) define( 'MON_4', 0x2001d );
if ( !defined('MON_5') ) define( 'MON_5', 0x2001e );
if ( !defined('MON_6') ) define( 'MON_6', 0x2001f );
if ( !defined('MON_7') ) define( 'MON_7', 0x20020 );
if ( !defined('MON_8') ) define( 'MON_8', 0x20021 );
if ( !defined('MON_9') ) define( 'MON_9', 0x20022 );
if ( !defined('MON_10') ) define( 'MON_10', 0x20023 );
if ( !defined('MON_11') ) define( 'MON_11', 0x20024 );
if ( !defined('MON_12') ) define( 'MON_12', 0x20025 );

if ( !defined('AM_STR') ) define( 'AM_STR', 0x20026 );
if ( !defined('PM_STR') ) define( 'PM_STR', 0x20027 );

if ( !defined('D_T_FMT') ) define( 'D_T_FMT', 0x20028 );
if ( !defined('D_FMT') ) define( 'D_FMT', 0x20029 );
if ( !defined('T_FMT') ) define( 'T_FMT', 0x2002a );
if ( !defined('T_FMT_AMPM') ) define( 'T_FMT_AMPM', 0x2002b );

// NOTE: NOT SUPPORTED, BECAUSE I DO NOT UNDERSTAND WHAT THESE MEAN
if ( !defined('ERA') ) define( 'ERA', 0x2002c );
if ( !defined('ERA_YEAR') ) define( 'ERA_YEAR', 0x2002d );
if ( !defined('ERA_D_T_FMT') ) define( 'ERA_D_T_FMT', 0x20030 );
if ( !defined('ERA_D_FMT') ) define( 'ERA_D_FMT', 0x2002e );
if ( !defined('ERA_T_FMT') ) define( 'ERA_T_FMT', 0x20031 );

// LC_MONETARY category constants
if ( !defined('INT_CURR_SYMBOL') ) define( 'INT_CURR_SYMBOL', 0x40000 );
if ( !defined('CURRENCY_SYMBOL') ) define( 'CURRENCY_SYMBOL', 0x40001 );
if ( !defined('CRNCYSTR') ) define( 'CRNCYSTR', 0x40001 );
if ( !defined('MON_DECIMAL_POINT') ) define( 'MON_DECIMAL_POINT', 0x40002 );
if ( !defined('MON_THOUSANDS_SEP') ) define( 'MON_THOUSANDS_SEP', 0x40003 );
if ( !defined('MON_GROUPING') ) define( 'MON_GROUPING', 0x40004 );
if ( !defined('POSITIVE_SIGN') ) define( 'POSITIVE_SIGN', 0x40005 );
if ( !defined('NEGATIVE_SIGN') ) define( 'NEGATIVE_SIGN', 0x40006 );
if ( !defined('INT_FRAC_DIGITS') ) define( 'INT_FRAC_DIGITS', 0x40007 );
if ( !defined('FRAC_DIGITS') ) define( 'FRAC_DIGITS', 0x40008 );
// The following six items are are not supported by teh Windows registry
if ( !defined('P_CS_PRECEDES') ) define( 'P_CS_PRECEDES', 0x40009 );
if ( !defined('P_SEP_BY_SPACE') ) define( 'P_SEP_BY_SPACE', 0x4000a );
if ( !defined('N_CS_PRECEDES') ) define( 'N_CS_PRECEDES', 0x4000b );
if ( !defined('N_SEP_BY_SPACE') ) define( 'N_SEP_BY_SPACE', 0x4000c );
if ( !defined('P_SIGN_POSN') ) define( 'P_SIGN_POSN', 0x4000d );
if ( !defined('N_SIGN_POSN') ) define( 'N_SIGN_POSN', 0x4000e );

// LC_NUMERIC category constants
if ( !defined('DECIMAL_POINT') ) define( 'DECIMAL_POINT', 0x10000 );
if ( !defined('RADIXCHAR') ) define( 'RADIXCHAR', 0x10000 );
if ( !defined('THOUSANDS_SEP') ) define( 'THOUSANDS_SEP', 0x10001 );
if ( !defined('THOUSEP') ) define( 'THOUSEP', 0x10001 );
if ( !defined('GROUPING') ) define( 'GROUPING', 0x10002 );

// NOTE: THESE ITEMS ARE NOT SUPPORTED BECAUSE I DO NOT KNOW HOW TO GET THEM
// LC_MESSAGES category constants
if ( !defined('YESEXPR') ) define( 'YESEXPR', 0x50000 );
if ( !defined('NOEXPR') ) define( 'NOEXPR', 0x50001 );
if ( !defined('YESSTR') ) define( 'YESSTR', 0x50002 );
if ( !defined('NOSTR') ) define( 'NOSTR', 0x50003 );

// LC_CTYPE category constants
if ( !defined('CODESET') ) define( 'CODESET', 0x0000e );

/**
* Static array holding requested nl_langinfo elements
*
* The array starts out empty and the elements will be filled once they
* are requested for the first time.
*
* @var        string[integer]
* @access    public
*/
static $_nl_langinfo_strings = array();

/**
* Static array holding date elements in current locale
*
* The array starts out empty and the elements will be filled once they
* are requested for the first time.
*
* The key into this array is the date format specifier from strftime()<br/>
* The value is the value that strftime() returns in the current locale
*
* @var        string[string]
* @access    public
*/
static $_nl_langinfo_date_strings = array();

/**
* Static array holding internaltional and local currency symbols
*
* The array starts out empty and the elements will be filled once they
* are requested for the first time.
*
* The key into this array is the lower case international currency symbol.<br/>
* The value (if available) is the local currency symbol (UTF-8 encoded)!!
*
* @var        string[string]
* @access    public
*/
static $_nl_langinfo_currencies = array();

/**
* Implement a basic nl_langinfo() function (for Windows users)
*
* This function is an implementation of the 'standard'
* PHP nl_langinfo() function and might be needed on some
* platforms (i.e. Windows as the manual for the
* {@link http://nl2.php.net/manual/en/function.nl_langinfo.php nl_langinfo}
* function explains).
*
* Return values depend on the current locale the script is operating under.
*
* The following digressions from nl_langinfo() in the PHP manual are noteworthy:
* - T_FMT does nor return '%r' as the format string, but the fully expanded strftime() format string
* - All ERA_XXXX constants return an empty string
* - The LC_MESSAGES category constants return empty strings
*
* @param        integer                Item to return
* @return        mixed                Locale setting for requested item
*/
function nl_langinfo( $item )
{
    global $_nl_langinfo_strings, $_nl_langinfo_currencies;
    
    // Is the element present already?
    if ( isset($_nl_langinfo_strings[$item]) )
    {
        return $_nl_langinfo_strings[$item];
    }
    
    // Convert Unicode code points to UTF-8
    if ( !function_exists('_utf8') )
    {
        function _utf8($cp)
        {
            if ( $cp >= 0x10000 ) // 17 or more bits
            {
                return chr(0xf0+$cp>>18) . chr(0x80+(($cp>>12)&0x3f)) . chr(0x80+(($cp>>6)&0x3f)) . chr(0x80+($cp&0x3f));
            }
            elseif ( $cp >= 0x400 ) // 11 or more bits
            {
                return chr(0xe0+(($cp>>12)&0x3f)) . chr(0x80+(($cp>>6)&0x3f)) . chr(0x80+($cp&0x3f));
            }
            elseif ( $cp >= 0x80 ) // 7 or more bits
            {
                return chr(0xc0+(($cp>>6)&0x3f)) . chr(0x80+($cp&0x3f));
            }
            else
            {
                return chr($cp);
            }
        }
    }
    
    // Set up the currency table
    $_nl_langinfo_currencies = array(
        'ALL'  => _utf8(0x4c) . _utf8(0x65) . _utf8(0x6b), // Albania, Leke 
        'USD'  => _utf8(0x24), // America (United States of America), Dollars 
        'AFN'  => _utf8(0x60b), // Afghanistan, Afghanis 
        'ARS'  => _utf8(0x24), // Argentina, Pesos 
        'AWG'  => _utf8(0x192), // Aruba, Guilders (also called Florins) 
        'AUD'  => _utf8(0x24), // Australia, Dollars 
        'AZN'  => _utf8(0x43c) . _utf8(0x430) . _utf8(0x43d), // Azerbaijan, New Manats 
        'BSD'  => _utf8(0x24), // Bahamas, Dollars 
        'BBD'  => _utf8(0x24), // Barbados, Dollars 
        'BYR'  => _utf8(0x70) . _utf8(0x2e), // Belarus, Rubles 
        'BEF'  => _utf8(0x20a3), // Belgium, Francs (obsolete) 
        'BZD'  => _utf8(0x42) . _utf8(0x5a) . _utf8(0x24), // Belize, Dollars 
        'BMD'  => _utf8(0x24), // Bermuda, Dollars 
        'BOB'  => _utf8(0x24) . _utf8(0x62), // Bolivia, Bolivianos 
        'BAM'  => _utf8(0x4b) . _utf8(0x4d), // Bosnia and Herzegovina, Convertible Marka 
        'BWP'  => _utf8(0x50), // Botswana, Pulas 
        'BGN'  => _utf8(0x43b) . _utf8(0x432), // Bulgaria, Leva 
        'BRL'  => _utf8(0x52) . _utf8(0x24), // Brazil, Reais 
        'BRC'  => _utf8(0x20a2), // Brazil, Cruzeiros (obsolete) 
        'GBP'  => _utf8(0xa3), // Britain (United Kingdom), Pounds 
        'BND'  => _utf8(0x24), // Brunei Darussalam, Dollars 
        'KHR'  => _utf8(0x17db), // Cambodia, Riels 
        'CAD'  => _utf8(0x24), // Canada, Dollars 
        'KYD'  => _utf8(0x24), // Cayman Islands, Dollars 
        'CLP'  => _utf8(0x24), // Chile, Pesos 
        'CNY'  => _utf8(0x5143), // China, Yuan Renminbi 
        'COP'  => _utf8(0x24), // Colombia, Pesos 
        'CRC'  => _utf8(0x20a1), // Costa Rica, Col?n 
        'HRK'  => _utf8(0x6b) . _utf8(0x6e), // Croatia, Kuna 
        'CUP'  => _utf8(0x20b1), // Cuba, Pesos 
        'CYP'  => _utf8(0xa3), // Cyprus, Pounds 
        'CZK'  => _utf8(0x4b) . _utf8(0x10d), // Czech Republic, Koruny 
        'DKK'  => _utf8(0x6b) . _utf8(0x72), // Denmark, Kroner 
        'DOP'  => _utf8(0x52) . _utf8(0x44) . _utf8(0x24), // Dominican Republic, Pesos 
        'XCD'  => _utf8(0x24), // East Caribbean, Dollars 
        'EGP'  => _utf8(0xa3), // Egypt, Pounds 
        'SVC'  => _utf8(0x24), // El Salvador, Colones 
        'GBP'  => _utf8(0xa3), // England (United Kingdom), Pounds 
        'EEK'  => _utf8(0x6b) . _utf8(0x72), // Estonia, Krooni 
        'EUR'  => _utf8(0x20ac), // Euro 
        'XEU'  => _utf8(0x20a0), // European Currency Unit (obsolete) 
        'FKP'  => _utf8(0xa3), // Falkland Islands, Pounds 
        'FJD'  => _utf8(0x24), // Fiji, Dollars 
        'FRF'  => _utf8(0x20a3), // France, Francs (obsolete) 
        'GHC'  => _utf8(0xa2), // Ghana, Cedis 
        'GIP'  => _utf8(0xa3), // Gibraltar, Pounds 
        'GRD'  => _utf8(0x20af), // Greece, Drachmae (obsolete) 
        'GTQ'  => _utf8(0x51), // Guatemala, Quetzales 
        'GGP'  => _utf8(0xa3), // Guernsey, Pounds 
        'GYD'  => _utf8(0x24), // Guyana, Dollars 
        'NLG'  => _utf8(0x192), // Holland (Netherlands), Guilders (also called Florins) (obsolete) 
        'HNL'  => _utf8(0x4c), // Honduras, Lempiras 
        'HKD'  => _utf8(0x48) . _utf8(0x4b) . _utf8(0x24), // Hong Kong, Dollars (General written use) 
        'HKD'  => _utf8(0x5713), // Hong Kong, Dollars (BOC notes) 
        'HKD'  => _utf8(0x5713), // Hong Kong, Dollars (SCB notes) 
        'HKD'  => _utf8(0x5143), // Hong Kong, Dollars (HSBC notes) 
        'HUF'  => _utf8(0x46) . _utf8(0x74), // Hungary, Forint 
        'ISK'  => _utf8(0x6b) . _utf8(0x72), // Iceland, Kronur 
        'INR'  => _utf8(0x20a8), // India, Rupees (Rs or Rs. are commonly used instead of the symbol) 
        'IDR'  => _utf8(0x52) . _utf8(0x70), // Indonesia, Rupiahs 
        'IRR'  => _utf8(0xfdfc), // Iran, Rials 
        'IEP'  => _utf8(0xa3), // Ireland, Punt (obsolete) 
        'IMP'  => _utf8(0xa3), // Isle of Man, Pounds 
        'ILS'  => _utf8(0x20aa), // Israel, New Shekels 
        'ITL'  => _utf8(0x20a4), // Italy, Lire (obsolete) 
        'JMD'  => _utf8(0x4a) . _utf8(0x24), // Jamaica, Dollars 
        'JPY'  => _utf8(0xa5), // Japan, Yen 
        'JEP'  => _utf8(0xa3), // Jersey, Pounds 
        'KZT'  => _utf8(0x43b) . _utf8(0x432), // Kazakhstan, Tenge 
        'KPW'  => _utf8(0x20a9), // Korea (North), Won 
        'KRW'  => _utf8(0x20a9), // Korea (South), Won 
        'KGS'  => _utf8(0x43b) . _utf8(0x432), // Kyrgyzstan, Soms 
        'LAK'  => _utf8(0x20ad), // Laos, Kips 
        'LVL'  => _utf8(0x4c) . _utf8(0x73), // Latvia, Lati 
        'LBP'  => _utf8(0xa3), // Lebanon, Pounds 
        'LRD'  => _utf8(0x24), // Liberia, Dollars 
        'CHF'  => _utf8(0x43) . _utf8(0x48) . _utf8(0x46), // Liechtenstein, Switzerland Francs 
        'LTL'  => _utf8(0x4c) . _utf8(0x74), // Lithuania, Litai 
        'LUF'  => _utf8(0x20a3), // Luxembourg, Francs (obsolete) 
        'MKD'  => _utf8(0x434) . _utf8(0x435) . _utf8(0x43d), // Macedonia, Denars 
        'MYR'  => _utf8(0x52) . _utf8(0x4d), // Malaysia, Ringgits 
        'MTL'  => _utf8(0x4c) . _utf8(0x6d), // Malta, Liri 
        'MUR'  => _utf8(0x20a8), // Mauritius, Rupees 
        'MXN'  => _utf8(0x24), // Mexico, Pesos 
        'MNT'  => _utf8(0x20ae), // Mongolia, Tugriks 
        'MZN'  => _utf8(0x4d) . _utf8(0x54), // Mozambique, Meticais 
        'NAD'  => _utf8(0x24), // Namibia, Dollars 
        'NPR'  => _utf8(0x20a8), // Nepal, Rupees 
        'ANG'  => _utf8(0x192), // Netherlands Antilles, Guilders (also called Florins) 
        'NLG'  => _utf8(0x192), // Netherlands, Guilders (obsolete) 
        'NZD'  => _utf8(0x24), // New Zealand, Dollars 
        'NIO'  => _utf8(0x43) . _utf8(0x24), // Nicaragua, Cordobas 
        'NGN'  => _utf8(0x20a6), // Nigeria, Nairas 
        'KPW'  => _utf8(0x20a9), // North Korea, Won 
        'NOK'  => _utf8(0x6b) . _utf8(0x72), // Norway, Krone 
        'OMR'  => _utf8(0xfdfc), // Oman, Rials 
        'PKR'  => _utf8(0x20a8), // Pakistan, Rupees 
        'PAB'  => _utf8(0x42) . _utf8(0x2f) . _utf8(0x2e), // Panama, Balboa 
        'PYG'  => _utf8(0x47) . _utf8(0x73), // Paraguay, Guarani 
        'PEN'  => _utf8(0x53) . _utf8(0x2f) . _utf8(0x2e), // Peru, Nuevos Soles 
        'PHP'  => _utf8(0x50) . _utf8(0x68) . _utf8(0x70), // Philippines, Pesos 
        'PLN'  => _utf8(0x7a) . _utf8(0x142), // Poland, Zlotych 
        'QAR'  => _utf8(0xfdfc), // Qatar, Rials 
        'RON'  => _utf8(0x6c) . _utf8(0x65) . _utf8(0x69), // Romania, New Lei 
        'RUB'  => _utf8(0x440) . _utf8(0x443) . _utf8(0x431), // Russia, Rubles 
        'SHP'  => _utf8(0xa3), // Saint Helena, Pounds 
        'SAR'  => _utf8(0xfdfc), // Saudi Arabia, Riyals 
        'RSD'  => _utf8(0x414) . _utf8(0x438) . _utf8(0x43d), // Serbia, Dinars 
        'SCR'  => _utf8(0x20a8), // Seychelles, Rupees 
        'SGD'  => _utf8(0x24), // Singapore, Dollars 
        'SKK'  => _utf8(0x53) . _utf8(0x49) . _utf8(0x54), // Slovakia, Koruny 
        'EUR'  => _utf8(0x20ac), // Slovenia, Euro 
        'SBD'  => _utf8(0x24), // Solomon Islands, Dollars 
        'SOS'  => _utf8(0x53), // Somalia, Shillings 
        'ZAR'  => _utf8(0x52), // South Africa, Rand 
        'KRW'  => _utf8(0x20a9), // South Korea, Won 
        'ESP'  => _utf8(0x20a7), // Spain, Pesetas (obsolete) 
        'LKR'  => _utf8(0x20a8), // Sri Lanka, Rupees 
        'SEK'  => _utf8(0x6b) . _utf8(0x72), // Sweden, Kronor 
        'CHF'  => _utf8(0x43) . _utf8(0x48) . _utf8(0x46), // Switzerland, Francs 
        'SRD'  => _utf8(0x24), // Suriname, Dollars 
        'SYP'  => _utf8(0xa3), // Syria, Pounds 
        'TWD'  => _utf8(0x4e) . _utf8(0x54) . _utf8(0x24), // Taiwan, New Dollars 
        'THB'  => _utf8(0xe3f), // Thailand, Baht 
        'TTD'  => _utf8(0x54) . _utf8(0x54) . _utf8(0x24), // Trinidad and Tobago, Dollars 
        'TRY'  => _utf8(0x59) . _utf8(0x54) . _utf8(0x4c), // Turkey, New Lira 
        'TRL'  => _utf8(0x20a4), // Turkey, Liras 
        'TVD'  => _utf8(0x24), // Tuvalu, Dollars 
        'UAH'  => _utf8(0x20b4), // Ukraine, Hryvnia 
        'GBP'  => _utf8(0xa3), // United Kingdom, Pounds 
        'USD'  => _utf8(0x24), // United States of America, Dollars 
        'UYU'  => _utf8(0x24) . _utf8(0x55), // Uruguay, Pesos 
        'UZS'  => _utf8(0x43b) . _utf8(0x432), // Uzbekistan, Sums 
        'VAL'  => _utf8(0x20a4), // Vatican City, Lire (obsolete) 
        'VEB'  => _utf8(0x42) . _utf8(0x73), // Venezuela, Bolivares 
        'VND'  => _utf8(0x20ab), // Vietnam, Dong 
        'YER'  => _utf8(0xfdfc), // Yemen, Rials 
        'ZWD'  => _utf8(0x5a) . _utf8(0x24), // Zimbabwe, Zimbabwe Dollars 
        'AED'  => '',
        'AMD'  => '',
        'AOA'  => '',
        'BDT'  => '',
        'BHD'  => '',
        'BIF'  => '',
        'BTN'  => '',
        'CDF'  => '',
        'CHE'  => '',
        'CHW'  => '',
        'CLF'  => '',
        'COU'  => '',
        'CVE'  => '',
        'DJF'  => '',
        'DZD'  => '',
        'ERN'  => '',
        'ETB'  => '',
        'GEL'  => '',
        'GHS'  => '',
        'GMD'  => '',
        'GNF'  => '',
        'GTQ'  => '',
        'GWP'  => '',
        'HTG'  => '',
        'IQD'  => '',
        'JOD'  => '',
        'KES'  => '',
        'KMF'  => '',
        'KWD'  => '',
        'LSL'  => '',
        'LYD'  => '',
        'MAD'  => '',
        'MDL'  => '',
        'MGA'  => '',
        'MMK'  => '',
        'MOP'  => '',
        'MRO'  => '',
        'MVR'  => '',
        'MWK'  => '',
        'MXV'  => '',
        'PGK'  => '',
        'RWF'  => '',
        'SDG'  => '',
        'SLL'  => '',
        'STD'  => '',
        'SZL'  => '',
        'TJS'  => '',
        'TMM'  => '',
        'TND'  => '',
        'TOP'  => '',
        'TZS'  => '',
        'UGX'  => '',
        'USN'  => '',
        'USS'  => '',
        'UYI'  => '',
        'VEF'  => '',
        'VUV'  => '',
        'WST'  => '',
        'XAF'  => '',
        'XAG'  => '',
        'XAU'  => '',
        'XBA'  => '',
        'XBB'  => '',
        'XBC'  => '',
        'XBD'  => '',
        'XDR'  => '',
        'XFO'  => '',
        'XFU'  => '',
        'XOF'  => '',
        'XPD'  => '',
        'XPF'  => '',
        'XPT'  => '',
        'XTS'  => '',
        'XXX'  => '',
        'ZMK'  => ''
    );
        
    // Make WshShell accessible
    $shell= &new COM('WScript.Shell');
    // Element was not present. Create it into the global string array
    switch ( $item )
    {
    case ABDAY_1:
    case ABDAY_2:
    case ABDAY_3:
    case ABDAY_4:
    case ABDAY_5:
    case ABDAY_6:
    case ABDAY_7:
        // Get the abbreviation for a weekday, knowing that 2007-11-18 was a Sunday
        $_nl_langinfo_strings[$item] = strftime( '%a', mktime( 0, 0, 0, 11, 18+$item-ABDAY_1, 2007 ) );
        break;
    case DAY_1:
    case DAY_2:
    case DAY_3:
    case DAY_4:
    case DAY_5:
    case DAY_6:
    case DAY_7:
        // Get the name for a weekday, knowing that 2007-11-18 was a Sunday
        $_nl_langinfo_strings[$item] = strftime( '%A', mktime( 0, 0, 0, 11, 18+$item-DAY_1, 2007 ) );
        break;
    case ABMON_1:
    case ABMON_2:
    case ABMON_3:
    case ABMON_4:
    case ABMON_5:
    case ABMON_6:
    case ABMON_7:
    case ABMON_8:
    case ABMON_9:
    case ABMON_10:
    case ABMON_11:
    case ABMON_12:
        // Get the month abbreviation
        $_nl_langinfo_strings[$item] = strftime( '%b', mktime( 0, 0, 0, 1+$item-ABMON_1, 1, 2007 ) );
        break;
    case MON_1:
    case MON_2:
    case MON_3:
    case MON_4:
    case MON_5:
    case MON_6:
    case MON_7:
    case MON_8:
    case MON_9:
    case MON_10:
    case MON_11:
    case MON_12:
        // Get the month name
        $_nl_langinfo_strings[$item] = strftime( '%B', mktime( 0, 0, 0, 1+$item-MON_1, 1, 2007 ) );
        break;
    case AM_STR:
        $_nl_langinfo_strings[$item] = strftime( '%p', mktime( 1, 0, 0, 1, 1, 2007 ) );
        break;
    case PM_STR:
        $_nl_langinfo_strings[$item] = strftime( '%p', mktime( 13, 0, 0, 1, 1, 2007 ) );
        break;
    case D_T_FMT:
        $_nl_langinfo_strings[$item] = nl_langinfo_parse( strftime( '%c', mktime( 21, 22, 23, 11, 1, 2007 ) ) );
        break;
    case D_FMT:
        $_nl_langinfo_strings[$item] = nl_langinfo_parse( strftime( '%x', mktime( 21, 22, 23, 11, 1, 2007 ) ) );
        break;
    case T_FMT:
        // NOTE: Contrary to the original nl_langinfo function,
        // this function does not return '%r', but the expanded format string
        $_nl_langinfo_strings[$item] = nl_langinfo_parse( strftime( '%X', mktime( 21, 22, 23, 11, 1, 2007 ) ) );
        break;
    case T_FMT_AMPM:
        $_nl_langinfo_strings[$item] = nl_langinfo_parse( strftime( '%r', mktime( 21, 22, 23, 11, 1, 2007 ) ) );
        break;
    case INT_CURR_SYMBOL:
        // Read the currency symbol from the regisrty and try to make it into an international symbol.
        // If the international symbol cannot be found, use the local currency symbol
        // !! NOTE: This is a diversino from nl_langinfo() !!
        $curr = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sCurrency');
        if ( ($intlCurr = array_search($curr,$_nl_langinfo_currencies)) !== false )
        {
            $_nl_langinfo_strings[$item] = $intlCurr;
        }
        else
        {
            $_nl_langinfo_strings[$item] = $curr;
        }
        // Try to resolve it using the currency table
        break;
    case CURRENCY_SYMBOL:
    case CRNCYSTR:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sCurrency');
        break;
    case MON_DECIMAL_POINT:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sMonDecimalSep');
        break;
    case MON_THOUSANDS_SEP:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sMonThousandSep');;
        break;
    case MON_GROUPING:
        // Grouping needs to be turned from seim-colon separated string to an ASCII string
        // See also http://www.opengroup.org/onlinepubs/009695399/functions/localeconv.html
        // Note that nl_langinfo returns a string of characters
        // The codes returned are encoded as the ASCII characters
        // E.g.: If the return value is 2 and 3, the returned string's two characters are ASCII 2 and ASCII 3
        $gr = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sMonGrouping');
        $a = explode( ';', $gr );
        $grouping = '';
        foreach ( $a as $g )
        {
            $grouping .= chr($g);
        }
        $_nl_langinfo_strings[$item] = $grouping;
        break;
    case GROUPING:
        // Grouping needs to be turned from seim-colon separated string to an ASCII string
        // See also http://www.opengroup.org/onlinepubs/009695399/functions/localeconv.html
        // Note that nl_langinfo returns a string of characters
        // The codes returned are encoded as the ASCII characters
        // E.g.: If the return value is 2 and 3, the returned string's two characters are ASCII 2 and ASCII 3
        $gr = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sGrouping');
        $a = explode( ';', $gr );
        $grouping = '';
        foreach ( $a as $g )
        {
            $grouping .= chr($g);
        }
        $_nl_langinfo_strings[$item] = $grouping;
        break;
    case POSITIVE_SIGN:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sPositiveSign');
        break;
    case NEGATIVE_SIGN:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sNegativeSign');
        break;
    case INT_FRAC_DIGITS:
        $lc = localeconv();
        // Note that nl_langinfo returns a string of 1 character
        // The code returned is encoded as the ASCII character
        // E.g.: If the return value is 1, the returned string's single character is ASCII 1
        $_nl_langinfo_strings[$item] = chr($shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\iCurrDigits'));
        break;
    case FRAC_DIGITS:
        $lc = localeconv();
        // Note that nl_langinfo returns a string of 1 character
        // The code returned is encoded as the ASCII character
        // E.g.: If the return value is 1, the returned string's single character is ASCII 1
        $_nl_langinfo_strings[$item] = chr($shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\iDigits'));
        break;
    case DECIMAL_POINT:
    case RADIXCHAR:
        $lc = localeconv();
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sDecimal');
        break;
    case THOUSANDS_SEP:
    case THOUSEP:
        $_nl_langinfo_strings[$item] = $shell->regRead('HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sThousand');
        break;
    case CODESET:
        // Get the current locale
        $s = setlocale(LC_ALL,0);
        // Parse out the character set in the first item
        if ( preg_match( '/\.([0-9a-z\-_]+)/i', $s, $matches ) )
        {
            $_nl_langinfo_strings[$item] = $matches[1];
        }
        else
        {
            // Unknown character set
            $_nl_langinfo_strings[$item] = '';
        }
        break;
        
    default:
        // ERA_XXXX constants and LC_MESSAGES are moved here, because I do not have a clue what they mean.
        // Some currency elements are not supported through the registry either
        return '';
    }
    
    return $_nl_langinfo_strings[$item];
}

/**
* Helper parse function
*
* Parses out date and time elements from a given string
* and returns the strftime formatting parameters
*
* @param        string                Date/time string for 2007-11-01 21:22:23
* @return        string                strftime() format string
*/
function nl_langinfo_parse( $dt )
{
    global $_nl_langinfo_date_strings;
    
    if ( !count($_nl_langinfo_date_strings) )
    {
        // First time build of the elements.The order is important to make sure longer items get evaluated first
        $t = mktime( 21, 22, 23, 11, 1, 2007 );
        $_nl_langinfo_date_strings['%Y'] = strftime( '%Y', $t );
        $_nl_langinfo_date_strings['%G'] = strftime( '%G', $t );
        $_nl_langinfo_date_strings['%A'] = strftime( '%A', $t );
        $_nl_langinfo_date_strings['%B'] = strftime( '%B', $t );
        $_nl_langinfo_date_strings['%a'] = strftime( '%a', $t );
        $_nl_langinfo_date_strings['%b'] = strftime( '%b', $t );
        $_nl_langinfo_date_strings['%h'] = strftime( '%h', $t );
        $_nl_langinfo_date_strings['%C'] = strftime( '%C', $t );
        $_nl_langinfo_date_strings['%d'] = strftime( '%d', $t );
        $_nl_langinfo_date_strings['%e'] = strftime( '%e', $t );
        $_nl_langinfo_date_strings['%y'] = strftime( '%y', $t );
        $_nl_langinfo_date_strings['%g'] = strftime( '%g', $t );
        $_nl_langinfo_date_strings['%H'] = strftime( '%H', $t );
        $_nl_langinfo_date_strings['%I'] = strftime( '%I', $t );
        $_nl_langinfo_date_strings['%j'] = strftime( '%j', $t );
        $_nl_langinfo_date_strings['%m'] = strftime( '%m', $t );
        $_nl_langinfo_date_strings['%M'] = strftime( '%M', $t );
        $_nl_langinfo_date_strings['%p'] = strftime( '%p', $t );
        $_nl_langinfo_date_strings['%S'] = strftime( '%S', $t );
        $_nl_langinfo_date_strings['%u'] = strftime( '%u', $t );
        $_nl_langinfo_date_strings['%U'] = strftime( '%U', $t );
        $_nl_langinfo_date_strings['%V'] = strftime( '%V', $t );
        $_nl_langinfo_date_strings['%W'] = strftime( '%W', $t );
        $_nl_langinfo_date_strings['%w'] = strftime( '%w', $t );
        $_nl_langinfo_date_strings['%z'] = strftime( '%z', $t );
        $_nl_langinfo_date_strings['%Z'] = strftime( '%Z', $t );
    }
    
    // Replace the elements in the passed date string with the elements from
    // the $_nl_langinfo_date_strings array
    $dt = str_replace( array_values($_nl_langinfo_date_strings), array_keys($_nl_langinfo_date_strings), $dt );
    return $dt;
}
?>