當前位置: 首頁>>代碼示例>>PHP>>正文


PHP i18n::get_languages方法代碼示例

本文整理匯總了PHP中i18n::get_languages方法的典型用法代碼示例。如果您正苦於以下問題:PHP i18n::get_languages方法的具體用法?PHP i18n::get_languages怎麽用?PHP i18n::get_languages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在i18n的用法示例。


在下文中一共展示了i18n::get_languages方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: action_edit

 /**
  * action: EDIT
  */
 public function action_edit()
 {
     $id = $this->request->param('id');
     $content = new Model_Content($id);
     $type = $content->type;
     $site = $type == 'page' ? __('Page') : __('Email');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $site));
     $locale = $content->locale;
     if ($content->loaded()) {
         $languages = i18n::get_languages();
         $this->template->content = View::factory('oc-panel/pages/content/edit', array('cont' => $content, 'locale' => $languages));
         if ($p = $this->request->post()) {
             foreach ($p as $name => $value) {
                 if ($name != 'submit') {
                     $content->{$name} = $value;
                 }
             }
             // if status is not checked, it is not set as POST response
             $content->status = isset($p['status']) ? 1 : 0;
             //$content->seotitle = $content->gen_seotitle($this->request->post('title'));
             try {
                 $content->save();
                 Cache::instance()->delete_all();
                 Alert::set(Alert::SUCCESS, $content->type . ' ' . __('is edited'));
                 Request::current()->redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit', 'id' => $content->id_content)));
             } catch (Exception $e) {
                 Alert::set(Alert::ERROR, $e->getMessage());
             }
         }
     } else {
         Alert::set(Alert::INFO, __('Faild to load content'));
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit')) . '?type=' . $type . '&locale_select=' . $locale);
     }
 }
開發者ID:Wildboard,項目名稱:WbWebApp,代碼行數:37,代碼來源:content.php

示例2: action_index

 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     $parse = $this->request->query('parse');
     if ($parse) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if ($this->request->param('id')) {
         //save language
         $locale = new Model_Config();
         $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find();
         if (!$locale->loaded()) {
             $locale->group_name = 'i18n';
             $locale->config_key = 'locale';
         }
         $locale->config_value = $this->request->param('id');
         try {
             $locale->save();
             Alert::set(Alert::SUCCESS, __('Translations regenarated'));
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     //create language
     if (Core::post('locale')) {
         $language = $this->request->post('locale');
         $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/';
         // if folder does not exist, try to make it
         if (!file_exists($folder) and !@mkdir($folder, 0775, true)) {
             // mkdir not successful ?
             Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
         }
         // write an empty .po file for $language
         $out = 'msgid ""' . PHP_EOL;
         $out .= 'msgstr ""' . PHP_EOL;
         File::write($folder . 'messages.po', $out);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
開發者ID:demoic,項目名稱:common,代碼行數:55,代碼來源:translations.php

示例3: before

 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     //we need this option enabled for this plugin to work
     if (Core::config('i18n.allow_query_language') == 0) {
         Model_Config::set_value('i18n', 'allow_query_language', 1);
     }
     if ($this->languages == '') {
         $this->languages = i18n::get_languages();
     } else {
         $this->languages = array_map('trim', explode(',', $this->languages));
     }
 }
開發者ID:kotsios5,項目名稱:openclassifieds2,代碼行數:18,代碼來源:languages.php

示例4: action_index

 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     if (core::get('parse') !== NULL) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if (($locale = $this->request->param('id')) != NULL and array_key_exists($locale, i18n::get_languages())) {
         //save language
         Model_Config::set_value('i18n', 'locale', $locale);
         //change the cookie if not he will not see the changes
         if (Core::config('i18n.allow_query_language') == 1) {
             Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
         }
         Alert::set(Alert::SUCCESS, __('Language') . ' ' . $locale);
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     //create language
     if (Core::post('locale')) {
         $language = $this->request->post('locale');
         $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/';
         // if folder does not exist, try to make it
         if (!file_exists($folder) and !@mkdir($folder, 0775, true)) {
             // mkdir not successful ?
             Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
         }
         // write an empty .po file for $language
         $out = 'msgid ""' . PHP_EOL;
         $out .= 'msgstr ""' . PHP_EOL;
         File::write($folder . 'messages.po', $out);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
開發者ID:ThomWensink,項目名稱:common,代碼行數:47,代碼來源:translations.php

示例5: action_index

 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     $parse = $this->request->query('parse');
     if ($parse) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if ($this->request->param('id')) {
         //save language
         $locale = new Model_Config();
         $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find();
         if (!$locale->loaded()) {
             $locale->group_name = 'i18n';
             $locale->config_key = 'locale';
         }
         $locale->config_value = $this->request->param('id');
         try {
             $locale->save();
             Alert::set(Alert::SUCCESS, '');
             Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations')));
         } catch (Exception $e) {
             echo $e;
         }
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
開發者ID:Wildboard,項目名稱:WbWebApp,代碼行數:39,代碼來源:translations.php

示例6: action_edit

 /**
  * action: EDIT
  */
 public function action_edit()
 {
     $id = $this->request->param('id');
     $content = new Model_Content($id);
     $type = $content->type;
     $site = self::translate_type($type);
     Breadcrumbs::add(Breadcrumb::factory()->set_title($site)->set_url(Route::url('oc-panel', array('controller' => 'content', 'action' => $type))));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $site));
     $locale = $content->locale;
     if ($content->loaded()) {
         $languages = i18n::get_languages();
         $this->template->content = View::factory('oc-panel/pages/content/edit', array('cont' => $content, 'locale' => $languages));
         if ($p = $this->request->post()) {
             foreach ($p as $name => $value) {
                 //for description we accept the HTML as comes...a bit risky but only admin can
                 if ($name == 'description') {
                     $content->description = Kohana::$_POST_ORIG['description'];
                 } elseif ($name != 'submit') {
                     $content->{$name} = $value;
                 }
             }
             // if status is not checked, it is not set as POST response
             $content->status = isset($p['status']) ? 1 : 0;
             try {
                 $content->save();
                 Alert::set(Alert::SUCCESS, $content->type . ' ' . __('is edited'));
             } catch (Exception $e) {
                 Alert::set(Alert::ERROR, $e->getMessage());
             }
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit', 'id' => $content->id_content)));
         }
     } else {
         Alert::set(Alert::INFO, __('Failed to load content'));
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit')) . '?type=' . $type . '&locale_select=' . $locale);
     }
 }
開發者ID:JeffPedro,項目名稱:project-garage-sale,代碼行數:39,代碼來源:content.php

示例7: form_setup

 public function form_setup($form)
 {
     $form->fields['order']['display_as'] = 'select';
     $form->fields['order']['options'] = range(0, 30);
     $form->fields['locale']['display_as'] = 'select';
     $form->fields['locale']['options'] = i18n::get_languages();
     $form->fields['seotitle']['display_as'] = 'hidden';
 }
開發者ID:Wildboard,項目名稱:WbWebApp,代碼行數:8,代碼來源:content.php

示例8: foreach

 /**
  * get language codes as options of a selectable list
  *
  * This function returns a full <select> tag with the name 'language' and the id 'language'.
  *
  * If no parameter is provided, then surfer language is used.
  *
  * @param string the current language, if any
  * @param string alternate name and id of the returned tag
  * @return the HTML to insert in the page
  */
 public static function &get_languages_select($current = NULL, $id = 'language')
 {
     global $context;
     // use surfer language by default
     if (!$current) {
         $current = $context['language'];
     }
     // all options
     $text = '<select name="' . $id . '" id="' . $id . '">' . "\n";
     // fetch the list of languages
     $languages =& i18n::get_languages();
     // engage surfer
     $text .= '<option value="none">' . i18n::s('Use browser settings') . "</option>\n";
     // current language setting
     if ($current == $context['language']) {
         $text .= '<option value="' . $context['language'] . '" selected="selected">' . i18n::get_language_label($context['language']) . "</option>\n";
     } else {
         $text .= '<option value="' . $context['language'] . '">' . i18n::get_language_label($context['language']) . "</option>\n";
     }
     // all options
     foreach ($languages as $code => $label) {
         // is this the current setting?
         if ($code == $context['language']) {
             continue;
         }
         // the code
         $text .= '<option value="' . $code . '"';
         // is this the current option?
         if ($code == $current) {
             $text .= ' selected="selected"';
         }
         // the label for this language
         $text .= '>' . $label . "</option>\n";
     }
     // return by reference
     $text .= '</select>';
     // job done
     return $text;
 }
開發者ID:rair,項目名稱:yacs,代碼行數:50,代碼來源:i18n.php


注:本文中的i18n::get_languages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。