translate() public static method

Used by the translation functions in basics.php Returns a translated string based on current language and translation files stored in locale folder
public static translate ( string $singular, string $plural = null, string $domain = null, string $category = self::LC_MESSAGES, integer $count = null, string $language = null, string $context = null ) : string
$singular string String to translate
$plural string Plural string (if any)
$domain string Domain The domain of the translation. Domains are often used by plugin translations. If null, the default domain will be used.
$category string Category The integer value of the category to use.
$count integer Count Count is used with $plural to choose the correct plural form.
$language string Language to translate string to. If null it checks for language in session followed by Config.language configuration variable.
$context string Context The context of the translation, e.g a verb or a noun.
return string translated string.
コード例 #1
0
 function testTranslationCaching()
 {
     Configure::write('Config.language', 'cache_test_po');
     $i18n =& i18n::getInstance();
     // reset internally stored entries
     I18n::clear();
     Cache::clear(false, '_cake_core_');
     $lang = Configure::read('Config.language');
     #$i18n->l10n->locale;
     Cache::config('_cake_core_', Cache::config('default'));
     // make some calls to translate using different domains
     $this->assertEqual(I18n::translate('dom1.foo', false, 'dom1'), 'Dom 1 Foo');
     $this->assertEqual(I18n::translate('dom1.bar', false, 'dom1'), 'Dom 1 Bar');
     $this->assertEqual($i18n->__domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo'], 'Dom 1 Foo');
     // reset internally stored entries
     I18n::clear();
     // now only dom1 should be in cache
     $cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
     $this->assertEqual($cachedDom1['LC_MESSAGES']['dom1.foo'], 'Dom 1 Foo');
     $this->assertEqual($cachedDom1['LC_MESSAGES']['dom1.bar'], 'Dom 1 Bar');
     // dom2 not in cache
     $this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
     // translate a item of dom2 (adds dom2 to cache)
     $this->assertEqual(I18n::translate('dom2.foo', false, 'dom2'), 'Dom 2 Foo');
     // verify dom2 was cached through manual read from cache
     $cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
     $this->assertEqual($cachedDom2['LC_MESSAGES']['dom2.foo'], 'Dom 2 Foo');
     $this->assertEqual($cachedDom2['LC_MESSAGES']['dom2.bar'], 'Dom 2 Bar');
     // modify cache entry manually to verify that dom1 entries now will be read from cache
     $cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO';
     Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
     $this->assertEqual(I18n::translate('dom1.foo', false, 'dom1'), 'FOO');
 }
コード例 #2
0
ファイル: i18n.test.php プロジェクト: kaz0636/openflp
 function testPlural()
 {
     $result = I18n::translate('chair', 'chairs', null, 5, 1, $this->dir);
     $this->assertEqual($result, 'chair');
     $result = I18n::translate('chair', 'chairs', null, 5, 2, $this->dir);
     $this->assertEqual($result, 'chairs');
     $data['count'] = 1;
     $result = I18n::translate('chair', 'chairs', null, 5, $data['count'], $this->dir);
     $this->assertEqual($result, 'chair');
     $data['count'] = 8;
     $result = I18n::translate('chair', 'chairs', null, 5, $data['count'], $this->dir);
     $this->assertEqual($result, 'chairs');
 }
コード例 #3
0
 public function run()
 {
     DB::table('navigations')->delete();
     $title1 = new I18n();
     $title1->i18n_type_id = I18nType::where('name', '=', 'title')->first()->id;
     $title1->save();
     $title1->translate('fr', 'Accueil');
     $title1->translate('en', 'Home');
     $title7 = new I18n();
     $title7->i18n_type_id = I18nType::where('name', '=', 'title')->first()->id;
     $title7->save();
     $title7->translate('fr', 'Contact');
     $title7->translate('en', 'Contact');
     DB::table('navigations')->insert(array(array('i18n_title' => $title1->id, 'parent_id' => 0, 'order' => 1, 'navigable_id' => 1, 'navigable_type' => 'Page'), array('i18n_title' => $title7->id, 'parent_id' => 0, 'order' => 2, 'navigable_id' => 2, 'navigable_type' => 'Page')));
     //Admin navigation group
     DB::table('admin_navigation_groups')->delete();
     $adminNav1 = I18n::add(array('fr' => 'Racine', 'en' => 'Root'), 'key', 'admin.admin_navigation_root');
     $adminNav2 = I18n::add(array('fr' => 'Gestion des contenus', 'en' => 'Content managment'), 'key', 'admin.admin_navigation_content');
     $adminNav3 = I18n::add(array('fr' => 'Gestion des utilisateurs', 'en' => 'User managment'), 'key', 'admin.admin_navigation_user');
     $adminNav4 = I18n::add(array('fr' => 'Traduction', 'en' => 'Translation'), 'key', 'admin.admin_navigation_translation');
     $adminNav5 = I18n::add(array('fr' => 'Option', 'en' => 'Option'), 'key', 'admin.admin_navigation_option');
     DB::table('admin_navigation_groups')->insert(array(array('i18n_title' => $adminNav1, 'parent_id' => 0, 'order' => 0, 'deletable' => false), array('i18n_title' => $adminNav2, 'parent_id' => 0, 'order' => 1, 'deletable' => true), array('i18n_title' => $adminNav3, 'parent_id' => 0, 'order' => 2, 'deletable' => true), array('i18n_title' => $adminNav4, 'parent_id' => 0, 'order' => 3, 'deletable' => true), array('i18n_title' => $adminNav5, 'parent_id' => 0, 'order' => 4, 'deletable' => true)));
 }
コード例 #4
0
ファイル: BaseModel.php プロジェクト: titaphp/test-app
 public function validate($rules = null)
 {
     $validator = new Validator();
     foreach ($this->rules as $rule) {
         $fields = explode(',', str_replace(' ', '', $rule[0]));
         foreach ($fields as $field) {
             count($rule) == 4 ? $validator->add($field, $rule[1], $rule[2], \I18n::translate($rule[3]), $this->label($field)) : $validator->add($field, $rule[1], [], \I18n::translate($rule[2]), $this->label($field));
         }
     }
     if (!$validator->validate($this->getAttributes())) {
         $messages = $validator->getMessages();
         foreach ($messages as $message) {
             foreach ($message as $error) {
                 $this->errors[] = (string) $error;
             }
         }
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: app_paginator.php プロジェクト: slywalker/vendors
 public function sort($title, $key = null, $options = array())
 {
     if (empty($key)) {
         $key = $this->Paginator->defaultModel() . '.' . $title;
         $title = preg_replace('/_id$/', '', $title);
         if (!class_exists('I18n')) {
             App::import('Core', 'i18n');
         }
         $title = I18n::translate(Inflector::humanize($title));
     }
     if (false === strpos($key, '.')) {
         $key = $this->Paginator->defaultModel() . '.' . $key;
     }
     $sortKey = $this->Paginator->sortKey();
     $sortDir = $this->Paginator->sortDir();
     if ($key === $sortKey) {
         $title .= $sortDir === 'asc' ? '<span class="asc">↑</span>' : '<span class="desc">↓</span>';
         $options = am($options, array('escape' => false));
     }
     return $this->Paginator->sort($title, $key, $options);
 }
コード例 #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array();
     $tag_name_datas = array();
     foreach (Input::except('_token') as $k => $v) {
         if (strpos($k, 'tag_name_') !== false) {
             $rules[$k] = Config::get('validator.admin.tag.name');
             $tag_name_datas[mb_substr($k, strlen('tag_name_'), strlen($k) - strpos($k, 'tag_name_'))] = $v;
         }
     }
     //return var_dump($tag_name_datas);
     // Validate the inputs
     $validator = Validator::make(Input::except('_token'), $rules);
     if ($validator->passes()) {
         //create i18n key
         $i18n_name = new I18n();
         $i18n_name->i18n_type_id = I18nType::where('name', '=', 'tag')->first()->id;
         $i18n_name->save();
         foreach ($tag_name_datas as $locale => $value) {
             if (!$i18n_name->translate($locale, $value)) {
                 return Redirect::to('admin/tag')->with('error', Lang::get('admin.tag_save_fail'));
             }
         }
         $tag = new Tag();
         $tag->i18n_name = $i18n_name->id;
         // Was the blog post created?
         if ($tag->save()) {
             //track user
             parent::track('create', 'Tag', $tag->id);
             return Redirect::to('admin/tag')->with('success', Lang::get('admin.tag_save_success'));
         }
         // Redirect to the blog post create tag
         return Redirect::to('admin/tag/create')->with('error', Lang::get('admin.tag_save_fail'));
     }
     // Form validation failed
     return Redirect::to('admin/tag/create')->withInput()->withErrors($validator);
 }
コード例 #7
0
ファイル: i18n-test.php プロジェクト: hmmbug/unbindery
<?php

include '../../lib/sfYaml/sfYaml.php';
include '../I18n.php';
echo "Testing English...\n\n";
$i18n = new I18n('../../translations', 'en');
echo "login.username: "******"\n";
echo "dashboard.top_proofers: " . $i18n->translate('dashboard.top_proofers') . "\n";
echo "footer.text: " . $i18n->translate('footer.text') . "\n";
echo "\nTesting faux Spanish...\n\n";
$i18n = new I18n('../../translations', 'es');
echo "login.username: "******"\n";
echo "dashboard.top_proofers: " . $i18n->translate('dashboard.top_proofers') . "\n";
echo "footer.text: " . $i18n->translate('footer.text') . "\n";
echo "\nTesting a key that doesn't exist...\n\n";
echo "supercalifragilisticexpialidocious: " . $i18n->translate('supercalifragilisticexpialidocious') . "\n";
コード例 #8
0
ファイル: TableHelper.php プロジェクト: gourmet/common
 /**
  * Replace translatable strings by their translated values.
  *
  * Examples:
  *  - [__]Translate this[/__]
  *  - [__d|domain]Translate this[/__d]
  *  - [__c|category]Translate this[/__c]
  *
  * @param string $str String to check and modify.
  * @return string Modified string.
  */
 protected function _replaceTranslate($str)
 {
     // [__]Text to translate[/__]
     if (preg_match_all('/\\[__\\](.*?)\\[\\/__\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[1][$i]), $str);
         }
     }
     // [__d|domain]Text to translate[/__d]
     if (preg_match_all('/\\[__d\\|(.+?)\\](.*?)\\[\\/__d\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
         }
     }
     // [__c|category]Text to translate[/__c]
     if (preg_match_all('/\\[__c\\|(.+?)\\](.*?)\\[\\/__c\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
         }
     }
     return $str;
 }
コード例 #9
0
ファイル: basics.php プロジェクト: mrbadao/api-official
 /**
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
  *
  * Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
  *
  * - LC_ALL       I18n::LC_ALL
  * - LC_COLLATE   I18n::LC_COLLATE
  * - LC_CTYPE     I18n::LC_CTYPE
  * - LC_MONETARY  I18n::LC_MONETARY
  * - LC_NUMERIC   I18n::LC_NUMERIC
  * - LC_TIME      I18n::LC_TIME
  * - LC_MESSAGES  I18n::LC_MESSAGES
  *
  * @param string $context  Context of the text
  * @param string $msg      String to translate
  * @param int    $category Category
  * @param mixed  $args     Array with arguments or multiple arguments in function, otherwise null.
  *
  * @return string translated string
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
  */
 function __xc($context, $msg, $category, $args = NULL)
 {
     if (!$msg) {
         return NULL;
     }
     App::uses('I18n', 'I18n');
     $translated = I18n::translate($msg, NULL, NULL, $category, NULL, NULL, $context);
     $arguments = func_get_args();
     return I18n::insertArgs($translated, array_slice($arguments, 3));
 }
コード例 #10
0
ファイル: functions.php プロジェクト: chroda/lolcollector
function __t($_query = false, $_ordering = array('en', 'es', 'pt'))
{
    if (file_exists(__CONTROLLERS_DIR__ . 'I18n.php')) {
        require_once __CONTROLLERS_DIR__ . 'I18n.php';
        $_translator = new I18n($_ordering);
        if ($_query == false) {
            return 'Please insert a query';
        }
        return $_translator->translate($_query);
    } else {
        return 'ERROR - Class I18n not found';
    }
}
コード例 #11
0
 /**
  * @return string
  */
 public function title()
 {
     return I18n::translate('common/script/' . strtolower($this->m_name));
 }
コード例 #12
0
 function printErrors($includeSubPanels_ = true, $expandThreshold_ = 4)
 {
     $errors = $this->errors($includeSubPanels_);
     if (1 > ($count = $this->countErrors($includeSubPanels_))) {
         return;
     }
     // TODO Localize ...
     printf('
     <div class="ui_panel_errors">
       <div class="ui_panel_disclosure_header">
         <h2 class="title">%2$s (%3$s)</h2>
         <a href="javascript:void(0);" rel="%1$s-errors" class="ui_panel_disclosure_toggle%4$s">collapse</a>
       </div>', $this->id(), \html\escape(I18n::translate('ui/panel/errors/title')), $count, $count > $expandThreshold_ ? '' : ' expanded');
     printf('<ul id="%1$s-errors" class="ui_panel_errors">', $this->id());
     foreach ($errors as $panelId => $value) {
         if ($includeSubPanels_) {
             if (!($title = $value['panel']->title)) {
                 $title = $value['panel']->name;
             }
             printf('<li class="ui_panel_error_category"><label for="%1$s">%2$s</label><ul>', $value['panel']->id(), \html\escape($title));
         }
         foreach ($value['errors'] as $error) {
             printf('<li class="ui_panel_error"><label for="%1$s">%2$s</label></li>', $value['panel']->id(), \html\escape($error['message']));
         }
         if ($includeSubPanels_) {
             echo '</ul></li>';
         }
     }
     echo '</ul></div>';
 }
コード例 #13
0
ファイル: index.php プロジェクト: suga/Megiddo
<?php

Template::includeTemplate('Default', 'Head.php');
echo '<br>' . I18n::translate('no.layout.test', $var->culture) . '<br>';
echo time();
var_dump($var->var1);
var_dump($var->var2);
var_dump($var->var3);
var_dump($var->var4);
var_dump($var->var5, $var->var6);
var_dump($var->var7);
var_dump($var->var8);
var_dump($var->var9);
var_dump($var->var10);
コード例 #14
0
/**
 * The category argument allows a specific category of the locale settings to be used for fetching a message.
 * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
 *
 * Note that the category must be specified with a numeric value, instead of the constant name.  The values are:
 * LC_CTYPE     0
 * LC_NUMERIC   1
 * LC_TIME      2
 * LC_COLLATE   3
 * LC_MONETARY  4
 * LC_MESSAGES  5
 * LC_ALL       6
 *
 * @param string $msg String to translate
 * @param integer $category Category
 * @param string $return true to return, false to echo
 * @return translated string if $return is false string will be echoed
 */
function __c($msg, $category, $return = false)
{
    if (!class_exists('I18n')) {
        uses('i18n');
    }
    $calledFrom = debug_backtrace();
    $dir = dirname($calledFrom[0]['file']);
    unset($calledFrom);
    if ($return === false) {
        echo I18n::translate($msg, null, null, $category, null, $dir);
    } else {
        return I18n::translate($msg, null, null, $category, null, $dir);
    }
}
コード例 #15
0
ファイル: I18nTest.php プロジェクト: kuradakis/cakephp-ex
 /**
  * Test that the '' domain causes exceptions.
  *
  * @expectedException CakeException
  * @return void
  */
 public function testTranslateEmptyDomain()
 {
     I18n::translate('Plural Rule 1', null, '');
 }
コード例 #16
0
 /**
  * Store all type of menu, parent, child internal or external link and button
  *
  * @return Response
  */
 public function store()
 {
     $rules = array();
     $navigation_title_datas = array();
     foreach (Input::except('_token') as $k => $v) {
         if (strpos($k, 'navigation_title_') !== false) {
             $rules[$k] = Config::get('validator.admin.navigation_title.title');
             $navigation_title_datas[mb_substr($k, strlen('navigation_title_'), strlen($k) - strpos($k, 'navigation_title_'))] = $v;
         }
     }
     $rules = array_merge($rules, Config::get('validator.admin.navigation'));
     //return var_dump($rules);
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         //create i18n key
         $i18n_title = new I18n();
         $i18n_title->i18n_type_id = I18nType::where('name', '=', 'navigation')->first()->id;
         $i18n_title->save();
         foreach ($navigation_title_datas as $locale => $value) {
             if (!$i18n_title->translate($locale, $value)) {
                 return Redirect::to('admin/navigation')->with('error', Lang::get('admin.navigation_save_fail'));
             }
         }
         $navigation = new Nav();
         $navigation->i18n_title = $i18n_title->id;
         if (Input::has('parent_id')) {
             $navigation->parent_id = Input::get('parent_id');
         } else {
             $navigation->parent_id = 0;
         }
         //There case : external link, internal link and link container (button)
         if (Input::has('url_external')) {
             //create a link and put the id in the navigable_id :)
             $nav_link = new NavLink();
             $nav_link->url = Input::get('url_external');
             $nav_link->save();
             $navigation->navigable_id = $nav_link->id;
             $navigation->navigable_type = 'NavLink';
         }
         if (Input::has('model_resource_id')) {
             $result_explode = explode('|', Input::get('model_resource_id'));
             $navigation->navigable_id = $result_explode[1];
             $navigation->navigable_type = $result_explode[0];
         }
         if (!Input::has('url_external') && !Input::has('model_resource_id')) {
             $nav_link = new NavLink();
             $nav_link->url = '#';
             $nav_link->save();
             $navigation->navigable_id = $nav_link->id;
             $navigation->navigable_type = 'NavLink';
         }
         if (Input::has('order')) {
             $navigation->order = Input::get('order');
         } else {
             $navigation->order = Nav::max() + 1;
         }
         // Was the blog post created?
         if ($navigation->save()) {
             //track user
             parent::track('create', 'Navigation', $navigation->id);
             Cache::forget('DB_Nav');
             // Redirect to the new blog post menu
             return Redirect::to('admin/navigation')->with('success', 'Le menu à bien été ajouté !');
         }
         // Redirect to the blog post create menu
         return Redirect::to('admin/navigation/create')->with('error', 'Le menu n\'a pas pu être enregistrée...');
     }
     // Form validation failed
     return Redirect::to('admin/navigation/create')->withInput()->withErrors($validator);
 }
コード例 #17
0
ファイル: Estado.php プロジェクト: Leo137/libredte-lib
 /**
  * Método que recupera la glosa del estado
  * @param codigo Código del error que se desea recuperar
  * @param args Argumentos que se usarán para reemplazar "máscaras" en glosa
  * @return Glosa del estado si existe o bien el mismo código del estado si no hay glosa
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
  * @version 2015-09-24
  */
 public static function get($codigo, $args = null)
 {
     // si no hay glosa asociada al código se entrega el mismo código
     if (!isset(self::$glosas[(int) $codigo])) {
         return (int) $codigo;
     }
     // si los argumentos no son un arreglo se obtiene arreglo a partir
     // de los argumentos pasados a la función
     if (!is_array($args)) {
         $args = array_slice(func_get_args(), 1);
     }
     // entregar glosa
     return vsprintf(I18n::translate(self::$glosas[(int) $codigo], 'estados'), $args);
 }
コード例 #18
0
 /**
  * Replace validation error messages for i18n
  *
  * @access public
  * @return void
  */
 function replaceValidationMessages(&$model)
 {
     $validate = $model->validate;
     // 再構築するために初期化
     $model->validate = array();
     foreach ($validate as $fieldName => $ruleSet) {
         if (!is_array($ruleSet) || is_array($ruleSet) && isset($ruleSet['rule'])) {
             $ruleSet = array($ruleSet);
         }
         foreach ($ruleSet as $index => $validator) {
             if (!is_array($validator)) {
                 $validator = array('rule' => $validator);
             }
             // 再構築
             if (!isset($model->validate[$fieldName])) {
                 $model->validate[$fieldName] = array();
             }
             $model->validate[$fieldName][$index] = $validator;
             // ルールとパラメータを分割
             if (is_array($validator['rule'])) {
                 $rule = $validator['rule'][0];
                 unset($validator['rule'][0]);
                 $ruleParams = array_values($validator['rule']);
             } else {
                 $rule = $validator['rule'];
                 $ruleParams = array();
             }
             $messages = $this->messages;
             $errorMessage = array_key_exists($rule, $messages) ? $messages[$rule] : null;
             if (!empty($errorMessage)) {
                 if ($rule === 'multiple') {
                     $min = null;
                     $max = null;
                     if (isset($ruleParams[0]['min'])) {
                         $min = $ruleParams[0]['min'];
                     }
                     if (isset($ruleParams[0]['max'])) {
                         $max = $ruleParams[0]['max'];
                     }
                     $ruleParams = array($min, $max);
                 }
                 if ($rule === 'checkCompare') {
                     $ruleParams = array(I18n::translate(Inflector::humanize($fieldName . $ruleParams[0])));
                 }
                 $errorMessage = vsprintf($errorMessage, $ruleParams);
             } elseif (!empty($model->validate[$fieldName][$index]['message'])) {
                 $errorMessage = $model->validate[$fieldName][$index]['message'];
             }
             if ($this->settings[$model->alias]['fieldName'] && !empty($errorMessage)) {
                 $errorMessage = I18n::translate(Inflector::humanize($fieldName)) . $this->settings[$model->alias]['separator'] . $errorMessage;
             }
             $model->validate[$fieldName][$index]['message'] = $errorMessage;
         }
     }
 }
コード例 #19
0
ファイル: searchable.php プロジェクト: kevthunder/cake-search
 function _translate($lang, $singular, $plural = null, $domain = null, $category = 6, $count = null)
 {
     $curLang = Configure::read('Config.language');
     Configure::write('Config.language', $lang);
     if (!class_exists('I18n')) {
         App::import('Core', 'i18n');
     }
     $res = I18n::translate($singular, $plural = null, $domain = null, $category = 6, $count);
     Configure::write('Config.language', $curLang);
     return $res;
 }
コード例 #20
0
 private function getKeywords()
 {
     $rootKeywordName = Configure::read('rootKeywordName');
     $root = $this->Keyword->findByName($rootKeywordName);
     $keywords = $this->getAllSubKeywords($root['Keyword']['modelId']);
     $fh = fopen("Locale" . DS . "default.pot", 'w');
     fwrite($fh, "# LANGUAGE translation of https://github.com/theus77/Aperture2Global\n");
     fwrite($fh, "# Copyright 2015 Theus Deka <*****@*****.**>\n");
     fwrite($fh, "#\n");
     fwrite($fh, "#, fuzzy\n");
     fwrite($fh, "msgid \"\"\n");
     fwrite($fh, "msgstr \"\"\n");
     fwrite($fh, "\"Project-Id-Version: Aperture2Global\\n\"\n");
     fwrite($fh, "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n");
     fwrite($fh, "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n");
     fwrite($fh, "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n");
     fwrite($fh, "\"MIME-Version: 1.0\\n\"\n");
     fwrite($fh, "\"Content-Type: text/plain; charset=utf-8\\n\"\n");
     fwrite($fh, "\"Content-Transfer-Encoding: 8bit\\n\"\n");
     fwrite($fh, "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n");
     foreach ($keywords as $keyword) {
         $key = $keyword['name'];
         $value = $keyword['name'];
         $key = addslashes($key);
         $value = addslashes($value);
         fwrite($fh, "\n");
         fwrite($fh, "#: " . $keyword['modelId'] . "\n");
         fwrite($fh, "msgid \"{$key}\"\n");
         fwrite($fh, "msgstr \"\"\n");
         $keyword = ['modelId' => $keyword['modelId'], 'name' => $keyword['name'], 'uuid' => $keyword['encodedUuid']];
         foreach ($this->languages as $language) {
             $keyword['name_' . $language] = I18n::translate(Normalizer::normalize($keyword['name']), null, null, I18n::LC_MESSAGES, null, $language, null);
         }
         $this->putObjectToElasticSearch($keyword, 'keyword', $keyword['uuid']);
     }
     fwrite($fh, "\n");
     fclose($fh);
     return $keywords;
 }
コード例 #21
0
ファイル: basics.php プロジェクト: robotarmy/Phog
/**
 * The category argument allows a specific category of the locale settings to be used for fetching a message.
 * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
 *
 * Note that the category must be specified with a numeric value, instead of the constant name.  The values are:
 *
 * - LC_ALL       0
 * - LC_COLLATE   1
 * - LC_CTYPE     2
 * - LC_MONETARY  3
 * - LC_NUMERIC   4
 * - LC_TIME      5
 * - LC_MESSAGES  6
 *
 * @param string $msg String to translate
 * @param integer $category Category
 * @param mixed $args Array with arguments or multiple arguments in function
 * @return translated string
 */
function __c($msg, $category, $args = null)
{
    if (!$msg) {
        return;
    }
    if (!class_exists('I18n')) {
        App::import('Core', 'i18n');
    }
    $translated = I18n::translate($msg, null, null, $category);
    if ($args === null) {
        return $translated;
    } elseif (!is_array($args)) {
        $args = array_slice(func_get_args(), 2);
    }
    return vsprintf($translated, $args);
}
コード例 #22
0
ファイル: bootstrap.php プロジェクト: tpobozy/kohana-3.4
 /**
  * I18n translate alias function.
  *
  * @deprecated 3.4 Use I18n::translate() instead
  */
 function __($string, array $values = NULL, $lang = 'en-us')
 {
     return I18n::translate($string, $values, $lang);
 }
コード例 #23
0
ファイル: basics.php プロジェクト: dudasc/site-fescjj
 /**
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
  *
  * Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
  *
  * - LC_ALL       I18n::LC_ALL
  * - LC_COLLATE   I18n::LC_COLLATE
  * - LC_CTYPE     I18n::LC_CTYPE
  * - LC_MONETARY  I18n::LC_MONETARY
  * - LC_NUMERIC   I18n::LC_NUMERIC
  * - LC_TIME      I18n::LC_TIME
  * - LC_MESSAGES  I18n::LC_MESSAGES
  *
  * @param string $msg String to translate
  * @param integer $category Category
  * @param mixed $args Array with arguments or multiple arguments in function
  * @return translated string
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
  */
 function __c($msg, $category, $args = null)
 {
     if (!$msg) {
         return;
     }
     App::uses('I18n', 'I18n');
     $translated = I18n::translate($msg, null, null, $category);
     if ($args === null) {
         return $translated;
     } elseif (!is_array($args)) {
         $args = array_slice(func_get_args(), 2);
     }
     $translated = preg_replace('/(?<!%)%(?![%\'\\-+bcdeEfFgGosuxX\\d\\.])/', '%%', $translated);
     return vsprintf($translated, $args);
 }
コード例 #24
0
ファイル: I18nClass.php プロジェクト: quyen91/lfpr
 public static function t($key)
 {
     return I18n::translate($key);
 }
コード例 #25
0
 /**
  * Step 0, Select language. ( change this to index() )
  *
  * @return void
  */
 public function language()
 {
     App::uses('I18n', 'I18n');
     if (isset($this->params['named']['lang']) && preg_match('/^[a-z]{3}$/', $this->params['named']['lang'])) {
         CakeSession::write('Config.language', $this->params['named']['lang']);
         $this->redirect(array('action' => 'license'));
     }
     $Folder = new Folder(ROOT . DS . 'Locale' . DS);
     $langs = $Folder->read(true, false);
     $languages = array();
     foreach ($langs[0] as $l) {
         $file = ROOT . DS . 'Locale' . DS . $l . DS . 'LC_MESSAGES' . DS . 'default.po';
         if ($l != 'eng' && file_exists($file)) {
             $languages[$l] = array('welcome' => I18n::translate('Welcome to QuickApps CMS', null, null, 6, null, $l), 'action' => I18n::translate('Click here to install in English', null, null, 6, null, $l));
         }
     }
     if (empty($languages)) {
         CakeSession::write('Config.language', 'eng');
         $this->redirect(array('action' => 'license'));
     }
     $this->set('languages', $languages);
 }
コード例 #26
0
ファイル: i18n.class.php プロジェクト: nathansamson/CoOrg
function t($string, $params = array())
{
	return I18n::translate($string, $params);
}
コード例 #27
0
 /**
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
  *
  * Note that the category must be specified with a numeric value, instead of the constant name. The values are:
  *
  * - LC_ALL       0
  * - LC_COLLATE   1
  * - LC_CTYPE     2
  * - LC_MONETARY  3
  * - LC_NUMERIC   4
  * - LC_TIME      5
  * - LC_MESSAGES  6
  *
  * @param string $msg String to translate
  * @param integer $category Category
  * @param mixed $args Array with arguments or multiple arguments in function
  * @return translated string
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
  */
 function __c($msg, $category, $args = null)
 {
     if (!$msg) {
         return;
     }
     App::uses('I18n', 'I18n');
     $translated = I18n::translate($msg, null, null, $category);
     if ($args === null) {
         return $translated;
     } elseif (!is_array($args)) {
         $args = array_slice(func_get_args(), 2);
     }
     return vsprintf($translated, $args);
 }
コード例 #28
0
ファイル: basics.php プロジェクト: atikahmed/joomla-probid
/**
 * For use in administration
 * Returns a translated string if one is found, or the submitted message if not found.
 */
function __a($singular, $return = false, $js = false)
{
    $domain = 'admin';
    if (!$singular) {
        return;
    }
    if (!class_exists('I18n')) {
        require S2_LIBS . 'I18n.php';
    }
    $text = I18n::translate($singular, null, $domain);
    if ($js) {
        $text = str_replace("'", "\\'", $text);
        $text = str_replace('"', "'+String.fromCharCode(34)+'", $text);
    }
    if ($return === false) {
        echo $text;
    } else {
        return $text;
    }
}
コード例 #29
0
ファイル: basics.php プロジェクト: ambagasdowa/kml
/**
 * The category argument allows a specific category of the locale settings to be used for fetching a message.
 * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
 *
 * Note that the category must be specified with a numeric value, instead of the constant name.  The values are:
 *
 * - LC_ALL       0
 * - LC_COLLATE   1
 * - LC_CTYPE     2
 * - LC_MONETARY  3
 * - LC_NUMERIC   4
 * - LC_TIME      5
 * - LC_MESSAGES  6
 *
 * @param string $msg String to translate
 * @param integer $category Category
 * @param string $return true to return, false to echo
 * @return translated string if $return is false string will be echoed
 */
function __c($msg, $category, $return = false)
{
    if (!$msg) {
        return;
    }
    if (!class_exists('I18n')) {
        App::import('Core', 'i18n');
    }
    if ($return === false) {
        echo I18n::translate($msg, null, null, $category);
    } else {
        return I18n::translate($msg, null, null, $category);
    }
}
コード例 #30
0
ファイル: I18nTest.php プロジェクト: julkar9/gss
 /**
  * testTranslateLanguageParam method
  *
  * @return void
  */
 public function testTranslateLanguageParam()
 {
     Configure::write('Config.language', 'rule_0_po');
     $result = I18n::translate('Plural Rule 1', null, null, 6);
     $expected = 'Plural Rule 0 (translated)';
     $this->assertEquals($expected, $result);
     $result = I18n::translate('Plural Rule 1', null, null, 6, null, 'rule_1_po');
     $expected = 'Plural Rule 1 (translated)';
     $this->assertEquals($expected, $result);
 }