Пример #1
0
<?php

include '../vendor/autoload.php';
include '../src/unreal4u/localization.php';
$locale = new \unreal4u\localization();
$testLocales = array('pt-BR', 'hi_IN', 'es-CL', 'es-BO', 'pt-PT', 'ko-KR', 'nl-NL', 'jp-JP', 'nl-BE', 'de-DE', 'en-CA', 'en-GB', '');
$locale->sendHeaders();
foreach ($testLocales as $testLocale) {
    if (empty($testLocale)) {
        $locale->autodetectLocale();
    } else {
        $locale->setDefault($testLocale);
    }
    $theDate = new \DateTime('23-05-2015 21:34:09', new \DateTimeZone('UTC'));
    if ($locale->timezoneId != 'UTC') {
        var_dump('Current locale: ' . $locale->getDefault());
        var_dump('Time zone id: ' . $locale->timezoneId);
        var_dump('Offset is: ' . $locale->getTimezoneOffset('hours') . ' hours (or ' . $locale->getTimezoneOffset('z') . ')');
        printf('UTC 23-05-2015 21:34:09 is %s %s in %s' . PHP_EOL, $locale->formatSimpleDate($theDate), $locale->formatSimpleTime($theDate), $locale->getDefault());
    } else {
        var_dump('Could not determine automatically the timezone for ' . $locale->getDefault());
        var_dump('Please select one from the following list: ');
        var_dump($locale->getTimeZoneCandidates());
    }
    var_dump(str_repeat('-', 80));
}
Пример #2
0
<?php

include '../src/unreal4u/localization.php';
$locale = new unreal4u\localization();
$testLocales = array('pt-BR', 'hi_IN', 'pt-PT', 'ko-KR', 'nl-NL', 'jp-JP', 'nl-BE', 'de-DE', 'en-CA', 'en-GB', '');
$testNumbers = array(0, 1, 3, 3.1415, -45.33, 20000);
$locale->sendHeaders();
foreach ($testLocales as $testLocale) {
    if (empty($testLocale)) {
        $locale->autodetectLocale();
    } else {
        $locale->setDefault($testLocale);
    }
    var_dump('Current locale: ' . $locale->getDefault());
    printf('Timezone offset: <strong>%s</strong><br />', $locale->getTimezoneOffset());
    printf('Date (UTC): <strong>%s</strong><br />', $locale->formatSimpleDate(0, 'UTC'));
    printf('Date (local): <strong>%s</strong><br />', $locale->formatSimpleDate());
    printf('Time (UTC): <strong>%s</strong><br />', $locale->formatSimpleTime(0, 'UTC'));
    printf('Time (local): <strong>%s</strong><br />', $locale->formatSimpleTime());
    foreach ($testNumbers as $testNumber) {
        printf('Number: <strong>%s</strong><br />', $locale->formatNumber($testNumber));
        printf('Currency: <strong>%s</strong><br />', $locale->formatNumber($testNumber, \Numberformatter::CURRENCY));
        printf('Currency Symbol: <strong>%s</strong><br />', $locale->getCurrencyISOCode());
        printf('---<br />');
    }
}