当前位置: 首页>>代码示例>>PHP>>正文


PHP i18n::get_language_path方法代码示例

本文整理汇总了PHP中i18n::get_language_path方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::get_language_path方法的具体用法?PHP i18n::get_language_path怎么用?PHP i18n::get_language_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在i18n的用法示例。


在下文中一共展示了i18n::get_language_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_translation

 /**
  * gets the translation as array form a language
  * @param  string $language 
  * @return array           
  */
 public function get_translation($language)
 {
     $mo_translation = i18n::get_language_path($language);
     if (!file_exists($mo_translation)) {
         Alert::set(Alert::ERROR, $language);
         $this->redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     $base_translation = i18n::get_language_path();
     //pear gettext scripts
     require_once Kohana::find_file('vendor', 'GT/Gettext', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/PO', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/MO', 'php');
     //load the .po files
     //original en translation
     $pocreator_en = new File_Gettext_PO();
     $pocreator_en->load($base_translation);
     //the translation file
     $pocreator_translated = new File_Gettext_PO();
     $pocreator_translated->load($mo_translation);
     //get an array with all the strings
     $en_array_order = $pocreator_en->strings;
     //sort alphabetical using locale
     ksort($en_array_order, SORT_LOCALE_STRING);
     //array with translated language may contain missing from EN
     $origin_translation = $pocreator_translated->strings;
     //lets get the array with translated values and sorted, will include everything even if was not previously saved
     $translation_array = array();
     $untranslated_array = array();
     //keep track of words not translated stores ID
     $i = 0;
     foreach ($en_array_order as $origin => $value) {
         //do we have the translation?
         if (isset($origin_translation[$origin]) and !empty($origin_translation[$origin]) > 0) {
             $translated = $origin_translation[$origin];
         } else {
             $untranslated_array[] = $i;
             $translated = '';
         }
         $translation_array[] = array('id' => $i, 'original' => $origin, 'translated' => $translated);
         $i++;
     }
     return array($translation_array, $untranslated_array);
 }
开发者ID:ThomWensink,项目名称:common,代码行数:48,代码来源:translations.php

示例2: action_edit

 public function action_edit()
 {
     if ($this->request->param('id')) {
         $language = $this->request->param('id');
         $default = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/messages.po';
         $default_mo = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/messages.mo';
     } else {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Translation')));
     $this->template->title = __('Edit Translation');
     $this->template->bind('content', $content);
     $content = View::factory('oc-panel/pages/translations/edit');
     $this->template->scripts['footer'][] = 'js/oc-panel/translations.js';
     $base_translation = i18n::get_language_path();
     //pear gettext scripts
     require_once Kohana::find_file('vendor', 'GT/Gettext', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/PO', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/MO', 'php');
     //.po to .mo script
     require_once Kohana::find_file('vendor', 'php-mo/php-mo', 'php');
     //load the .po files
     $pocreator_en = new File_Gettext_PO();
     $pocreator_en->load($base_translation);
     $pocreator_default = new File_Gettext_PO();
     $pocreator_default->load($default);
     $en_array_order = $pocreator_en->strings;
     //        ksort($en_array_order,SORT_NATURAL); // since PHP 5.4
     natcasesort($en_array_order);
     // better than natsort() ??
     //watch out there's a limit of 1000 posts....we have 540...
     if ($this->request->post()) {
         foreach ($en_array_order as $key => $string) {
             $keys[] = $key;
         }
         $translations = $this->request->post('translations');
         $strings = array();
         $out = '';
         foreach ($translations as $key => $value) {
             if ($value != "") {
                 $strings[$keys[$key]] = $value;
                 $out .= '#: String ' . $key . PHP_EOL;
                 $out .= 'msgid "' . $keys[$key] . '"' . PHP_EOL;
                 $out .= 'msgstr "' . $value . '"' . PHP_EOL;
                 $out .= PHP_EOL;
             }
         }
         //write the generated .po to file
         $fp = fopen($default, 'w+');
         $read = fwrite($fp, $out);
         fclose($fp);
         $pocreator_default->strings = $strings;
         //generate the .mo from the .po file
         phpmo_convert($default);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations', 'action' => 'edit', 'id' => $this->request->param('id'))));
     }
     $content->edit_language = $this->request->param('id');
     $content->strings_en = $en_array_order;
     $content->strings_default = $pocreator_default->strings;
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:61,代码来源:translations.php


注:本文中的i18n::get_language_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。