public static function localeList() { App::import("Lib", 'l10n'); $l10n = new L10n(); $lc = $l10n->catalog(); $locales = array(); foreach ($lc as $l) { $locales[$l['locale']] = $l['language']; } return $locales; }
/** * Get available locales in locale directory * * @return array * @throws CakeException */ public static function getAvailableLocale() { if (!is_dir(APP . 'Locale')) { throw new CakeException('Locale directory not exist.'); } $dir = new Folder(APP . 'Locale'); if (!$dir->read()[0]) { throw new CakeException('Locale not exist.'); } $availableCatalog = []; $l10n = new L10n(); foreach ($dir->read()[0] as $locale) { $poFile = new File(APP . 'Locale' . self::DS . $locale . self::DS . 'LC_MESSAGES' . self::DS . 'hurad.po'); if ($poFile->exists()) { $catalog = $l10n->catalog($locale); if ($catalog) { $availableCatalog[$locale] = $catalog; } } } $availableCatalog = Hash::merge(['eng' => $l10n->catalog('eng')], $availableCatalog); return $availableCatalog; }
/** * PrivateSpaceルームの生成 * * @param array $data デフォルト値 * @return array PrivateSpaceルーム配列 */ public function createRoom($data = array()) { $this->loadModels(['Language' => 'M17n.Language', 'Room' => 'Rooms.Room', 'RoomsLanguage' => 'Rooms.RoomsLanguage']); $parentRoom = $this->Room->find('first', array('recursive' => -1, 'fields' => array('space_id', 'active', 'need_approval', 'page_layout_permitted'), 'conditions' => array('id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID)))); $result = $this->Room->create(Hash::merge(array('id' => null, 'root_id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID), 'parent_id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID), 'default_role_key' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, 'default_participation' => false), $parentRoom['Room'])); $languages = $this->Language->getLanguages(); App::uses('L10n', 'I18n'); $L10n = new L10n(); foreach ($languages as $i => $language) { $catalog = $L10n->catalog($language['Language']['code']); $roomsLanguage = $this->RoomsLanguage->create(array('id' => null, 'language_id' => $language['Language']['id'], 'room_id' => null, 'name' => __d('private_space', $catalog['language']))); $result['RoomsLanguage'][$i] = $roomsLanguage['RoomsLanguage']; } $result['Page']['parent_id'] = null; return $result; }
public function startup(Controller $controller) { $this->controller =& $controller; $this->Cookie->time = 3600 * 24 * 30; // expires after one month $languageOptions = array('ara' => 'العربية', 'chi' => '中文', 'eng' => 'English', 'fre' => 'Français', 'rus' => 'русский', 'spa' => 'español'); $l10n = new L10n(); $params = $controller->params; $ConfigItem = ClassRegistry::init('ConfigItem'); $showLanguage = $ConfigItem->getValue('language_menu'); $controller->set('showLanguage', $showLanguage); if (!empty($params->query['lang'])) { $lang = $params->query['lang']; } else { if ($this->Session->check('System.language')) { $lang = $this->Session->read('System.language'); } else { $lang = $ConfigItem->getValue('language'); } } if ($controller->name == 'Security' && $controller->action == 'login' && $controller->request->is('post') && isset($controller->request->data['submit']) && $controller->request->data['submit'] == 'reload') { $lang = $controller->request->data['SecurityUser']['language']; //$this->Cookie->write('System.language', $lang); } $locale = $l10n->map($lang); if ($locale == false) { $lang = 'eng'; $locale = $l10n->map($lang); } $catalog = $l10n->catalog($locale); $controller->set('lang_locale', $locale); $controller->set('lang_dir', $catalog['direction']); $controller->set('lang', $lang); $controller->set('languageOptions', $languageOptions); $this->Session->write('System.language', $lang); Configure::write('Config.language', $lang); }
public function initialize(Controller $Controller, $settings = array()) { $this->controller = $Controller; $this->isBrwPanel = (!empty($Controller->request->params['prefix']) and $Controller->request->params['prefix'] == 'brw' or $Controller->params['plugin'] == 'brownie'); ClassRegistry::init('BrwUser')->Behaviors->attach('Brownie.BrwUser'); ClassRegistry::init('BrwImage')->Behaviors->attach('Brownie.BrwUpload'); ClassRegistry::init('BrwFile')->Behaviors->attach('Brownie.BrwUpload'); if (!empty($Controller->request->params['prefix']) and $Controller->request->params['prefix'] == 'brw') { if (!class_exists('AuthComponent')) { $Controller->Components->load('Auth', Configure::read('brwAuthConfig')); } else { foreach (Configure::read('brwAuthConfig') as $key => $value) { $Controller->Auth->{$key} = $value; } } App::build(array('views' => ROOT . DS . APP_DIR . DS . 'Plugin' . DS . 'Brownie' . DS . 'View' . DS)); $Controller->helpers[] = 'Js'; $Controller->layout = 'brownie_default'; if (!empty($Controller->modelClass)) { $Controller->{$Controller->modelClass}->attachBackend(); } } if ($this->isBrwPanel) { AuthComponent::$sessionKey = 'Auth.BrwUserLogged'; $this->_menuConfig(); } if (Configure::read('Config.languages')) { $langs3chars = array(); $l10n = new L10n(); foreach ((array) Configure::read('Config.languages') as $lang) { $catalog = $l10n->catalog($lang); $langs3chars[$lang] = $catalog['localeFallback']; } Configure::write('Config.langs', $langs3chars); } }
/** * testCatalog method * * @return void */ public function testCatalog() { $localize = new L10n(); $result = $localize->catalog(array('af')); $expected = array('af' => array('language' => 'Afrikaans', 'locale' => 'afr', 'localeFallback' => 'afr', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ar', 'ar-ae', 'ar-bh', 'ar-dz', 'ar-eg', 'ar-iq', 'ar-jo', 'ar-kw', 'ar-lb', 'ar-ly', 'ar-ma', 'ar-om', 'ar-qa', 'ar-sa', 'ar-sy', 'ar-tn', 'ar-ye')); $expected = array('ar' => array('language' => 'Arabic', 'locale' => 'ara', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-ae' => array('language' => 'Arabic (U.A.E.)', 'locale' => 'ar_ae', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-bh' => array('language' => 'Arabic (Bahrain)', 'locale' => 'ar_bh', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-dz' => array('language' => 'Arabic (Algeria)', 'locale' => 'ar_dz', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-eg' => array('language' => 'Arabic (Egypt)', 'locale' => 'ar_eg', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-iq' => array('language' => 'Arabic (Iraq)', 'locale' => 'ar_iq', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-jo' => array('language' => 'Arabic (Jordan)', 'locale' => 'ar_jo', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-kw' => array('language' => 'Arabic (Kuwait)', 'locale' => 'ar_kw', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-ly' => array('language' => 'Arabic (Libya)', 'locale' => 'ar_ly', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-ma' => array('language' => 'Arabic (Morocco)', 'locale' => 'ar_ma', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-om' => array('language' => 'Arabic (Oman)', 'locale' => 'ar_om', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-qa' => array('language' => 'Arabic (Qatar)', 'locale' => 'ar_qa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-sa' => array('language' => 'Arabic (Saudi Arabia)', 'locale' => 'ar_sa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-sy' => array('language' => 'Arabic (Syria)', 'locale' => 'ar_sy', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-tn' => array('language' => 'Arabic (Tunisia)', 'locale' => 'ar_tn', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('be')); $expected = array('be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('bg')); $expected = array('bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('bs')); $expected = array('bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ca')); $expected = array('ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('cs')); $expected = array('cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('da')); $expected = array('da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('de', 'de-at', 'de-ch', 'de-de', 'de-li', 'de-lu')); $expected = array('de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('el')); $expected = array('el' => array('language' => 'Greek', 'locale' => 'ell', 'localeFallback' => 'ell', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('en', 'en-au', 'en-bz', 'en-ca', 'en-gb', 'en-ie', 'en-jm', 'en-nz', 'en-tt', 'en-us', 'en-za')); $expected = array('en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-ca' => array('language' => 'English (Canadian)', 'locale' => 'en_ca', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-ie' => array('language' => 'English (Ireland)', 'locale' => 'en_ie', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-jm' => array('language' => 'English (Jamaica)', 'locale' => 'en_jm', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-tt' => array('language' => 'English (Trinidad)', 'locale' => 'en_tt', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'en-za' => array('language' => 'English (South Africa)', 'locale' => 'en_za', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('es', 'es-ar', 'es-bo', 'es-cl', 'es-co', 'es-cr', 'es-do', 'es-ec', 'es-es', 'es-gt', 'es-hn', 'es-mx', 'es-ni', 'es-pa', 'es-pe', 'es-pr', 'es-py', 'es-sv', 'es-uy', 'es-ve')); $expected = array('es' => array('language' => 'Spanish (Spain - Traditional)', 'locale' => 'spa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-ar' => array('language' => 'Spanish (Argentina)', 'locale' => 'es_ar', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-bo' => array('language' => 'Spanish (Bolivia)', 'locale' => 'es_bo', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-cl' => array('language' => 'Spanish (Chile)', 'locale' => 'es_cl', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-co' => array('language' => 'Spanish (Colombia)', 'locale' => 'es_co', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-cr' => array('language' => 'Spanish (Costa Rica)', 'locale' => 'es_cr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-ec' => array('language' => 'Spanish (Ecuador)', 'locale' => 'es_ec', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-es' => array('language' => 'Spanish (Spain)', 'locale' => 'es_es', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-gt' => array('language' => 'Spanish (Guatemala)', 'locale' => 'es_gt', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-hn' => array('language' => 'Spanish (Honduras)', 'locale' => 'es_hn', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-mx' => array('language' => 'Spanish (Mexican)', 'locale' => 'es_mx', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-ni' => array('language' => 'Spanish (Nicaragua)', 'locale' => 'es_ni', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-pa' => array('language' => 'Spanish (Panama)', 'locale' => 'es_pa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-pe' => array('language' => 'Spanish (Peru)', 'locale' => 'es_pe', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-pr' => array('language' => 'Spanish (Puerto Rico)', 'locale' => 'es_pr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-py' => array('language' => 'Spanish (Paraguay)', 'locale' => 'es_py', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-sv' => array('language' => 'Spanish (El Salvador)', 'locale' => 'es_sv', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('et')); $expected = array('et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('eu')); $expected = array('eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('fa')); $expected = array('fa' => array('language' => 'Farsi', 'locale' => 'fas', 'localeFallback' => 'fas', 'charset' => 'utf-8', 'direction' => 'rtl')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('fi')); $expected = array('fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('fo')); $expected = array('fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('fr', 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'fr-lu')); $expected = array('fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ga')); $expected = array('ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('gd', 'gd-ie')); $expected = array('gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'), 'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('gl')); $expected = array('gl' => array('language' => 'Galician', 'locale' => 'glg', 'localeFallback' => 'glg', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('he')); $expected = array('he' => array('language' => 'Hebrew', 'locale' => 'heb', 'localeFallback' => 'heb', 'charset' => 'utf-8', 'direction' => 'rtl')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('hi')); $expected = array('hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('hr')); $expected = array('hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('hu')); $expected = array('hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('hy')); $expected = array('hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('id')); $expected = array('id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('is')); $expected = array('is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('it', 'it-ch')); $expected = array('it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'), 'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ja')); $expected = array('ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('kk')); $expected = array('kk' => array('language' => 'Kazakh', 'locale' => 'kaz', 'localeFallback' => 'kaz', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ko', 'ko-kp', 'ko-kr')); $expected = array('ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'), 'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'), 'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('koi8-r', 'ru', 'ru-mo')); $expected = array('koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'), 'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('lt')); $expected = array('lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('lv')); $expected = array('lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('mk', 'mk-mk')); $expected = array('mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mkd', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'), 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ms')); $expected = array('ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('mt')); $expected = array('mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('nl', 'nl-be')); $expected = array('nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), 'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog('nl'); $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog('nld'); $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog('dut'); $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog(array('nb')); $expected = array('nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('nn', 'no')); $expected = array('nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'), 'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('pl')); $expected = array('pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('pt', 'pt-br')); $expected = array('pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'), 'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('rm')); $expected = array('rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ro', 'ro-mo')); $expected = array('ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sb')); $expected = array('sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sk')); $expected = array('sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sl')); $expected = array('sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sq')); $expected = array('sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sr')); $expected = array('sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sv', 'sv-fi')); $expected = array('sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('se')); $expected = array('se' => array('language' => 'Sami', 'locale' => 'sme', 'localeFallback' => 'sme', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('th')); $expected = array('th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('tn')); $expected = array('tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('tr')); $expected = array('tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ts')); $expected = array('ts' => array('language' => 'Tsonga', 'locale' => 'tso', 'localeFallback' => 'tso', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('uk')); $expected = array('uk' => array('language' => 'Ukrainian', 'locale' => 'ukr', 'localeFallback' => 'ukr', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ur')); $expected = array('ur' => array('language' => 'Urdu', 'locale' => 'urd', 'localeFallback' => 'urd', 'charset' => 'utf-8', 'direction' => 'rtl')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ve')); $expected = array('ve' => array('language' => 'Venda', 'locale' => 'ven', 'localeFallback' => 'ven', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('vi')); $expected = array('vi' => array('language' => 'Vietnamese', 'locale' => 'vie', 'localeFallback' => 'vie', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('cy')); $expected = array('cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('xh')); $expected = array('xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('yi')); $expected = array('yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('zh', 'zh-cn', 'zh-hk', 'zh-sg', 'zh-tw')); $expected = array('zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'), 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('zu')); $expected = array('zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('en-nz', 'es-do', 'ar-lb', 'zh-hk', 'pt-br')); $expected = array('en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); $result = $localize->catalog(array('eng', 'deu', 'zho', 'rum', 'zul', 'yid')); $expected = array('eng' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'deu' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zho' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'rum' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zul' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr'), 'yid' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr')); $this->assertEquals($expected, $result); }
/** * 言語データタイプを取得 * * @return array DataTypes配列 */ public function getLanguages() { App::uses('L10n', 'I18n'); $L10n = new L10n(); $languages = $this->Language->getLanguage(); $results = array(); foreach ($languages as $lang) { $catalog = $L10n->catalog($lang['Language']['code']); $results[] = array('key' => $lang['Language']['code'], 'name' => __d('m17n', $catalog['language']), 'code' => $lang['Language']['code'], 'language_id' => $lang['Language']['id']); } return $results; }
/** * Set current language * * @param string $lang * @return bool Success */ public static function setLocale($lang = null, $setCookie = false) { $locales = SlConfigure::read('I18n.locales'); if (empty($locales)) { $languages = SlConfigure::read1('I18n.languages'); $langs = array_keys($languages); $locales = array(); $catalogs = array(); if (!$langs) { $langs = array('en'); } App::import('Core', 'l10n'); $l10n = new L10n(); foreach ($langs as $lang_) { $catalog = $l10n->catalog($lang_); if ($catalog) { $catalogs[$lang_] = $catalog; $locales[$lang_] = $catalog['locale']; } } $langs = array_keys($locales); SlConfigure::write('I18n.langs', $langs); SlConfigure::write('I18n.catalogs', $catalogs); SlConfigure::write('I18n.locales', $locales); if (empty($lang)) { $lang = SlCookie::read('I18n.lang'); // guess language based on Accept-Language header if (empty($lang)) { $envLangs = explode(',', env('HTTP_ACCEPT_LANGUAGE')); foreach ($envLangs as $envLang) { list($envLang) = explode(';', $envLang); if (isset($locales[$envLang])) { $lang = $envLang; break; } } if (empty($lang)) { $lang = SlConfigure::read('I18n.lang'); } } // convert locale_id to lang_id $lang_ = array_search($lang, $locales); if ($lang_) { $lang = $lang_; } if (empty($lang) || !isset($locales[$lang])) { $lang = $langs[0]; } } } else { $catalogs = SlConfigure::read('I18n.catalogs'); } if ($lang) { // convert locale_id to lang_id $lang_ = array_search($lang, $locales); if ($lang_) { $lang = $lang_; } if (isset($locales[$lang])) { SlConfigure::write('I18n.lang', $lang); SlConfigure::write('I18n.catalog', $catalogs[$lang]); SlConfigure::write('I18n.locale', $locales[$lang]); Configure::write('Config.language', $locales[$lang]); if ($setCookie) { SlCookie::write('I18n.lang', $lang, false, "+1 year"); } SlConfigure::localeChanged(); return true; } } return false; }