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'))); }
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'))); }
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'))); }
<?php include 'POTCreator.php'; $obj = new POTCreator(); $obj->set_root(dirname(__FILE__) . '/example'); $obj->set_exts('php|tpl'); $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i'); $obj->set_base_path('..'); $obj->set_read_subdir(true); $potfile = 'example/language/example.pot'; $obj->write_pot($potfile); header('Content-type:text/html; Charset=GBK'); echo "<p>POT 文件位于 - The POT file located in:<br>\n{$potfile}</p>\n"; echo "<p>然后你就可以使用 Poedit 进行翻译啦 - Then you can translate it by Poedit.</p>\n";