/** * Returns an instance of a gettext implementation depending on * the capabilities of the PHP installation. If the gettext extension * is loaded, we use the native gettext() bindings, otherwise we use * an own implementation * * @param String $directory Directory to search the mo files in * @param String $domain The current domain * @param String $locale The local * * @return Gettext An instance of a Gettext implementation */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Gettext_Extension(); } return self::$instance; }
/** * @param string $mofile * @return bool */ public function startupMO($mofile) { $file = new File($mofile); if ($file->exists()) { $translations = Translations::fromMoFile($mofile); self::$t->loadTranslations($translations); self::$activeTranslation = $translations; return true; } else { return false; } }
public function testNgettext() { $g = Gettext::getInstance('./', 'gettext', 'de'); $this->assertEquals('Datei existiert nicht', $g->gettext('File does not exist')); $this->assertEquals('Datei existiert nicht', $g->ngettext('File does not exist', 'Files donnot exists', 1)); $this->assertEquals('Datei ist zu klein', $g->ngettext('File is too small', 'Files are too small', 1)); $this->assertEquals('Foobar', $g->ngettext('Foobar', 'Foobar', 1)); $this->assertEquals('Datei existiert nicht', $g->ngettext('File does not exist', 'Files donnot exists', 2)); $this->assertEquals('Dateien sind zu klein', $g->ngettext('File is too small', 'Files are too small', 2)); $this->assertEquals('Foobar', $g->ngettext('Foobar', 'Foobar', 2)); $this->assertContains('Last-Translator', $g->ngettext(null, null, 1)); $this->assertEquals('Dateien sind zu klein', $g->ngettext('File is too small', 'Files are too small', -1)); $this->assertEquals('Dateien sind zu klein', $g->ngettext('File is too small', 'Files are too small', 0)); }
/** * get started with all this * @return void * @todo template-map */ public static function startup() { $activeTemplate = new Template(app::get('template')); $gettext = new Gettext(HOME_DIR . '/locale/' . app::get('language') . '.mo'); if ($activeTemplate->translated) { Gettext::addTranslation(HOME_DIR . '/templates/' . app::get('template') . '/locale/' . app::get('language') . '.mo'); } require_once HOME_DIR . '/translate_functions.php'; if (isset($activeTemplate->map)) { foreach ($activeTemplate->map as $map) { Route::get("/{$map}/[fn:filename]", "AssetsController.everything")->name($map); } } // add your routes here! Route::get('/^\\s*$/', 'IndexController.get', true); Route::get('/test/stack', 'TestController.stack'); Route::get('/css/[fn:filename]', 'AssetsController.css'); Route::get('/js/[fn:filename]', 'AssetsController.js'); Modules::loadModuleList(); Modules::loadModules(); //$msqlo = new MySQLi(app::get('mysql')->host, app::get('mysql')->user, app::get('mysql')->password, app::get('mysql')->database); //\DI::addInstance($msqlo); $modelob = new \Observer\ModelObserver(); \DI::addInstance($modelob); $etagevent = new \Event('etag.change'); $etagevent->call(function ($newval) { \Kernel::$response->etag = md5(\Kernel::$response->etag . '|' . $newval); }); \EventHandler::attach($etagevent); Route::registerNotFoundAction('/', function () { \Kernel::$response->errorCode(404); (new \Controller())->view('error', ['error' => ['code' => '404', 'text' => 'Not found!']]); }); Route::registerNotFoundAction('/api/', function () { throw new \HTTPException\ObjectNotFoundException(404, "Requested resource not found!"); }); }
<?php // Load the Gettext module Gettext::instance();
/** * ファイルアップロードからリリース * @param string $package_name パッケージ名 **/ public function package_release_by_upload($package_name) { $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $package->permission($this->user()); if ($this->is_post() && $this->is_files('package_file') && $this->verify()) { try { $package_file = $this->in_files('package_file'); $package_file->generate(work_path('upload/' . $package_name . '-' . date('YmdHis') . '.tgz')); if ($package_xml = simplexml_load_file(sprintf('phar://%s/package.xml', $package_file->fullname()))) { if ($package_xml->name != $package->name()) { throw new OpenpearException(Gettext::trans('incorrect package name')); } if ($package_xml->channel != OpenpearConfig::pear_domain('openpear.org')) { $package_xml->channel = OpenpearConfig::pear_domain('openpear.org'); $pd = new PharData($package_file->fullname()); $pd->addFromString('package.xml', $package_xml->asXML()); unset($pd); } $upload_queue = new stdClass(); $upload_queue->package_id = $package->id(); $upload_queue->package_file = $package_file->fullname(); $upload_queue->maintainer_id = $this->user()->id(); $queue = new OpenpearQueue('type=upload_release'); $queue->data(serialize($upload_queue)); $queue->save(); $message = new OpenpearMessage('type=system_notice,mail=false'); $message->maintainer_to_id($this->user()->id()); $message->subject(trans('リリースキューに追加されました')); $message->description(trans('{1}のリリースを受け付けました。リリースの完了後,メールでお知らせします。', $package->name())); $message->save(); $this->redirect_by_map('dashboard'); } } catch (Exception $e) { Log::debug($e); Exceptions::add($e); } } $this->vars('package', $package); $this->vars('package_id', $package->id()); }
/** * パッケージの詳細 * @param string $package_name パッケージ名 * @param string $path リポジトリのパス * @request string $lang ロケール * @request string $tag タグ * @context OpenpearPackage $package パッケージ * @context string $body 説明 */ public function document_browse($package_name, $path = '') { $lang = $this->in_vars('lang', Gettext::lang()); if (empty($path)) { $this->redirect_method('document_browse', $package_name, '/' . $lang . '/README'); } else { if (strlen($path) > 4) { $lang = substr($path, 1, 2); } } $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $path = rtrim(ltrim($path, ' /.'), '/'); $root = File::absolute(OpenpearConfig::svn_root(), implode('/', array($package->name(), 'doc'))); $repo_path = File::absolute($root, $path); $this->vars('package', $package); try { $body = Subversion::cmd('cat', array($repo_path)); } catch (Exception $e) { $body = ''; } if (empty($body)) { Http::status_header(404); $body = '* Not found.' . PHP_EOL; $body .= 'Requested page is not found in our repositories.'; } $this->vars('lang', $lang); $this->vars('body', HatenaSyntax::render($body)); $this->vars('tree', Subversion::cmd('list', array($root . '/' . $lang), array('recursive' => 'recursive'))); $this->add_vars_other_tree($package_name, 'doc'); }
public final function tlalt($type) { switch ($type) { case 'release': return Gettext::trans('Release:'); case 'changeset': return Gettext::trans('Changeset:'); case 'user_activities': return Gettext::trans('Setting:'); case 'package_setting': return Gettext::trans('Setting:'); case 'favorite': return Gettext::trans('Fav:'); } }
/** * Constructs the Gettext singleton * * @return void */ protected function __construct() { Gettext::$config = Kohana::config('gettext'); if (Gettext::$config['regenerate_var'] and isset($_GET[Gettext::$config['regenerate_var']])) { // Regenerate language files Gettext::generate_po_files(); } $cache = Cache::instance(); $refresh = FALSE; if (Gettext::$config['auto_refresh'] !== FALSE) { $time = $cache->get('gettext-refresh'); if ($time !== NULL and time() > $time + Gettext::$config['auto_refresh']) { // Force a refresh from language data expiring $refresh = TRUE; } } if (Gettext::$config['refresh_var'] and isset($_GET[Gettext::$config['refresh_var']])) { // Force a refresh from get var $refresh = TRUE; } if ($refresh) { // Forcing a reload of language settings, otherwise Apache has to be restarted $time = time(); foreach (Gettext::$config['locales'] as $locale) { $file = APPPATH . Gettext::$config['directory'] . '/' . $locale . '/LC_MESSAGES/' . Gettext::$config['domain']; if (($old_time = $cache->get('gettext-refresh')) !== NULL) { // Delete old language file if it exists @unlink($file . '-' . $old_time . '.mo'); } if (is_file($file . '.mo')) { // Copy default language file to a temporary language file to be loaded in copy($file . '.mo', $file . '-' . $time . '.mo'); } } // Set new refresh value to current time $cache->set('gettext-refresh', $time, NULL, 0); } $domain = Gettext::$config['domain']; if (($time = $cache->get('gettext-refresh')) !== NULL) { // Grab temporary language file to use if one is set, otherwise use default $domain .= '-' . $time; } // Bind text domain bindtextdomain($domain, APPPATH . Kohana::config('gettext.directory')); textdomain($domain); // Grab current locale $locale = Kohana::config('locale.language'); // Update environment to current locale putenv('LC_ALL=' . $locale[0]); }