/** * GetInstance of ZL10n singleton. * * @return ZGettext Instance. */ public static function getInstance() { if (!self::$instance) { self::$instance = new ZGettext(); } return self::$instance; }
define('LC_MESSAGES', 5); } include 'lib/StreamReader/Abstract.php'; include 'lib/StreamReader/String.php'; include 'lib/StreamReader/CachedFile.php'; include 'lib/i18n/ZGettext.php'; include 'lib/i18n/ZMO.php'; if (!isset($_GET['lang']) || count($_GET) < 2) { badRequest(); } $lang = $_GET['lang']; validate($lang); if (!preg_match('#(^[a-z]{2,3}$)|(^[a-z]{2,3}-[a-z]{2,3}$)|(^[a-z]{2,3}-[a-z]{2,3}-[a-z]{2,3}$)#', $lang)) { badRequest(); } $gettext = ZGettext::getInstance(); $gettext->setLocale(LC_MESSAGES, $lang); $translations = array(); $translations[$lang] = array(); foreach ($_GET as $domain => $meta) { if ($domain == 'lang') { continue; } validate($domain); validate($meta); $p = explode('_', $domain); $type = $p[0]; $m = explode('|', $meta); $name = $m[0]; // module name or system plugin name. $pluginName = isset($m[1]) ? $m[1] : '';
/** * Plural version of dcgettext. * * @param string $domain Gettext domain. * @param string $single Singular. * @param string $plural Plural. * @param integer $number Count. * @param integer $category LC_CONSTANT. * * @return string */ function _dcngettext($domain, $single, $plural, $number, $category) { return ZGettext::getReader($domain, $category)->ngettext($single, $plural, $number); }
/** * Bind domain. * * @param string $domain Gettext domain. * @param string $path Domain path. * * @return boolean */ public static function bindDomain($domain, $path) { $_this = self::getInstance(); $locale = $_this->getLocale(); // exit if the language system hasnt yet fully initialised if (!$locale) { return false; } // prevent double loading if (array_key_exists($domain, $_this->domainCache[$locale])) { return true; } ZGettext::getInstance()->bindTextDomain($domain, $path); ZGettext::getInstance()->bindTextDomainCodeset($domain, $_this->encoding); $_this->domainCache[$locale][$domain] = true; return $_this->domainCache[$locale][$domain]; }
/** * Bind domain. * * @param string $domain Gettext domain. * @param string $path Domain path. * * @return boolean */ public static function bindDomain($domain, $path) { $_this = self::getInstance(); $locale = $_this->getLocale(); if (!$locale) { // fallback solution to be replaced by proper routing $defaultLocale = System::getVar('language_i18n', 'en'); if (System::getVar('shorturls')) { // we need to extract the language code from current url, since it is not ensured // that System::queryStringDecode() has been executed already $customentrypoint = System::getVar('entrypoint'); $expectEntrypoint = !System::getVar('shorturlsstripentrypoint'); $root = empty($customentrypoint) ? 'index.php' : $customentrypoint; // get base path to work out our current url $parsedURL = parse_url(System::getCurrentUri()); $tobestripped = array(System::getBaseUri(), "{$root}"); $path = str_replace($tobestripped, '', $parsedURL['path']); $path = trim($path, '/'); // split the path into a set of argument strings $args = explode('/', rtrim($path, '/')); // ensure that each argument is properly decoded foreach ($args as $k => $v) { $args[$k] = urldecode($v); } if (isset($args[0]) && self::isLangParam($args[0]) && in_array($args[0], self::getInstalledLanguages())) { $defaultLocale = $args[0]; } } $_this->setLocale($defaultLocale); $locale = $_this->getLocale(); } // exit if the language system hasnt yet fully initialised if (!$locale) { return false; } // prevent double loading if (array_key_exists($domain, $_this->domainCache[$locale])) { return true; } ZGettext::getInstance()->bindTextDomain($domain, $path); ZGettext::getInstance()->bindTextDomainCodeset($domain, $_this->encoding); $_this->domainCache[$locale][$domain] = true; return $_this->domainCache[$locale][$domain]; }