/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $rb = new \ResourceBundle($locale, $resource);
     if (!$rb) {
         throw new \RuntimeException("cannot load this resource : {$resource}");
     } elseif (intl_is_failure($rb->getErrorCode())) {
         throw new \RuntimeException($rb->getErrorMessage(), $rb->getErrorCode());
     }
     $messages = $this->flatten($rb);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     $catalogue->addResource(new FileResource($resource . '.dat'));
     return $catalogue;
 }
Exemple #2
0
 public function getStrictDomainDataProvider()
 {
     ini_set('memory_limit', '6G');
     // All available locales
     $locales = \ResourceBundle::getLocales('');
     // Fake locales
     $locales[] = 'xx_XX_XXXX';
     $locales[] = 'en_XX';
     $locales[] = 'en_US_XXXX';
     $locales[] = 'xx_Cyrl';
     // Invalid locales
     $locales[] = 'foobarfoobarfoobar';
     $locales[] = 'foo bar';
     // All available currencies
     $currencies = [];
     $currencyResources = \ResourceBundle::create('en', 'ICUDATA-curr', true);
     $currencySymbols = $currencyResources->get('Currencies');
     foreach ($currencySymbols as $currencyCode => $bundle) {
         $currencies[] = $currencyCode;
     }
     $data = [];
     foreach ($locales as $locale) {
         foreach ($currencies as $currencyCode) {
             $data[] = [$locale, $currencyCode];
         }
     }
     return $data;
 }
 /**
  * Get options array for locale dropdown
  *
  * @param   bool $translatedName translation flag
  * @return  array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _getOptionLocales($translatedName = false)
 {
     $currentLocale = $this->localeResolver->getLocale();
     $locales = \ResourceBundle::getLocales('') ?: [];
     $languages = (new LanguageBundle())->get($currentLocale)['Languages'];
     $countries = (new RegionBundle())->get($currentLocale)['Countries'];
     $options = [];
     $allowedLocales = $this->_config->getAllowedLocales();
     foreach ($locales as $locale) {
         if (!in_array($locale, $allowedLocales)) {
             continue;
         }
         $language = \Locale::getPrimaryLanguage($locale);
         $country = \Locale::getRegion($locale);
         if (!$languages[$language] || !$countries[$country]) {
             continue;
         }
         if ($translatedName) {
             $label = ucwords(\Locale::getDisplayLanguage($locale, $locale)) . ' (' . \Locale::getDisplayRegion($locale, $locale) . ') / ' . $languages[$language] . ' (' . $countries[$country] . ')';
         } else {
             $label = $languages[$language] . ' (' . $countries[$country] . ')';
         }
         $options[] = ['value' => $locale, 'label' => $label];
     }
     return $this->_sortOptionArray($options);
 }
function load_resource_bundle($locale, $directory)
{
    $bundle = \ResourceBundle::create($locale, $directory);
    if (null === $bundle) {
        bailout('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $directory);
    }
    return $bundle;
}
Exemple #5
0
 /**
  * @param string $locale
  *
  * @throws \IntlException
  * @return \ResourceBundle
  */
 private function getResourceBundle($locale)
 {
     if (!isset($this->resourceBundles[$locale])) {
         $resourceBundle = \ResourceBundle::create($locale, $this->resourcesDirectory, true);
         if ($resourceBundle === null) {
             throw new \IntlException('Could not create resource bundle');
         }
         $this->resourceBundles[$locale] = $resourceBundle;
     }
     return $this->resourceBundles[$locale];
 }
Exemple #6
0
 /**
  * Returns the language names for a locale
  *
  * @param  string $locale     The locale to use for the language names
  * @return array              The language names with their codes as keys
  * @throws RuntimeException   When the resource bundles cannot be loaded
  */
 public static function getDisplayLanguages($locale)
 {
     if (!isset(self::$languages[$locale])) {
         $bundle = new \ResourceBundle($locale, __DIR__ . '/Resources/data/lang');
         if (null === $bundle) {
             throw new \RuntimeException('The language resource bundle could not be loaded');
         }
         $collator = new \Collator($locale);
         $languages = array();
         foreach ($bundle->get('Languages') as $code => $name) {
             // "mul" is the code for multiple languages
             if ('mul' !== $code) {
                 $languages[$code] = $name;
             }
         }
         $collator->asort($languages);
         self::$languages[$locale] = $languages;
     }
     return self::$languages[$locale];
 }
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource . '.dat')) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource . '.dat')) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $rb = new \ResourceBundle($locale, $resource);
     if (!$rb) {
         throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
     } elseif (intl_is_failure($rb->getErrorCode())) {
         throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
     }
     $messages = $this->flatten($rb);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     $catalogue->addResource(new FileResource($resource . '.dat'));
     return $catalogue;
 }
 /**
  * Return array of locales, supported by the theme
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return array
  */
 protected static function _getThemeLocales(\Magento\Framework\View\Design\ThemeInterface $theme)
 {
     $result = [];
     $patternDir = self::_getLocalePatternDir($theme);
     foreach (\ResourceBundle::getLocales('') as $locale) {
         $dir = str_replace('<locale_placeholder>', $locale, $patternDir);
         if (is_dir($dir)) {
             $result[] = $locale;
         }
     }
     return $result;
 }
Exemple #9
0
 /**
  * Retrieve list of locales
  *
  * @return  array
  */
 public function getLocaleList()
 {
     $languages = (new LanguageBundle())->get(Resolver::DEFAULT_LOCALE)['Languages'];
     $countries = (new RegionBundle())->get(Resolver::DEFAULT_LOCALE)['Countries'];
     $locales = \ResourceBundle::getLocales('') ?: [];
     $list = [];
     foreach ($locales as $locale) {
         if (!in_array($locale, $this->allowedLocales)) {
             continue;
         }
         $language = \Locale::getPrimaryLanguage($locale);
         $country = \Locale::getRegion($locale);
         if (!$languages[$language] || !$countries[$country]) {
             continue;
         }
         $list[$locale] = $languages[$language] . ' (' . $countries[$country] . ')';
     }
     asort($list);
     return $list;
 }
Exemple #10
0
    /**
     * Returns the locale names for a locale
     *
     * @param  string $locale     The locale to use for the locale names
     * @return array              The locale names with their codes as keys
     * @throws RuntimeException   When the resource bundles cannot be loaded
     */
    static public function getDisplayLocales($locale)
    {
        if (!isset(self::$locales[$locale])) {
            $bundle = \ResourceBundle::create($locale, __DIR__.'/Resources/data/names');

            if (null === $bundle) {
                throw new \RuntimeException('The locale resource bundle could not be loaded');
            }

            $collator = new \Collator($locale);
            $locales = array();

            foreach ($bundle->get('Locales') as $code => $name) {
                $locales[$code] = $name;
            }

            $collator->asort($locales);

            self::$locales[$locale] = $locales;
        }

        return self::$locales[$locale];
    }
Exemple #11
0
 /**
  * Retrieve the currency symbol of the given locale anche currency code.
  *
  * @param $locale
  * @param $currencyCode
  * @return string
  */
 protected function getFirstCurrencySymbol($locale, $currencyCode)
 {
     $currencySymbol = null;
     $parent = null;
     // Check first in passed locale
     $currencyResources = \ResourceBundle::create($locale, 'ICUDATA-curr', false);
     if ($currencyResources instanceof \ResourceBundle) {
         $currencySymbols = $currencyResources->get('Currencies');
         $parent = $currencyResources->get('%%Parent');
         if ($currencySymbols instanceof \ResourceBundle) {
             $currencyCodeSymbols = $currencySymbols->get($this->getCurrencyCode());
             if ($currencyCodeSymbols instanceof \ResourceBundle) {
                 if ($currencySymbol = $currencyCodeSymbols->get(0)) {
                     return $currencySymbol;
                     // found
                 }
             }
         }
     }
     // If root, no other fallbacks are available. Return the ISO currency code as default.
     if ($locale === 'root') {
         return $currencyCode;
     }
     // If any, check in parent
     if ($parent) {
         $currencyResources = \ResourceBundle::create($parent, 'ICUDATA-curr', false);
         if ($currencyResources instanceof \ResourceBundle) {
             $currencySymbols = $currencyResources->get('Currencies');
             if ($currencySymbols instanceof \ResourceBundle) {
                 $currencyCodeSymbols = $currencySymbols->get($this->getCurrencyCode());
                 if ($currencyCodeSymbols instanceof \ResourceBundle) {
                     if ($currencySymbol = $currencyCodeSymbols->get(0)) {
                         return $currencySymbol;
                         // Found
                     }
                 }
             }
         }
         // If root, no other fallbacks are available. Return the ISO currency code as default.
         if ($parent === 'root') {
             return $currencyCode;
         }
     }
     // Fallback locale up to root
     if (strpos($locale, '_') !== false) {
         $locale = explode('_', $locale);
         array_pop($locale);
         $locale = implode('_', $locale);
     } else {
         $locale = 'root';
     }
     return $this->getFirstCurrencySymbol($locale, $currencyCode);
 }
<?php

$b = new ResourceBundle('de_DE', 'ICUDATA-region');
var_dump($b->get('Countries')->get('DE'));
$b = new ResourceBundle('icuver', 'ICUDATA');
var_dump($b->get('ICUVersion') !== NULL);
$b = new ResourceBundle('supplementalData', 'ICUDATA', false);
var_dump($b->get('cldrVersion') !== NULL);
Exemple #13
0
 function index()
 {
     $this->load->helper('form');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('company_name', 'lang:company_name', 'required');
     $this->form_validation->set_rules('theme', 'lang:theme', 'required');
     $this->form_validation->set_rules('email', 'lang:cart_email', 'required|valid_email');
     $this->form_validation->set_rules('country_id', 'lang:country');
     $this->form_validation->set_rules('address1', 'lang:address');
     $this->form_validation->set_rules('address2', 'lang:address');
     $this->form_validation->set_rules('zone_id', 'lang:state');
     $this->form_validation->set_rules('zip', 'lang:zip');
     $this->form_validation->set_rules('locale', 'lang:locale', 'required');
     $this->form_validation->set_rules('currency_iso', 'lang:currency', 'required');
     $data = $this->Settings_model->get_settings('gocart');
     $data['config'] = $data;
     //break out order statuses to an array
     //get installed themes
     $data['themes'] = array();
     if ($handle = opendir(FCPATH . APPPATH . '/themes')) {
         while (false !== ($entry = readdir($handle))) {
             if ($entry != "." && $entry != ".." && is_dir(FCPATH . APPPATH . '/themes/' . $entry)) {
                 $data['themes'][$entry] = $entry;
             }
         }
         closedir($handle);
     }
     asort($data['themes']);
     //get locales
     $locales = ResourceBundle::getLocales('');
     $data['locales'] = array();
     foreach ($locales as $locale) {
         $data['locales'][$locale] = locale_get_display_name($locale);
     }
     asort($data['locales']);
     //get ISO 4217 codes
     $data['iso_4217'] = array();
     $iso_4217 = json_decode(json_encode(simplexml_load_file(FCPATH . 'ISO_4217.xml')));
     $iso_4217 = $iso_4217->CcyTbl->CcyNtry;
     foreach ($iso_4217 as $iso_code) {
         if (isset($iso_code->Ccy)) {
             $data['iso_4217'][$iso_code->Ccy] = $iso_code->Ccy;
         }
     }
     asort($data['iso_4217']);
     $data['countries_menu'] = $this->Location_model->get_countries_menu();
     if (!empty($data['country_id'])) {
         $data['zones_menu'] = $this->Location_model->get_zones_menu($data['country_id']);
     } else {
         $data['zones_menu'] = $this->Location_model->get_zones_menu(array_shift(array_keys($data['countries_menu'])));
     }
     $data['page_title'] = lang('common_gocart_configuration');
     if ($this->form_validation->run() == FALSE) {
         $data['error'] = validation_errors();
         $this->view($this->config->item('admin_folder') . '/settings', $data);
     } else {
         $this->session->set_flashdata('message', lang('config_updated_message'));
         $save = $this->input->post();
         //fix boolean values
         $save['ssl_support'] = $this->input->post('ssl_support');
         $save['require_login'] = $this->input->post('require_login');
         $save['new_customer_status'] = $this->input->post('new_customer_status');
         $save['allow_os_purchase'] = $this->input->post('allow_os_purchase');
         $save['tax_shipping'] = $this->input->post('tax_shipping');
         $this->Settings_model->save_settings('gocart', $save);
         redirect(config_item('admin_folder') . '/settings');
     }
 }
<?php

ini_set("intl.error_level", E_WARNING);
$r = new ResourceBundle('en_US', NULL);
$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
var_dump($c);
ini_set('intl.default_locale', 'pt_PT');
$r = new ResourceBundle(NULL, NULL);
$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
var_dump($c);
?>
==DONE==
 public function actionSuggestLocale($term)
 {
     $result = [];
     $locales = \ResourceBundle::getLocales('');
     foreach ($locales as $locale) {
         if ($term !== '' && strncasecmp($term, $locale, min(strlen($term), strlen($locale))) === 0) {
             $result[] = $locale;
         }
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $result;
 }
<?php

define('LOCALE', 'en_US');
$bundle = new ResourceBundle(LOCALE, __DIR__);
$candy = new MessageFormatter(LOCALE, $bundle->get('CANDY'));
$favs = new MessageFormatter(LOCALE, $bundle->get('FAVORITE_FOODS'));
print $favs->format(array($candy->format(array()))) . "\n";
<?php

$r = new ResourceBundle('en', 'ICUDATA');
$r->count();
$r->getErrorCode();
$r->getErrorMessage();
$r->get(0);
ResourceBundle::getLocales('');
resourcebundle_get($r, 0);
resourcebundle_locales('');
 public function index()
 {
     \CI::load()->helper('form');
     \CI::load()->library('form_validation');
     //set defaults
     $data = ['company_name' => '', 'theme' => 'default', 'homepage' => '', 'products_per_page' => '24', 'default_meta_keywords' => '', 'default_meta_description' => '', 'sendmail_path' => '/usr/sbin/sendmail -bs', 'email_from' => '', 'email_to' => '', 'email_method' => 'Mail', 'smtp_server' => '', 'smtp_username' => '', 'smtp_password' => '', 'smtp_port' => '25', 'country_id' => '', 'city' => '', 'address1' => '', 'address2' => '', 'zone_id' => '', 'zip' => '', 'locale' => locale_get_default(), 'timezone' => date_default_timezone_get(), 'currency_iso' => 'USD', 'ssl_support' => '', 'stage_username' => '', 'stage_password' => '', 'require_login' => '', 'new_customer_status' => '1', 'weight_unit' => 'LB', 'dimension_unit' => 'IN', 'order_status' => '', 'inventory_enabled' => '', 'allow_os_purchase' => '', 'tax_address' => '', 'tax_shipping' => ''];
     \CI::form_validation()->set_rules('company_name', 'lang:company_name', 'required');
     \CI::form_validation()->set_rules('default_meta_keywords', 'lang:default_meta_keywords', 'trim|strip_tags');
     \CI::form_validation()->set_rules('default_meta_description', 'lang:default_meta_description', 'trim|strip_tags');
     \CI::form_validation()->set_rules('theme', 'lang:theme', 'required');
     \CI::form_validation()->set_rules('homepage', 'lang:select_homepage');
     \CI::form_validation()->set_rules('products_per_page', 'lang:products_per_page');
     \CI::form_validation()->set_rules('email_from', 'lang:email_from', 'required|valid_email');
     \CI::form_validation()->set_rules('email_to', 'lang:email_to', 'required|valid_email');
     \CI::form_validation()->set_rules('email_method', 'lang:email_method', 'required');
     if (\CI::input()->post('email_method') == 'smtp') {
         \CI::form_validation()->set_rules('smtp_server', 'lang:smtp_server', 'required');
         \CI::form_validation()->set_rules('smtp_username', 'lang:smtp_username', 'required');
         \CI::form_validation()->set_rules('smtp_password', 'lang:smtp_password', 'required');
         \CI::form_validation()->set_rules('smtp_port', 'lang:smtp_port', 'required');
     } elseif (\CI::input()->post('email_method') == 'sendmail') {
         \CI::form_validation()->set_rules('sendmail_path', 'lang:sendmail_path', 'required');
     }
     \CI::form_validation()->set_rules('country_id', 'lang:country');
     \CI::form_validation()->set_rules('address1', 'lang:address');
     \CI::form_validation()->set_rules('address2', 'lang:address');
     \CI::form_validation()->set_rules('zone_id', 'lang:state');
     \CI::form_validation()->set_rules('zip', 'lang:zip');
     \CI::form_validation()->set_rules('locale', 'lang:locale', 'required');
     \CI::form_validation()->set_rules('timezone', 'lang:timezone', 'required');
     \CI::form_validation()->set_rules('currency_iso', 'lang:currency', 'required');
     \CI::form_validation()->set_rules('ssl_support', 'lang:ssl_support');
     \CI::form_validation()->set_rules('stage', 'lang:stage');
     \CI::form_validation()->set_rules('stage_username', 'lang:stage_username');
     \CI::form_validation()->set_rules('stage_password', 'lang:stage_password');
     \CI::form_validation()->set_rules('require_login', 'lang:require_login');
     \CI::form_validation()->set_rules('new_customer_status', 'lang:new_customer_status');
     \CI::form_validation()->set_rules('weight_unit', 'lang:weight_unit');
     \CI::form_validation()->set_rules('order_status', 'lang:order_status');
     \CI::form_validation()->set_rules('inventory_enabled', 'lang:inventory_enabled');
     \CI::form_validation()->set_rules('allow_os_purchase', 'lang:allow_os_purchase');
     \CI::form_validation()->set_rules('tax_address', 'lang:tax_address');
     \CI::form_validation()->set_rules('tax_shipping', 'lang:tax_shipping');
     // get the values from the DB
     $data = array_merge($data, \CI::Settings()->get_settings('gocart'));
     $data['config'] = $data;
     //break out order statuses to an array
     //get installed themes
     $data['themes'] = [];
     $themePath = FCPATH . 'themes/';
     if ($handle = opendir($themePath)) {
         while (false !== ($entry = readdir($handle))) {
             if ($entry != "." && $entry != ".." && is_dir($themePath . $entry)) {
                 $data['themes'][$entry] = $entry;
             }
         }
         closedir($handle);
     }
     asort($data['themes']);
     //get locales
     $locales = \ResourceBundle::getLocales('');
     $data['locales'] = [];
     foreach ($locales as $locale) {
         $data['locales'][$locale] = locale_get_display_name($locale);
     }
     asort($data['locales']);
     //get ISO 4217 codes
     $data['iso_4217'] = [];
     $iso_4217 = json_decode(json_encode(simplexml_load_file(FCPATH . 'ISO_4217.xml')));
     $iso_4217 = $iso_4217->CcyTbl->CcyNtry;
     foreach ($iso_4217 as $iso_code) {
         if (isset($iso_code->Ccy)) {
             $data['iso_4217'][$iso_code->Ccy] = $iso_code->Ccy;
         }
     }
     asort($data['iso_4217']);
     $data['countries_menu'] = \CI::Locations()->get_countries_menu();
     if (!empty($data['country_id'])) {
         $data['zones_menu'] = \CI::Locations()->get_zones_menu($data['country_id']);
     } else {
         $countries_menu = array_keys($data['countries_menu']);
         $data['zones_menu'] = \CI::Locations()->get_zones_menu(array_shift($countries_menu));
     }
     $data['page_title'] = lang('common_gocart_configuration');
     $pages = \CI::Pages()->get_pages_tiered();
     $data['pages'] = [];
     foreach ($pages['all'] as $page) {
         if (empty($page->url)) {
             $data['pages'][$page->id] = $page->title;
         }
     }
     if (\CI::form_validation()->run() == FALSE) {
         $data['error'] = validation_errors();
         $this->view('settings', $data);
     } else {
         \CI::session()->set_flashdata('message', lang('config_updated_message'));
         $save = \CI::input()->post();
         //fix boolean values
         $save['ssl_support'] = (bool) \CI::input()->post('ssl_support');
         $save['require_login'] = (bool) \CI::input()->post('require_login');
         $save['new_customer_status'] = \CI::input()->post('new_customer_status');
         $save['allow_os_purchase'] = (bool) \CI::input()->post('allow_os_purchase');
         $save['tax_shipping'] = (bool) \CI::input()->post('tax_shipping');
         $save['homepage'] = \CI::input()->post('homepage');
         \CI::Settings()->save_settings('gocart', $save);
         redirect('admin/settings');
     }
 }
Exemple #19
0
<?php

var_dump(count(\ResourceBundle::getLocales('')) > 0);
Exemple #20
0
<?php

$locale = "en-US";
$elements5 = array("uno", "dos", "tres", "cuatro", "cinco");
$elements3 = array("uno", "dos", "tres");
$elements2 = array("uno", "dos");
$elements1 = array("uno");
echo "List to format:<br>\n";
echo "<pre>";
print_r($elements);
$prb = new ResourceBundle($locale);
// Pseudo code to show outside.
$formats = array("LIST_TWO_ITEMS" => $prb->get_string("LIST_TWO_ITEMS"), "LIST_END" => $prb->get_string("LIST_END"), "LIST_MIDDLE" => $prb->get_string("LIST_MIDDLE"), "LIST_START" => $prb->get_string("LIST_START"));
function msgfm_format_message_lists($locale, $formats, $elements)
{
    $size = count($elements);
    if ($size == 1) {
        $result = $elements[0];
    }
    if ($size == 2) {
        $result = message_list($locale, $formats["LIST_TWO_ITEMS"], array($elements[0], $elements[1]));
    }
    if ($size > 2) {
        $size_rest = $size;
        $end_array = array($elements[$size - 2], $elements[$size - 1]);
        $result = message_list($locale, $formats["LIST_END"], $end_array);
        for ($i = 3; $i <= $size; $i++) {
            if ($i == $size) {
                $format = $formats["LIST_START"];
            } else {
                $format = $formats["LIST_MIDDLE"];
Exemple #21
0
 /**
  * Returns the locale names for a locale
  *
  * @param string $locale The locale to use for the locale names
  *
  * @return array              The locale names with their codes as keys
  *
  * @throws \RuntimeException  When the resource bundles cannot be loaded
  */
 public static function getDisplayLocales($locale)
 {
     if (!isset(self::$locales[$locale])) {
         $bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory() . '/names');
         if (null === $bundle) {
             throw new \RuntimeException(sprintf('The locale resource bundle could not be loaded for locale "%s"', $locale));
         }
         $collator = new \Collator($locale);
         $locales = array();
         $bundleLocales = $bundle->get('Locales') ?: array();
         foreach ($bundleLocales as $code => $name) {
             $locales[$code] = $name;
         }
         $fallbackLocale = self::getFallbackLocale($locale);
         if (null !== $fallbackLocale) {
             $locales = array_merge(self::getDisplayLocales($fallbackLocale), $locales);
         }
         $collator->asort($locales);
         self::$locales[$locale] = $locales;
     }
     return self::$locales[$locale];
 }
<?php

include "resourcebundle.inc";
$r = new ResourceBundle('es', BUNDLE);
var_dump($r instanceof Traversable);
var_dump(iterator_to_array($r->get('testarray')));