Exemplo n.º 1
0
        $translated = dngettext($domain, $singular, $plural, $count);
        return static::processTranslated($domain, $translated, $singular, $plural, $count, $fallbackSingular, $fallbackPlural);
    }
    public static function get($singular, $plural, $count = 1, $fallbackSingular = null, $fallbackPlural = null)
    {
        $count = abs($count);
        if (!\extension_loaded('gettext')) {
            return static::onMissingGettext($singular, $plural, $count, $fallbackSingular, $fallbackPlural);
        }
        // look for matching translation in default domain (l10n of current app)
        $translated = ngettext($singular, $plural, $count);
        // try l10n of TXF as fallback on missing translation in dictionary of app
        $isTranslated = $translated !== ($count == 1 ? $singular : $plural);
        if (!$isTranslated && static::current()->getDomain() !== 'txf') {
            return static::domainGet('txf', $singular, $plural, $count, $fallbackSingular, $fallbackPlural);
        }
        return static::processTranslated(null, $translated, $singular, $plural, $count, $fallbackSingular, $fallbackPlural);
    }
    public static function writeMissesCollection()
    {
        if (self::$collectionFile && is_writable(@dirname(self::$collectionFile))) {
            if (is_array(self::$collectionFileCache)) {
                @file_put_contents(self::$collectionFile, implode("", array_map(function ($line) {
                    return "msgid \"{$line}\"\nmsgstr \"\"\n";
                }, array_keys(self::$collectionFileCache))));
            }
        }
    }
}
locale::init();
Exemplo n.º 2
0
 /**
  * Catches exceptions not catched in code for embedding rendered exception
  * description in selected page design (if possible).
  *
  * @param \Exception $exception
  */
 public function onException(\Exception $exception)
 {
     if ($exception instanceof \ErrorException) {
         if ($exception->getCode() & E_NOTICE) {
             return;
         }
     }
     if ($exception instanceof \de\toxa\txf\http_exception) {
         header($exception->getResponse());
     }
     $this->accessVariable('exception', $exception);
     static::addBodyClass('exception');
     try {
         try {
             $code = $this->engine->render('exception', variable_space::create('exception', $exception));
         } catch (\Exception $e) {
             $code = locale::get('failed to render exception');
         }
         $this->viewport('error', $code);
         if (txf::getContextMode() == txf::CTXMODE_REWRITTEN) {
             // this mode does not have registered shutdown handler
             // --> call it explicitly here
             $this->onShutdown();
         }
     } catch (\Exception $e) {
         echo '<h1>Failed to render exception</h1>';
         echo self::simpleRenderException($exception);
         echo '<h1>Encountered error was</h1>';
         echo self::simpleRenderException($e);
     }
     exit;
 }