Example #1
0
 function i18n($params, $cache = false)
 {
     if (!is_array($params)) {
         $params = explode('/', trim($params, '/'));
     }
     $this->init();
     $cacheFile = implode(DS, $params);
     $params = $this->normalize($params);
     $jsFile = $this->parseFile($params);
     $lang = $this->parseLang($params);
     $L10n = new L10n();
     if (!$L10n->map($lang)) {
         $lang = null;
     }
     $L10n->get($lang);
     $sourceJsFile = $this->paths['source'] . $jsFile;
     if (file_exists($sourceJsFile)) {
         ob_start();
         include $sourceJsFile;
         $js = ob_get_clean();
         if ($cache) {
             $this->write($cacheFile, $js);
         }
         return $js;
     }
     return false;
 }
 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);
 }
Example #3
0
 /**
  * testMap method
  *
  * @return void
  */
 public function testMap()
 {
     $localize = new L10n();
     $result = $localize->map(array('afr', 'af'));
     $expected = array('afr' => 'af', 'af' => 'afr');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('sqi', 'sq'));
     $expected = array('sqi' => 'sq', 'sq' => 'sqi');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('alb', 'sq'));
     $expected = array('alb' => 'sq', 'sq' => 'sqi');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ara', 'ar'));
     $expected = array('ara' => 'ar', 'ar' => 'ara');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('hye', 'hy'));
     $expected = array('hye' => 'hy', 'hy' => 'hye');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('eus', 'eu'));
     $expected = array('eus' => 'eu', 'eu' => 'eus');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('baq', 'eu'));
     $expected = array('baq' => 'eu', 'eu' => 'eus');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('bos', 'bs'));
     $expected = array('bos' => 'bs', 'bs' => 'bos');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('bul', 'bg'));
     $expected = array('bul' => 'bg', 'bg' => 'bul');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('bel', 'be'));
     $expected = array('bel' => 'be', 'be' => 'bel');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('cat', 'ca'));
     $expected = array('cat' => 'ca', 'ca' => 'cat');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('chi', 'zh'));
     $expected = array('chi' => 'zh', 'zh' => 'zho');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('zho', 'zh'));
     $expected = array('zho' => 'zh', 'zh' => 'zho');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('hrv', 'hr'));
     $expected = array('hrv' => 'hr', 'hr' => 'hrv');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ces', 'cs'));
     $expected = array('ces' => 'cs', 'cs' => 'ces');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('cze', 'cs'));
     $expected = array('cze' => 'cs', 'cs' => 'ces');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('dan', 'da'));
     $expected = array('dan' => 'da', 'da' => 'dan');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('dut', 'nl'));
     $expected = array('dut' => 'nl', 'nl' => 'nld');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('nld', 'nl'));
     $expected = array('nld' => 'nl', 'nl' => 'nld');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('nld'));
     $expected = array('nld' => 'nl');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('dut'));
     $expected = array('dut' => 'nl');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('eng', 'en'));
     $expected = array('eng' => 'en', 'en' => 'eng');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('est', 'et'));
     $expected = array('est' => 'et', 'et' => 'est');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('fao', 'fo'));
     $expected = array('fao' => 'fo', 'fo' => 'fao');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('fas', 'fa'));
     $expected = array('fas' => 'fa', 'fa' => 'fas');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('per', 'fa'));
     $expected = array('per' => 'fa', 'fa' => 'fas');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('fin', 'fi'));
     $expected = array('fin' => 'fi', 'fi' => 'fin');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('fra', 'fr'));
     $expected = array('fra' => 'fr', 'fr' => 'fra');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('fre', 'fr'));
     $expected = array('fre' => 'fr', 'fr' => 'fra');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('gla', 'gd'));
     $expected = array('gla' => 'gd', 'gd' => 'gla');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('glg', 'gl'));
     $expected = array('glg' => 'gl', 'gl' => 'glg');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('deu', 'de'));
     $expected = array('deu' => 'de', 'de' => 'deu');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ger', 'de'));
     $expected = array('ger' => 'de', 'de' => 'deu');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ell', 'el'));
     $expected = array('ell' => 'el', 'el' => 'gre');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('gre', 'el'));
     $expected = array('gre' => 'el', 'el' => 'gre');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('heb', 'he'));
     $expected = array('heb' => 'he', 'he' => 'heb');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('hin', 'hi'));
     $expected = array('hin' => 'hi', 'hi' => 'hin');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('hun', 'hu'));
     $expected = array('hun' => 'hu', 'hu' => 'hun');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ice', 'is'));
     $expected = array('ice' => 'is', 'is' => 'isl');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('isl', 'is'));
     $expected = array('isl' => 'is', 'is' => 'isl');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ind', 'id'));
     $expected = array('ind' => 'id', 'id' => 'ind');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('gle', 'ga'));
     $expected = array('gle' => 'ga', 'ga' => 'gle');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ita', 'it'));
     $expected = array('ita' => 'it', 'it' => 'ita');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('jpn', 'ja'));
     $expected = array('jpn' => 'ja', 'ja' => 'jpn');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('kaz', 'kk'));
     $expected = array('kaz' => 'kk', 'kk' => 'kaz');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('kor', 'ko'));
     $expected = array('kor' => 'ko', 'ko' => 'kor');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('lav', 'lv'));
     $expected = array('lav' => 'lv', 'lv' => 'lav');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('lit', 'lt'));
     $expected = array('lit' => 'lt', 'lt' => 'lit');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('mac', 'mk'));
     $expected = array('mac' => 'mk', 'mk' => 'mkd');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('mkd', 'mk'));
     $expected = array('mkd' => 'mk', 'mk' => 'mkd');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('may', 'ms'));
     $expected = array('may' => 'ms', 'ms' => 'msa');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('msa', 'ms'));
     $expected = array('msa' => 'ms', 'ms' => 'msa');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('mlt', 'mt'));
     $expected = array('mlt' => 'mt', 'mt' => 'mlt');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('nor', 'no'));
     $expected = array('nor' => 'no', 'no' => 'nor');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('nob', 'nb'));
     $expected = array('nob' => 'nb', 'nb' => 'nob');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('nno', 'nn'));
     $expected = array('nno' => 'nn', 'nn' => 'nno');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('pol', 'pl'));
     $expected = array('pol' => 'pl', 'pl' => 'pol');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('por', 'pt'));
     $expected = array('por' => 'pt', 'pt' => 'por');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('roh', 'rm'));
     $expected = array('roh' => 'rm', 'rm' => 'roh');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ron', 'ro'));
     $expected = array('ron' => 'ro', 'ro' => 'ron');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('rum', 'ro'));
     $expected = array('rum' => 'ro', 'ro' => 'ron');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('rus', 'ru'));
     $expected = array('rus' => 'ru', 'ru' => 'rus');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('sme', 'se'));
     $expected = array('sme' => 'se', 'se' => 'sme');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('srp', 'sr'));
     $expected = array('srp' => 'sr', 'sr' => 'srp');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('slk', 'sk'));
     $expected = array('slk' => 'sk', 'sk' => 'slk');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('slo', 'sk'));
     $expected = array('slo' => 'sk', 'sk' => 'slk');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('slv', 'sl'));
     $expected = array('slv' => 'sl', 'sl' => 'slv');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('wen', 'sb'));
     $expected = array('wen' => 'sb', 'sb' => 'wen');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('spa', 'es'));
     $expected = array('spa' => 'es', 'es' => 'spa');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('swe', 'sv'));
     $expected = array('swe' => 'sv', 'sv' => 'swe');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('tha', 'th'));
     $expected = array('tha' => 'th', 'th' => 'tha');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('tso', 'ts'));
     $expected = array('tso' => 'ts', 'ts' => 'tso');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('tsn', 'tn'));
     $expected = array('tsn' => 'tn', 'tn' => 'tsn');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('tur', 'tr'));
     $expected = array('tur' => 'tr', 'tr' => 'tur');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ukr', 'uk'));
     $expected = array('ukr' => 'uk', 'uk' => 'ukr');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('urd', 'ur'));
     $expected = array('urd' => 'ur', 'ur' => 'urd');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('ven', 've'));
     $expected = array('ven' => 've', 've' => 'ven');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('vie', 'vi'));
     $expected = array('vie' => 'vi', 'vi' => 'vie');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('xho', 'xh'));
     $expected = array('xho' => 'xh', 'xh' => 'xho');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('cy', 'cym'));
     $expected = array('cym' => 'cy', 'cy' => 'cym');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('yid', 'yi'));
     $expected = array('yid' => 'yi', 'yi' => 'yid');
     $this->assertEquals($expected, $result);
     $result = $localize->map(array('zul', 'zu'));
     $expected = array('zul' => 'zu', 'zu' => 'zul');
     $this->assertEquals($expected, $result);
 }
Example #4
0
File: i18n.php Project: ntung/i18n
/**
 * Returns the correct image from the language code
 * 
 * @param string $lang Long language code
 * @param array $options Options with the following possible keys
 * 	- basePath: Base path for the flag images, with a trailing slash
 * @return string Image markup
 */
	public function flagImage($lang, $options = array()) {
		static $L10n = null;
		if (is_null($L10n)) {
			App::import('Core', 'L10n');
			$L10n = new L10n();
		}
		$_defaults = array('basePath' => $this->basePath);
		$options = array_merge($_defaults, $options);
		return $this->Html->image($options['basePath'] . $L10n->map($lang) . '.png');
	}
Example #5
0
 /**
  * Returns a 2 letters language code compatible with Google Translate
  * 
  * @param string $langCode Language code to convert
  * @return Two letters language code
  */
 protected function _twoLettersCode($langCode)
 {
     static $L10n = null;
     if (strlen($langCode) == 3) {
         if (is_null($L10n)) {
             App::import('Core', 'L10n');
             $L10n = new L10n();
         }
         $langCode = $L10n->map($langCode);
     }
     return $langCode;
 }
Example #6
0
 /**
  * quicklinks: clear, today, ...
  *
  * @return void
  */
 public function dateScripts($scripts = [], $quicklinks = false)
 {
     foreach ($scripts as $script) {
         if (!$this->scriptsAdded[$script]) {
             switch ($script) {
                 case 'date':
                     $lang = Configure::read('Config.language');
                     if (strlen($lang) !== 2) {
                         App::uses('L10n', 'I18n');
                         $Localization = new L10n();
                         $lang = $Localization->map($lang);
                     }
                     if (strlen($lang) !== 2) {
                         $lang = 'en';
                     }
                     if ($this->settings['webroot']) {
                         $this->Html->script('datepicker/lang/' . $lang, ['inline' => false]);
                         $this->Html->script('datepicker/datepicker', ['inline' => false]);
                         $this->Html->css('common/datepicker', ['inline' => false]);
                     } else {
                         $this->Common->script(['ToolsExtra.Asset|datepicker/lang/' . $lang, 'ToolsExtra.Asset|datepicker/datepicker'], ['inline' => false]);
                         $this->Common->css(['ToolsExtra.Asset|datepicker/datepicker'], ['inline' => false]);
                     }
                     $this->scriptsAdded['date'] = true;
                     break;
                 case 'time':
                     continue;
                     if ($this->settings['webroot']) {
                     } else {
                         //'ToolsExtra.Jquery|ui/core/jquery.ui.core', 'ToolsExtra.Jquery|ui/core/jquery.ui.widget', 'ToolsExtra.Jquery|ui/widgets/jquery.ui.slider',
                         $this->Common->script(['ToolsExtra.Jquery|plugins/jquery.timepicker.core', 'ToolsExtra.Jquery|plugins/jquery.timepicker'], ['inline' => false]);
                         $this->Common->css(['ToolsExtra.Jquery|ui/core/jquery.ui', 'ToolsExtra.Jquery|plugins/jquery.timepicker'], ['inline' => false]);
                     }
                     break;
                 default:
                     break;
             }
             if ($quicklinks) {
             }
         }
     }
 }
Example #7
0
 *
 * This plugin's Example component will be loaded in ALL controllers.
 */
Croogo::hookComponent('*', 'Example.Example');
/**
 * Helper
 *
 * This plugin's Example helper will be loaded via NodesController.
 */
Croogo::hookHelper('Nodes', 'Example.Example');
/**
 * Admin menu (navigation)
 */
CroogoNav::add('sidebar', 'extensions.children.example', array('title' => 'Example', 'url' => '#', 'children' => array('example1' => array('title' => 'Example 1', 'url' => array('admin' => true, 'plugin' => 'example', 'controller' => 'example', 'action' => 'index')), 'example2' => array('title' => 'Example 2 with a title that won\'t fit in the sidebar', 'url' => '#', 'children' => array('example-2-1' => array('title' => 'Example 2-1', 'url' => '#', 'children' => array('example-2-1-1' => array('title' => 'Example 2-1-1', 'url' => '#', 'children' => array('example-2-1-1-1' => array('title' => 'Example 2-1-1-1'))))))), 'example3' => array('title' => 'Chooser Example', 'url' => array('admin' => true, 'plugin' => 'example', 'controller' => 'example', 'action' => 'chooser')), 'example4' => array('title' => 'RTE Example', 'url' => array('admin' => true, 'plugin' => 'example', 'controller' => 'example', 'action' => 'rte_example')))));
$Localization = new L10n();
Croogo::mergeConfig('Wysiwyg.actions', array('Example/admin_rte_example' => array(array('elements' => 'ExampleBasic', 'preset' => 'basic'), array('elements' => 'ExampleStandard', 'preset' => 'standard', 'language' => 'ja'), array('elements' => 'ExampleFull', 'preset' => 'full', 'language' => $Localization->map(Configure::read('Site.locale'))), array('elements' => 'ExampleCustom', 'toolbar' => array(array('Format', 'Bold', 'Italic'), array('Copy', 'Paste')), 'uiColor' => '#ffe79a', 'language' => 'fr'))));
/**
 * Admin row action
 *
 * When browsing the content list in admin panel (Content > List),
 * an extra link called 'Example' will be placed under 'Actions' column.
 */
Croogo::hookAdminRowAction('Nodes/admin_index', 'Example', 'plugin:example/controller:example/action:index/:id');
/* Row action with link options */
Croogo::hookAdminRowAction('Nodes/admin_index', 'Button with Icon', array('plugin:example/controller:example/action:index/:id' => array('options' => array('icon' => 'key', 'button' => 'success'))));
/* Row action with icon */
Croogo::hookAdminRowAction('Nodes/admin_index', 'Icon Only', array('plugin:example/controller:example/action:index/:id' => array('title' => false, 'options' => array('icon' => 'picture', 'tooltip' => array('data-title' => 'A nice and simple action with tooltip', 'data-placement' => 'left')))));
/* Row action with confirm message */
Croogo::hookAdminRowAction('Nodes/admin_index', 'Reload Page', array('admin:true/plugin:nodes/controller:nodes/action:index' => array('title' => false, 'options' => array('icon' => 'refresh', 'tooltip' => 'Reload page'), 'confirmMessage' => 'Reload this page?')));
/**
 * Admin tab