Mega file creato il 28/01/2026 alle 18:25:22,90 ================================================ Cartella di partenza: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext Inclusi solo file .php, .js, .tsx, .jsx, .json Cartelle escluse: plugins, node_modules, lib, dist, android, .expo ================================================ ----- File: autoloader.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\autoloader.php ---------------------------------------- setLanguage($language); } } /** * Define the current locale. * * @param string $language * @param int|null $category * * @return self */ public function setLanguage($language, $category = null) { if ($category === null) { $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; } setlocale($category, $language); putenv('LANGUAGE='.$language); return $this; } /** * Loads a gettext domain. * * @param string $domain * @param string $path * @param bool $default * * @return self */ public function loadDomain($domain, $path = null, $default = true) { bindtextdomain($domain, $path); bind_textdomain_codeset($domain, 'UTF-8'); if ($default) { textdomain($domain); } return $this; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function gettext($original) { return gettext($original); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function ngettext($original, $plural, $value) { return ngettext($original, $plural, $value); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dngettext($domain, $original, $plural, $value) { return dngettext($domain, $original, $plural, $value); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function npgettext($context, $original, $plural, $value) { $message = $context."\x04".$original; $translation = ngettext($message, $plural, $value); return ($translation === $message) ? $original : $translation; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function pgettext($context, $original) { $message = $context."\x04".$original; $translation = gettext($message); return ($translation === $message) ? $original : $translation; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dgettext($domain, $original) { return dgettext($domain, $original); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dpgettext($domain, $context, $original) { $message = $context."\x04".$original; $translation = dgettext($domain, $message); return ($translation === $message) ? $original : $translation; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dnpgettext($domain, $context, $original, $plural, $value) { $message = $context."\x04".$original; $translation = dngettext($domain, $message, $plural, $value); return ($translation === $message) ? $original : $translation; } } ----- File: Merge.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Merge.php ---------------------------------------- deleteFlags(); } if (!($options & self::FLAGS_OURS)) { foreach ($from->getFlags() as $flag) { $to->addFlag($flag); } } } /** * Merge the extracted comments of two translations. * * @param Translation $from * @param Translation $to * @param int $options */ public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS) { if ($options & self::EXTRACTED_COMMENTS_THEIRS) { $to->deleteExtractedComments(); } if (!($options & self::EXTRACTED_COMMENTS_OURS)) { foreach ($from->getExtractedComments() as $comment) { $to->addExtractedComment($comment); } } } /** * Merge the comments of two translations. * * @param Translation $from * @param Translation $to * @param int $options */ public static function mergeComments(Translation $from, Translation $to, $options = self::DEFAULTS) { if ($options & self::COMMENTS_THEIRS) { $to->deleteComments(); } if (!($options & self::COMMENTS_OURS)) { foreach ($from->getComments() as $comment) { $to->addComment($comment); } } } /** * Merge the references of two translations. * * @param Translation $from * @param Translation $to * @param int $options */ public static function mergeReferences(Translation $from, Translation $to, $options = self::DEFAULTS) { if ($options & self::REFERENCES_THEIRS) { $to->deleteReferences(); } if (!($options & self::REFERENCES_OURS)) { foreach ($from->getReferences() as $reference) { $to->addReference($reference[0], $reference[1]); } } } /** * Merge the translations of two translations. * * @param Translation $from * @param Translation $to * @param int $options */ public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS) { $override = (boolean) ($options & self::TRANSLATION_OVERRIDE); if (!$to->hasTranslation() || ($from->hasTranslation() && $override)) { $to->setTranslation($from->getTranslation()); } if (!$to->hasPlural() || ($from->hasPlural() && $override)) { $to->setPlural($from->getPlural()); } if (!$to->hasPluralTranslations() || ($from->hasPluralTranslations() && $override)) { $to->setPluralTranslations($from->getPluralTranslations()); } } /** * Merge the translations of two translations. * * @param Translations $from * @param Translations $to * @param int $options */ public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS) { if ($options & self::REMOVE) { $filtered = []; foreach ($to as $entry) { if ($from->find($entry)) { $filtered[$entry->getId()] = $entry; } } $to->exchangeArray($filtered); } foreach ($from as $entry) { if (($existing = $to->find($entry))) { $existing->mergeWith($entry, $options); } elseif ($options & self::ADD) { $to[] = $entry->getClone(); } } } /** * Merge the headers of two translations. * * @param Translations $from * @param Translations $to * @param int $options */ public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS) { if ($options & self::HEADERS_REMOVE) { foreach (array_keys($to->getHeaders()) as $name) { if ($from->getHeader($name) === null) { $to->deleteHeader($name); } } } foreach ($from->getHeaders() as $name => $value) { $current = $to->getHeader($name); if (empty($current)) { if ($options & self::HEADERS_ADD) { $to->setHeader($name, $value); } continue; } if (empty($value)) { continue; } switch ($name) { case Translations::HEADER_LANGUAGE: case Translations::HEADER_PLURAL: if ($options & self::LANGUAGE_OVERRIDE) { $to->setHeader($name, $value); } break; case Translations::HEADER_DOMAIN: if ($options & self::DOMAIN_OVERRIDE) { $to->setHeader($name, $value); } break; default: if ($options & self::HEADERS_OVERRIDE) { $to->setHeader($name, $value); } } } } } ----- File: Translation.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Translation.php ---------------------------------------- context = (string) $context; $this->original = (string) $original; $this->setPlural($plural); } /** * Clones this translation. * * @param null|string $context Optional new context * @param null|string $original Optional new original * * @return Translation */ public function getClone($context = null, $original = null) { $new = clone $this; if ($context !== null) { $new->context = (string) $context; } if ($original !== null) { $new->original = (string) $original; } return $new; } /** * Returns the id of this translation. * * @return string */ public function getId() { return static::generateId($this->context, $this->original); } /** * Checks whether the translation matches with the arguments. * * @param string $context * @param string $original * * @return bool */ public function is($context, $original = '') { return (($this->context === $context) && ($this->original === $original)) ? true : false; } /** * Gets the original string. * * @return string */ public function getOriginal() { return $this->original; } /** * Checks if the original string is empty or not. * * @return bool */ public function hasOriginal() { return ($this->original !== '') ? true : false; } /** * Sets the translation string. * * @param string $translation * * @return self */ public function setTranslation($translation) { $this->translation = (string) $translation; return $this; } /** * Gets the translation string. * * @return string */ public function getTranslation() { return $this->translation; } /** * Checks if the translation string is empty or not. * * @return bool */ public function hasTranslation() { return ($this->translation !== '') ? true : false; } /** * Sets the plural translation string. * * @param string $plural * * @return self */ public function setPlural($plural) { $this->plural = (string) $plural; return $this; } /** * Gets the plural translation string. * * @return string */ public function getPlural() { return $this->plural; } /** * Checks if the plural translation string is empty or not. * * @return bool */ public function hasPlural() { return ($this->plural !== '') ? true : false; } /** * Set a new plural translation. * * @param array $plural * * @return self */ public function setPluralTranslations(array $plural) { $this->pluralTranslation = $plural; return $this; } /** * Gets all plural translations. * * @param int $size * * @return array */ public function getPluralTranslations($size = null) { if ($size === null) { return $this->pluralTranslation; } $current = count($this->pluralTranslation); if ($size > $current) { return $this->pluralTranslation + array_fill(0, $size, ''); } if ($size < $current) { return array_slice($this->pluralTranslation, 0, $size); } return $this->pluralTranslation; } /** * Checks if there are any plural translation. * * @param bool $checkContent * * @return bool */ public function hasPluralTranslations($checkContent = false) { if ($checkContent) { return implode('', $this->pluralTranslation) !== ''; } return !empty($this->pluralTranslation); } /** * Removes all plural translations. * * @return self */ public function deletePluralTranslation() { $this->pluralTranslation = []; return $this; } /** * Gets the context of this translation. * * @return string */ public function getContext() { return $this->context; } /** * Checks if the context is empty or not. * * @return bool */ public function hasContext() { return (isset($this->context) && ($this->context !== '')) ? true : false; } /** * Adds a new reference for this translation. * * @param string $filename The file path where the translation has been found * @param null|int $line The line number where the translation has been found * * @return self */ public function addReference($filename, $line = null) { $key = "{$filename}:{$line}"; $this->references[$key] = [$filename, $line]; return $this; } /** * Checks if the translation has any reference. * * @return bool */ public function hasReferences() { return !empty($this->references); } /** * Return all references for this translation. * * @return array */ public function getReferences() { return array_values($this->references); } /** * Removes all references. * * @return self */ public function deleteReferences() { $this->references = []; return $this; } /** * Adds a new comment for this translation. * * @param string $comment * * @return self */ public function addComment($comment) { if (!in_array($comment, $this->comments, true)) { $this->comments[] = $comment; } return $this; } /** * Checks if the translation has any comment. * * @return bool */ public function hasComments() { return isset($this->comments[0]); } /** * Returns all comments for this translation. * * @return array */ public function getComments() { return $this->comments; } /** * Removes all comments. * * @return self */ public function deleteComments() { $this->comments = []; return $this; } /** * Adds a new extracted comment for this translation. * * @param string $comment * * @return self */ public function addExtractedComment($comment) { if (!in_array($comment, $this->extractedComments, true)) { $this->extractedComments[] = $comment; } return $this; } /** * Checks if the translation has any extracted comment. * * @return bool */ public function hasExtractedComments() { return isset($this->extractedComments[0]); } /** * Returns all extracted comments for this translation. * * @return array */ public function getExtractedComments() { return $this->extractedComments; } /** * Removes all extracted comments. * * @return self */ public function deleteExtractedComments() { $this->extractedComments = []; return $this; } /** * Adds a new flag for this translation. * * @param string $flag * * @return self */ public function addFlag($flag) { if (!in_array($flag, $this->flags, true)) { $this->flags[] = $flag; } return $this; } /** * Checks if the translation has any flag. * * @return bool */ public function hasFlags() { return isset($this->flags[0]); } /** * Returns all extracted flags for this translation. * * @return array */ public function getFlags() { return $this->flags; } /** * Removes all flags. * * @return self */ public function deleteFlags() { $this->flags = []; return $this; } /** * Merges this translation with other translation. * * @param Translation $translation The translation to merge with * @param int $options * * @return self */ public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) { Merge::mergeTranslation($translation, $this, $options); Merge::mergeReferences($translation, $this, $options); Merge::mergeComments($translation, $this, $options); Merge::mergeExtractedComments($translation, $this, $options); Merge::mergeFlags($translation, $this, $options); return $this; } } ----- File: Translations.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Translations.php ---------------------------------------- [ 'Project-Id-Version' => '', 'Report-Msgid-Bugs-To' => '', 'Last-Translator' => '', 'Language-Team' => '', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8bit', ], 'headersSorting' => false, 'defaultDateHeaders' => [ 'POT-Creation-Date', 'PO-Revision-Date', ], ]; private $headers; /** * @see ArrayObject::__construct() */ public function __construct($input = [], $flags = 0, $iterator_class = 'ArrayIterator') { $this->headers = static::$options['defaultHeaders']; foreach (static::$options['defaultDateHeaders'] as $header) { $this->headers[$header] = date('c'); } $this->headers[self::HEADER_LANGUAGE] = ''; parent::__construct($input, $flags, $iterator_class); } /** * Magic method to create new instances using extractors * For example: Translations::fromMoFile($filename, $options);. * * @return Translations */ public static function __callStatic($name, $arguments) { if (!preg_match('/^from(\w+)(File|String)$/i', $name, $matches)) { throw new BadMethodCallException("The method $name does not exists"); } return call_user_func_array([new static(), 'add'.ucfirst($name)], $arguments); } /** * Magic method to import/export the translations to a specific format * For example: $translations->toMoFile($filename, $options); * For example: $translations->addFromMoFile($filename, $options);. * * @return self|bool */ public function __call($name, $arguments) { if (!preg_match('/^(addFrom|to)(\w+)(File|String)$/i', $name, $matches)) { throw new BadMethodCallException("The method $name does not exists"); } if ($matches[1] === 'addFrom') { $extractor = 'Gettext\\Extractors\\'.$matches[2].'::from'.$matches[3]; $source = array_shift($arguments); $options = array_shift($arguments) ?: []; call_user_func($extractor, $source, $this, $options); return $this; } $generator = 'Gettext\\Generators\\'.$matches[2].'::to'.$matches[3]; array_unshift($arguments, $this); return call_user_func_array($generator, $arguments); } /** * Magic method to clone each translation on clone the translations object. */ public function __clone() { $array = []; foreach ($this as $key => $translation) { $array[$key] = clone $translation; } $this->exchangeArray($array); } /** * Control the new translations added. * * @param mixed $index * @param Translation $value * * @throws InvalidArgumentException If the value is not an instance of Gettext\Translation * * @return Translation */ public function offsetSet($index, $value) { if (!($value instanceof Translation)) { throw new InvalidArgumentException( 'Only instances of Gettext\\Translation must be added to a Gettext\\Translations' ); } $id = $value->getId(); if ($this->offsetExists($id)) { $this[$id]->mergeWith($value); return $this[$id]; } parent::offsetSet($id, $value); return $value; } /** * Set the plural definition. * * @param int $count * @param string $rule * * @return self */ public function setPluralForms($count, $rule) { if (preg_match('/[a-z]/i', str_replace('n', '', $rule))) { throw new \InvalidArgumentException('Invalid Plural form: ' . $rule); } $this->setHeader(self::HEADER_PLURAL, "nplurals={$count}; plural={$rule};"); return $this; } /** * Returns the parsed plural definition. * * @param null|array [count, rule] */ public function getPluralForms() { $header = $this->getHeader(self::HEADER_PLURAL); if (!empty($header) && preg_match('/^nplurals\s*=\s*(\d+)\s*;\s*plural\s*=\s*([^;]+)\s*;$/', $header, $matches) ) { return [intval($matches[1]), $matches[2]]; } } /** * Set a new header. * * @param string $name * @param string $value * * @return self */ public function setHeader($name, $value) { $name = trim($name); $this->headers[$name] = trim($value); return $this; } /** * Returns a header value. * * @param string $name * * @return null|string */ public function getHeader($name) { return isset($this->headers[$name]) ? $this->headers[$name] : null; } /** * Returns all header for this translations (in alphabetic order). * * @return array */ public function getHeaders() { if (static::$options['headersSorting']) { ksort($this->headers); } return $this->headers; } /** * Removes all headers. * * @return self */ public function deleteHeaders() { $this->headers = []; return $this; } /** * Removes one header. * * @param string $name * * @return self */ public function deleteHeader($name) { unset($this->headers[$name]); return $this; } /** * Returns the language value. * * @return string $language */ public function getLanguage() { return $this->getHeader(self::HEADER_LANGUAGE); } /** * Sets the language and the plural forms. * * @param string $language * * @throws InvalidArgumentException if the language hasn't been recognized * * @return self */ public function setLanguage($language) { $this->setHeader(self::HEADER_LANGUAGE, trim($language)); if (($info = Language::getById($language))) { return $this->setPluralForms(count($info->categories), $info->formula); } throw new InvalidArgumentException(sprintf('The language "%s" is not valid', $language)); } /** * Checks whether the language is empty or not. * * @return bool */ public function hasLanguage() { $language = $this->getLanguage(); return (is_string($language) && ($language !== '')) ? true : false; } /** * Set a new domain for this translations. * * @param string $domain * * @return self */ public function setDomain($domain) { $this->setHeader(self::HEADER_DOMAIN, trim($domain)); return $this; } /** * Returns the domain. * * @return string */ public function getDomain() { return $this->getHeader(self::HEADER_DOMAIN); } /** * Checks whether the domain is empty or not. * * @return bool */ public function hasDomain() { $domain = $this->getDomain(); return (is_string($domain) && ($domain !== '')) ? true : false; } /** * Search for a specific translation. * * @param string|Translation $context The context of the translation or a translation instance * @param string $original The original string * * @return Translation|false */ public function find($context, $original = '') { if ($context instanceof Translation) { $id = $context->getId(); } else { $id = Translation::generateId($context, $original); } return $this->offsetExists($id) ? $this[$id] : false; } /** * Count all elements translated * * @return integer */ public function countTranslated() { $callback = function (Translation $v) { return ($v->hasTranslation()) ? $v->getTranslation() : null; }; return count(array_filter(get_object_vars($this), $callback)); } /** * Creates and insert/merges a new translation. * * @param string $context The translation context * @param string $original The translation original string * @param string $plural The translation original plural string * * @return Translation The translation created */ public function insert($context, $original, $plural = '') { return $this->offsetSet(null, new Translation($context, $original, $plural)); } /** * Merges this translations with other translations. * * @param Translations $translations The translations instance to merge with * @param int $options * * @return self */ public function mergeWith(Translations $translations, $options = Merge::DEFAULTS) { Merge::mergeHeaders($translations, $this, $options); Merge::mergeTranslations($translations, $this, $options); return $this; } } ----- File: Translator.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Translator.php ---------------------------------------- addTranslations($translations); return $this; } /** * Set the default domain. * * @param string $domain * * @return self */ public function defaultDomain($domain) { $this->domain = $domain; return $this; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function gettext($original) { return $this->dpgettext($this->domain, null, $original); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function ngettext($original, $plural, $value) { return $this->dnpgettext($this->domain, null, $original, $plural, $value); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dngettext($domain, $original, $plural, $value) { return $this->dnpgettext($domain, null, $original, $plural, $value); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function npgettext($context, $original, $plural, $value) { return $this->dnpgettext($this->domain, $context, $original, $plural, $value); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function pgettext($context, $original) { return $this->dpgettext($this->domain, $context, $original); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dgettext($domain, $original) { return $this->dpgettext($domain, null, $original); } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dpgettext($domain, $context, $original) { $translation = $this->getTranslation($domain, $context, $original); if (isset($translation[0]) && $translation[0] !== '') { return $translation[0]; } return $original; } /** * @see TranslatorInterface * * {@inheritdoc} */ public function dnpgettext($domain, $context, $original, $plural, $value) { $translation = $this->getTranslation($domain, $context, $original); $key = $this->getPluralIndex($domain, $value, $translation === false); if (isset($translation[$key]) && $translation[$key] !== '') { return $translation[$key]; } return ($key === 0) ? $original : $plural; } /** * Set new translations to the dictionary. * * @param array $translations */ protected function addTranslations(array $translations) { $domain = isset($translations['domain']) ? $translations['domain'] : ''; //Set the first domain loaded as default domain if ($this->domain === null) { $this->domain = $domain; } if (isset($this->dictionary[$domain])) { $this->dictionary[$domain] = array_replace_recursive($this->dictionary[$domain], $this->array_filter_recursive($translations['messages'])); return; } if (!empty($translations['plural-forms'])) { list($count, $code) = array_map('trim', explode(';', $translations['plural-forms'], 2)); // extract just the expression turn 'n' into a php variable '$n'. // Slap on a return keyword and semicolon at the end. $this->plurals[$domain] = [ 'count' => (int) str_replace('nplurals=', '', $count), 'code' => str_replace('plural=', 'return ', str_replace('n', '$n', $code)).';', ]; } $this->dictionary[$domain] = $translations['messages']; } protected function array_filter_recursive($input) { foreach ($input as &$value) { if (is_array($value)) { $value = $this->array_filter_recursive($value); } } return array_filter($input); } /** * Search and returns a translation. * * @param string $domain * @param string $context * @param string $original * * @return string|false */ protected function getTranslation($domain, $context, $original) { return isset($this->dictionary[$domain][$context][$original]) ? $this->dictionary[$domain][$context][$original] : false; } /** * Executes the plural decision code given the number to decide which * plural version to take. * * @param string $domain * @param string $n * @param bool $fallback set to true to get fallback plural index * * @return int */ protected function getPluralIndex($domain, $n, $fallback) { //Not loaded domain or translation, use a fallback if (!isset($this->plurals[$domain]) || $fallback === true) { return $n == 1 ? 0 : 1; } if (!isset($this->plurals[$domain]['function'])) { $code = self::fixTerseIfs($this->plurals[$domain]['code']); $this->plurals[$domain]['function'] = eval("return function (\$n) { $code };"); } if ($this->plurals[$domain]['count'] <= 2) { return call_user_func($this->plurals[$domain]['function'], $n) ? 1 : 0; } return call_user_func($this->plurals[$domain]['function'], $n); } /** * This function will recursively wrap failure states in brackets if they contain a nested terse if. * * This because PHP can not handle nested terse if's unless they are wrapped in brackets. * * This code probably only works for the gettext plural decision codes. * * return ($n==1 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2); * becomes * return ($n==1 ? 0 : ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2)); * * @param string $code the terse if string * @param bool $inner If inner is true we wrap it in brackets * * @return string A formatted terse If that PHP can work with. */ private static function fixTerseIfs($code, $inner = false) { /* * (?P[^?]+) Capture everything up to ? as 'expression' * \? ? * (?P[^:]+) Capture everything up to : as 'success' * : : * (?P[^;]+) Capture everything up to ; as 'failure' */ preg_match('/(?P[^?]+)\?(?P[^:]+):(?P[^;]+)/', $code, $matches); // If no match was found then no terse if was present if (!isset($matches[0])) { return $code; } $expression = $matches['expression']; $success = $matches['success']; $failure = $matches['failure']; // Go look for another terse if in the failure state. $failure = self::fixTerseIfs($failure, true); $code = $expression.' ? '.$success.' : '.$failure; if ($inner) { return "($code)"; } // note the semicolon. We need that for executing the code. return "$code;"; } } ----- File: TranslatorInterface.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\TranslatorInterface.php ---------------------------------------- gettext(html_entity_decode($original)); if (func_num_args() === 1) { return $text; } $args = array_slice(func_get_args(), 1); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Noop, marks the string for translation but returns it unchanged. * * @param string $original * * @return string */ function noop__($original) { return $original; } /** * Returns the singular/plural translation of a string. * * @param string $original * @param string $plural * @param string $value * * @return string */ function n__($original, $plural, $value) { $text = BaseTranslator::$current->ngettext($original, $plural, $value); if (func_num_args() === 3) { return $text; } $args = array_slice(func_get_args(), 3); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the translation of a string in a specific context. * * @param string $context * @param string $original * * @return string */ function p__($context, $original) { $text = BaseTranslator::$current->pgettext($context, $original); if (func_num_args() === 2) { return $text; } $args = array_slice(func_get_args(), 2); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the translation of a string in a specific domain. * * @param string $domain * @param string $original * * @return string */ function d__($domain, $original) { $text = BaseTranslator::$current->dgettext($domain, $original); if (func_num_args() === 2) { return $text; } $args = array_slice(func_get_args(), 2); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the translation of a string in a specific domain and context. * * @param string $domain * @param string $context * @param string $original * * @return string */ function dp__($domain, $context, $original) { $text = BaseTranslator::$current->dpgettext($domain, $context, $original); if (func_num_args() === 3) { return $text; } $args = array_slice(func_get_args(), 3); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the singular/plural translation of a string in a specific domain. * * @param string $domain * @param string $original * @param string $plural * @param string $value * * @return string */ function dn__($domain, $original, $plural, $value) { $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value); if (func_num_args() === 4) { return $text; } $args = array_slice(func_get_args(), 4); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the singular/plural translation of a string in a specific context. * * @param string $context * @param string $original * @param string $plural * @param string $value * * @return string */ function np__($context, $original, $plural, $value) { $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value); if (func_num_args() === 4) { return $text; } $args = array_slice(func_get_args(), 4); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } /** * Returns the singular/plural translation of a string in a specific domain and context. * * @param string $domain * @param string $context * @param string $original * @param string $plural * @param string $value * * @return string */ function dnp__($domain, $context, $original, $plural, $value) { $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value); if (func_num_args() === 5) { return $text; } $args = array_slice(func_get_args(), 5); return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); } ----- File: autoloader.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\autoloader.php ---------------------------------------- id = $matches[1]; $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { throw new Exception("Invalid CLDR category rule: $cldrFormulaAndExamples"); } $cldrFormula = trim($matches[1]); $s = isset($matches[2]) ? trim($matches[2]) : ''; $this->examples = ($s === '') ? null : $s; switch ($this->id) { case CldrData::OTHER_CATEGORY: if ($cldrFormula !== '') { throw new Exception("The '".CldrData::OTHER_CATEGORY."' category should not have any formula, but it has '$cldrFormula'"); } $this->formula = null; break; default: if ($cldrFormula === '') { throw new Exception("The '{$this->id}' category does not have a formula"); } $this->formula = FormulaConverter::convertFormula($cldrFormula); break; } } /** * Return a list of numbers corresponding to the $examples value. * @throws Exception Throws an Exception if we weren't able to expand the examples. * @return int[] */ public function getExampleIntegers() { return self::expandExamples($this->examples); } /** * Expand a list of examples as defined by CLDR. * @param string $examples A string like '1, 2, 5...7, …'. * @throws Exception Throws an Exception if we weren't able to expand $examples. * @return int[] */ public static function expandExamples($examples) { $result = array(); $m = null; if (substr($examples, -strlen(', …')) === ', …') { $examples = substr($examples, 0, strlen($examples) -strlen(', …')); } foreach (explode(',', str_replace(' ', '', $examples)) as $range) { if (preg_match('/^\d+$/', $range)) { $result[] = intval($range); } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { $from = intval($m[1]); $to = intval($m[2]); $delta = $to - $from; $step = (int) max(1, $delta / 100); for ($i = $from; $i < $to; $i += $step) { $result[] = $i; } $result[] = $to; } else { throw new Exception("Unhandled test range '$range' in '$examples'"); } } if (empty($result)) { throw new Exception("No test numbers from '$examples'"); } return $result; } } ----- File: CldrData.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\CldrData.php ---------------------------------------- $value) { $variant = ''; if (preg_match('/^(.+)-alt-(short|variant|stand-alone|long)$/', $key, $match)) { $key = $match[1]; $variant = $match[2]; } $key = str_replace('-', '_', $key); switch ($key) { case 'root': // Language: Root case 'und': // Language: Unknown Language case 'zxx': // Language: No linguistic content case 'ZZ': // Territory: Unknown Region case 'Zinh': // Script: Inherited case 'Zmth': // Script: Mathematical Notation case 'Zsym': // Script: Symbols case 'Zxxx': // Script: Unwritten case 'Zyyy': // Script: Common case 'Zzzz': // Script: Unknown Script break; default: switch ($variant) { case 'stand-alone': $standAlone[$key] = $value; break; case '': $result[$key] = $value; break; } break; } } return $result; }; $data = array(); $json = json_decode(file_get_contents(__DIR__.'/cldr-data/main/en-US/languages.json'), true); $data['languages'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['languages']); $json = json_decode(file_get_contents(__DIR__.'/cldr-data/main/en-US/territories.json'), true); $data['territories'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['territories']); $json = json_decode(file_get_contents(__DIR__.'/cldr-data/supplemental/plurals.json'), true); $data['plurals'] = $fixKeys($json['supplemental']['plurals-type-cardinal']); $json = json_decode(file_get_contents(__DIR__.'/cldr-data/main/en-US/scripts.json'), true); $data['scripts'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['scripts'], $data['standAloneScripts']); $data['standAloneScripts'] = array_merge($data['scripts'], $data['standAloneScripts']); $data['scripts'] = array_merge($data['standAloneScripts'], $data['scripts']); $data['supersededLanguages'] = array(); // Remove the languages for which we don't have plurals $m = null; foreach (array_keys(array_diff_key($data['languages'], $data['plurals'])) as $missingPlural) { if (preg_match('/^([a-z]{2,3})_/', $missingPlural, $m)) { if (!isset($data['plurals'][$m[1]])) { unset($data['languages'][$missingPlural]); } } else { unset($data['languages'][$missingPlural]); } } // Fix the languages for which we have plurals $formerCodes = array( 'in' => 'id', // former Indonesian 'iw' => 'he', // former Hebrew 'ji' => 'yi', // former Yiddish 'jw' => 'jv', // former Javanese 'mo' => 'ro_MD', // former Moldavian ); $knownMissingLanguages = array( 'bh' => 'Bihari', 'guw' => 'Gun', 'nah' => 'Nahuatl', 'smi' => 'Sami', ); foreach (array_keys(array_diff_key($data['plurals'], $data['languages'])) as $missingLanguage) { if (isset($formerCodes[$missingLanguage]) && isset($data['languages'][$formerCodes[$missingLanguage]])) { $data['languages'][$missingLanguage] = $data['languages'][$formerCodes[$missingLanguage]]; $data['supersededLanguages'][$missingLanguage] = $formerCodes[$missingLanguage]; } else { if (isset($knownMissingLanguages[$missingLanguage])) { $data['languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage]; } else { throw new Exception("We have the plural rule for the language '$missingLanguage' but we don't have its language name"); } } } ksort($data['languages'], SORT_STRING); ksort($data['territories'], SORT_STRING); ksort($data['plurals'], SORT_STRING); ksort($data['scripts'], SORT_STRING); ksort($data['standAloneScripts'], SORT_STRING); ksort($data['supersededLanguages'], SORT_STRING); self::$data = $data; } if (!@isset(self::$data[$key])) { throw new Exception("Invalid CLDR data key: '$key'"); } return self::$data[$key]; } /** * Returns a dictionary containing the language names. * The keys are the language identifiers. * The values are the language names in US English. * @return string[] */ public static function getLanguageNames() { return self::getData('languages'); } /** * Return a dictionary containing the territory names (in US English). * The keys are the territory identifiers. * The values are the territory names in US English. * @return string[] */ public static function getTerritoryNames() { return self::getData('territories'); } /** * Return a dictionary containing the script names (in US English). * The keys are the script identifiers. * The values are the script names in US English. * @param bool $standAlone Set to true to retrieve the stand-alone script names, false otherwise. * @return string[] */ public static function getScriptNames($standAlone) { return self::getData($standAlone ? 'standAloneScripts' : 'scripts'); } /** * @var array */ private static $plurals; /** * A dictionary containing the plural rules. * The keys are the language identifiers. * The values are arrays whose keys are the CLDR category names and the values are the CLDR category definition. * @example The English key-value pair is somethink like this: *
     * "en": {
     *     "pluralRule-count-one": "i = 1 and v = 0 @integer 1",
     *     "pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
     * }
     * 
* @var array */ public static function getPlurals() { return self::getData('plurals'); } /** * Return a list of superseded language codes. * @return array Keys are the former language codes, values are the new language/locale codes. */ public static function getSupersededLanguages() { return self::getData('supersededLanguages'); } /** * Retrieve the name of a language, as well as if a language code is deprecated in favor of another language code. * @param string $id The language identifier. * @return array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null. */ public static function getLanguageInfo($id) { $result = null; $matches = array(); if (preg_match('/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches)) { $languageId = strtolower($matches[1]); $scriptId = (isset($matches[2]) && ($matches[2] !== '')) ? ucfirst(strtolower($matches[2])) : null; $territoryId = (isset($matches[3]) && ($matches[3] !== '')) ? strtoupper($matches[3]) : null; $normalizedId = $languageId; if (isset($scriptId)) { $normalizedId .= '_'.$scriptId; } if (isset($territoryId)) { $normalizedId .= '_'.$territoryId; } // Structure precedence: see Likely Subtags - http://www.unicode.org/reports/tr35/tr35-31/tr35.html#Likely_Subtags $variants = array(); $variantsWithScript = array(); $variantsWithTerritory = array(); if (isset($scriptId) && isset($territoryId)) { $variantsWithTerritory[] = $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}_{$territoryId}"; } if (isset($scriptId)) { $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}"; } if (isset($territoryId)) { $variantsWithTerritory[] = $variants[] = "{$languageId}_{$territoryId}"; } $variants[] = $languageId; $allGood = true; $scriptName = null; $scriptStandAloneName = null; if (isset($scriptId)) { $scriptNames = self::getScriptNames(false); if (isset($scriptNames[$scriptId])) { $scriptName = $scriptNames[$scriptId]; $scriptStandAloneNames = self::getScriptNames(true); $scriptStandAloneName = $scriptStandAloneNames[$scriptId]; } else { $allGood = false; } } $territoryName = null; if (isset($territoryId)) { $territoryNames = self::getTerritoryNames(); if (isset($territoryNames[$territoryId])) { if ($territoryId !== '001') { $territoryName = $territoryNames[$territoryId]; } } else { $allGood = false; } } $languageName = null; $languageNames = self::getLanguageNames(); foreach ($variants as $variant) { if (isset($languageNames[$variant])) { $languageName = $languageNames[$variant]; if (isset($scriptName) && (!in_array($variant, $variantsWithScript))) { $languageName = $scriptName.' '.$languageName; } if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) { $languageName .= ' ('.$territoryNames[$territoryId].')'; } break; } } if (!isset($languageName)) { $allGood = false; } $baseLanguage = null; if (isset($scriptId) || isset($territoryId)) { if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) { $baseLanguage = $languageNames[$languageId]; } } $plural = null; $plurals = self::getPlurals(); foreach ($variants as $variant) { if (isset($plurals[$variant])) { $plural = $plurals[$variant]; break; } } if (!isset($plural)) { $allGood = false; } $supersededBy = null; $supersededBys = self::getSupersededLanguages(); foreach ($variants as $variant) { if (isset($supersededBys[$variant])) { $supersededBy = $supersededBys[$variant]; break; } } if ($allGood) { $result = array(); $result['id'] = $normalizedId; $result['name'] = $languageName; if (isset($supersededBy)) { $result['supersededBy'] = $supersededBy; } if (isset($scriptStandAloneName)) { $result['script'] = $scriptStandAloneName; } if (isset($territoryName)) { $result['territory'] = $territoryName; } if (isset($baseLanguage)) { $result['baseLanguage'] = $baseLanguage; } $result['categories'] = $plural; } } return $result; } } ----- File: FormulaConverter.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\FormulaConverter.php ---------------------------------------- the whole 'and' group is always false $gettextFormulaChunk = false; break; } elseif ($gettextAtom !== true) { $andSeparatedChunks[] = $gettextAtom; } } if (!isset($gettextFormulaChunk)) { if (empty($andSeparatedChunks)) { // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true $gettextFormulaChunk = true; } else { $gettextFormulaChunk = implode(' && ', $andSeparatedChunks); // Special cases simplification switch ($gettextFormulaChunk) { case 'n >= 0 && n <= 2 && n != 2': $gettextFormulaChunk = 'n == 0 || n == 1'; break; } } } if ($gettextFormulaChunk === true) { // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true return true; } elseif ($gettextFormulaChunk !== false) { $orSeparatedChunks[] = $gettextFormulaChunk; } } if (empty($orSeparatedChunks)) { // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false return false; } else { return implode(' || ', $orSeparatedChunks); } } /** * Converts an atomic part of the CLDR formula to its gettext representation. * @param string $cldrAtom The CLDR formula atom to convert. * @throws Exception * @return bool|string Returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise. */ private static function convertAtom($cldrAtom) { $m = null; $gettextAtom = $cldrAtom; $gettextAtom = str_replace(' = ', ' == ', $gettextAtom); $gettextAtom = str_replace('i', 'n', $gettextAtom); if (preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { return $gettextAtom; } if (preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { return self::expandAtom($gettextAtom); } if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return (intval($m[1]) === 0) ? true : false; } if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return (intval($m[1]) === 0) ? false : true; } if (preg_match('/^(?:f|t)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return (intval($m[1]) === 0) ? true : false; } if (preg_match('/^(?:f|t)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return (intval($m[1]) === 0) ? false : true; } throw new Exception("Unable to convert the formula chunk '$cldrAtom' from CLDR to gettext"); } /** * Expands an atom containing a range (for instance: 'n == 1,3..5'). * @param string $atom * @throws Exception * @return string */ private static function expandAtom($atom) { $m = null; if (preg_match('/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m)) { $what = $m[1]; $op = $m[2]; $chunks = array(); foreach (explode(',', $m[3]) as $range) { $chunk = null; if ((!isset($chunk)) && preg_match('/^\d+$/', $range)) { $chunk = "$what $op $range"; } if ((!isset($chunk)) && preg_match('/^(\d+)\.\.(\d+)$/', $range, $m)) { $from = intval($m[1]); $to = intval($m[2]); if (($to - $from) === 1) { switch ($op) { case '==': $chunk = "($what == $from || $what == $to)"; break; case '!=': $chunk = "$what != $from && $what == $to"; break; } } else { switch ($op) { case '==': $chunk = "$what >= $from && $what <= $to"; break; case '!=': if ($what === 'n' && $from <= 0) { $chunk = "$what > $to"; } else { $chunk = "($what < $from || $what > $to)"; } break; } } } if (!isset($chunk)) { throw new Exception("Unhandled range '$range' in '$atom'"); } $chunks[] = $chunk; } if (count($chunks) === 1) { return $chunks[0]; } switch ($op) { case '==': return '('.implode(' || ', $chunks).')';break; case '!=': return implode(' && ', $chunks); } } throw new Exception("Unable to expand '$atom'"); } } ----- File: Language.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Language.php ---------------------------------------- id = $info['id']; $this->name = $info['name']; $this->supersededBy = isset($info['supersededBy']) ? $info['supersededBy'] : null; $this->script = isset($info['script']) ? $info['script'] : null; $this->territory = isset($info['territory']) ? $info['territory'] : null; $this->baseLanguage = isset($info['baseLanguage']) ? $info['baseLanguage'] : null; // Let's build the category list $this->categories = array(); foreach ($info['categories'] as $cldrCategoryId => $cldrFormulaAndExamples) { $category = new Category($cldrCategoryId, $cldrFormulaAndExamples); foreach ($this->categories as $c) { if ($category->id === $c->id) { throw new Exception("The category '{$category->id}' is specified more than once"); } } $this->categories[] = $category; } if (empty($this->categories)) { throw new Exception("The language '{$info['id']}' does not have any plural category"); } // Let's sort the categories from 'zero' to 'other' usort($this->categories, function (Category $category1, Category $category2) { return array_search($category1->id, CldrData::$categories) - array_search($category2->id, CldrData::$categories); }); // The 'other' category should always be there if ($this->categories[count($this->categories) - 1]->id !== CldrData::OTHER_CATEGORY) { throw new Exception("The language '{$info['id']}' does not have the '".CldrData::OTHER_CATEGORY."' plural category"); } $this->checkAlwaysTrueCategories(); $this->checkAlwaysFalseCategories(); $this->checkAllCategoriesWithExamples(); $this->formula = $this->buildFormula(); } /** * Return a list of all languages available. * @throws Exception * @return Language[] */ public static function getAll() { $result = array(); foreach (array_keys(CldrData::getLanguageNames()) as $cldrLanguageId) { $result[] = new Language(CldrData::getLanguageInfo($cldrLanguageId)); } return $result; } /** * Return a Language instance given the language id * @param string $id * @return Language|null */ public static function getById($id) { $result = null; $info = CldrData::getLanguageInfo($id); if (isset($info)) { $result = new Language($info); } return $result; } /** * Let's look for categories that will always occur. * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have just one case. * If we found that (single) category we reduce the categories to that one only. */ private function checkAlwaysTrueCategories() { $alwaysTrueCategory = null; foreach ($this->categories as $category) { if ($category->formula === true) { if (!isset($category->examples)) { throw new Exception("The category '{$category->id}' should always occur, but it does not have examples (so for CLDR it will never occur for integers!)"); } $alwaysTrueCategory = $category; break; } } if (isset($alwaysTrueCategory)) { foreach ($this->categories as $category) { if (($category !== $alwaysTrueCategory) && isset($category->examples)) { throw new Exception("The category '{$category->id}' should never occur, but it has some examples (so for CLDR it will occur!)"); } } $alwaysTrueCategory->id = CldrData::OTHER_CATEGORY; $alwaysTrueCategory->formula = null; $this->categories = array($alwaysTrueCategory); } } /** * Let's look for categories that will never occur. * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. * If we found those categories we strip them out. */ private function checkAlwaysFalseCategories() { $filtered = array(); foreach ($this->categories as $category) { if ($category->formula === false) { if (isset($category->examples)) { throw new Exception("The category '{$category->id}' should never occur, but it has examples (so for CLDR it may occur!)"); } } else { $filtered[] = $category; } } $this->categories = $filtered; } /** * Let's look for categories that don't have examples. * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. * If we found those categories, we check that they never occur and we strip them out. * @throws Exception */ private function checkAllCategoriesWithExamples() { $allCategoriesIds = array(); $goodCategories = array(); $badCategories = array(); $badCategoriesIds = array(); foreach ($this->categories as $category) { $allCategoriesIds[] = $category->id; if (isset($category->examples)) { $goodCategories[] = $category; } else { $badCategories[] = $category; $badCategoriesIds[] = $category->id; } } if (empty($badCategories)) { return; } $removeCategoriesWithoutExamples = false; switch (implode(',', $badCategoriesIds).'@'.implode(',', $allCategoriesIds)) { case CldrData::OTHER_CATEGORY.'@one,few,many,'.CldrData::OTHER_CATEGORY: switch ($this->buildFormula()) { case '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) ? 2 : 3))': // Numbers ending with 0 => case 2 ('many') // Numbers ending with 1 but not with 11 => case 0 ('one') // Numbers ending with 11 => case 2 ('many') // Numbers ending with 2 but not with 12 => case 1 ('few') // Numbers ending with 12 => case 2 ('many') // Numbers ending with 3 but not with 13 => case 1 ('few') // Numbers ending with 13 => case 2 ('many') // Numbers ending with 4 but not with 14 => case 1 ('few') // Numbers ending with 14 => case 2 ('many') // Numbers ending with 5 => case 2 ('many') // Numbers ending with 6 => case 2 ('many') // Numbers ending with 7 => case 2 ('many') // Numbers ending with 8 => case 2 ('many') // Numbers ending with 9 => case 2 ('many') // => the 'other' case never occurs: use 'other' for 'many' $removeCategoriesWithoutExamples = true; break; case '(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n != 1 && (n % 10 == 0 || n % 10 == 1) || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 12 && n % 100 <= 14) ? 2 : 3))': // Numbers ending with 0 => case 2 ('many') // Numbers ending with 1 but not number 1 => case 2 ('many') // Number 1 => case 0 ('one') // Numbers ending with 2 but not with 12 => case 1 ('few') // Numbers ending with 12 => case 2 ('many') // Numbers ending with 3 but not with 13 => case 1 ('few') // Numbers ending with 13 => case 2 ('many') // Numbers ending with 4 but not with 14 => case 1 ('few') // Numbers ending with 14 => case 2 ('many') // Numbers ending with 5 => case 2 ('many') // Numbers ending with 6 => case 2 ('many') // Numbers ending with 7 => case 2 ('many') // Numbers ending with 8 => case 2 ('many') // Numbers ending with 9 => case 2 ('many') // => the 'other' case never occurs: use 'other' for 'many' $removeCategoriesWithoutExamples = true; break; } } if (!$removeCategoriesWithoutExamples) { throw new Exception("Unhandled case of plural categories without examples '".implode(', ', $badCategoriesIds)."' out of '".implode(', ', $allCategoriesIds)."'"); } if ($badCategories[count($badCategories) - 1]->id === CldrData::OTHER_CATEGORY) { // We're removing the 'other' cagory: let's change the last good category to 'other' $lastGood = $goodCategories[count($goodCategories) - 1]; $lastGood->id = CldrData::OTHER_CATEGORY; $lastGood->formula = null; } $this->categories = $goodCategories; } /** * Build the formula starting from the currently defined categories. * @return string */ private function buildFormula() { $numCategories = count($this->categories); switch ($numCategories) { case 1: // Just one category return '0'; case 2: return self::reduceFormula(self::reverseFormula($this->categories[0]->formula)); default: $formula = strval($numCategories - 1); for ($i = $numCategories - 2; $i >= 0; $i--) { $f = self::reduceFormula($this->categories[$i]->formula); if (!preg_match('/^\([^()]+\)$/', $f)) { $f = "($f)"; } $formula = "$f ? $i : $formula"; if ($i > 0) { $formula = "($formula)"; } } return $formula; } } /** * Reverse a formula. * @param string $formula * @throws Exception * @return string */ private static function reverseFormula($formula) { if (preg_match('/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula)) { return str_replace(' == ', ' != ', $formula); } if (preg_match('/^n( % \d+)? != \d+(\.\.\d+|,\d+)*?$/', $formula)) { return str_replace(' != ', ' == ', $formula); } if (preg_match('/^\(?n == \d+ \|\| n == \d+\)?$/', $formula)) { return trim(str_replace(array(' == ', ' || '), array(' != ', ' && '), $formula), '()'); } $m = null; if (preg_match('/^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$/', $formula, $m)) { return "{$m[1]} != {$m[2]} || {$m[3]} == {$m[4]}"; } switch ($formula) { case '(n == 1 || n == 2 || n == 3) || n % 10 != 4 && n % 10 != 6 && n % 10 != 9': return 'n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)'; case '(n == 0 || n == 1) || n >= 11 && n <= 99': return 'n >= 2 && (n < 11 || n > 99)'; } throw new Exception("Unable to reverse the formula '$formula'"); } /** * Reduce some excessively complex formulas. * @param string $formula * @return string */ private static function reduceFormula($formula) { $map = array( 'n != 0 && n != 1' => 'n > 1' , '(n == 0 || n == 1) && n != 0' => 'n == 1', ); return isset($map[$formula]) ? $map[$formula] : $formula; } /** * Take one variable and, if it's a string, we transliterate it to US-ASCII. * @param mixed $value The variable to work on. * @throws Exception */ private static function asciifier(&$value) { if (is_string($value) && ($value !== '')) { // Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y' $transliterated = strtr($value, array( 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ÿ' => 'Y', 'Ý' => 'Y', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'ÿ' => 'y', )); $transliterated = @iconv('UTF-8', 'US-ASCII//IGNORE//TRANSLIT', $transliterated); if (($transliterated === false) || ($transliterated === '')) { throw new Exception("Unable to transliterate '$value'"); } $value = $transliterated; } } /** * Returns a clone of this instance with all the strings to US-ASCII. * @return Language */ public function getUSAsciiClone() { $clone = clone $this; self::asciifier($clone->name); self::asciifier($clone->formula); $clone->categories = array(); foreach ($this->categories as $category) { $categoryClone = clone $category; self::asciifier($categoryClone->examples); $clone->categories[] = $categoryClone; } return $clone; } } ----- File: Docs.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Docs.php ---------------------------------------- gettext plural rules - built from CLDR
EOT; $result .= static::buildTable($languages, true); $result .= << EOT; return $result; } /** * @see Exporter::isForPublicUse */ public static function isForPublicUse() { return false; } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build the page http://mlocati.github.io/cldr-to-gettext-plural-rules'; } } ----- File: Exporter.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Exporter.php ---------------------------------------- $class) { if (call_user_func(self::getExporterClassName($handle).'::isForPublicUse') === true) { $result[$handle] = $class; } } } else { $result = self::$exporters; } return $result; } /** * Return the description of a specific exporter. * @param string $exporterHandle The handle of the exporter. * @throws Exception Throws an Exception if $exporterHandle is not valid. * @return string */ final public static function getExporterDescription($exporterHandle) { $exporters = self::getExporters(); if (!isset($exporters[$exporterHandle])) { throw new Exception("Invalid exporter handle: '$exporterHandle'"); } return call_user_func(self::getExporterClassName($exporterHandle).'::getDescription'); } /** * Returns the fully qualified class name of a exporter given its handle. * @param string $exporterHandle The exporter class handle. * @return string */ final public static function getExporterClassName($exporterHandle) { return __NAMESPACE__.'\\'.ucfirst(strtolower($exporterHandle)); } /** * Convert a list of Language instances to string. * @param Language[] $languages The Language instances to convert. * @return string */ protected static function toStringDo($languages) { throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__); } /** * Convert a list of Language instances to string. * @param Language[] $languages The Language instances to convert. * @return string */ final public static function toString($languages, $options = null) { if (isset($options) && is_array($options)) { if (isset($options['us-ascii']) && $options['us-ascii']) { $asciiList = array(); foreach ($languages as $language) { $asciiList[] = $language->getUSAsciiClone(); } $languages = $asciiList; } } return static::toStringDo($languages); } /** * Save the Language instances to a file. * @param Language[] $languages The Language instances to convert. * @throws Exception */ final public static function toFile($languages, $filename, $options = null) { $data = self::toString($languages, $options); if (@file_put_contents($filename, $data) === false) { throw new Exception("Error writing data to '$filename'"); } } /** * Is this exporter for public use? * @return bool */ public static function isForPublicUse() { return true; } /** * Return a short description of the exporter. * @return string */ public static function getDescription() { throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__); } } ----- File: Html.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Html.php ---------------------------------------- '; $lines[] = $prefix.' '; $lines[] = $prefix.' '; $lines[] = $prefix.' Language code'; $lines[] = $prefix.' Language name'; $lines[] = $prefix.' # plurals'; $lines[] = $prefix.' Formula'; $lines[] = $prefix.' Plurals'; $lines[] = $prefix.' '; $lines[] = $prefix.' '; $lines[] = $prefix.' '; foreach ($languages as $lc) { $lines[] = $prefix.' '; $lines[] = $prefix.' '.$lc->id.''; $name = self::h($lc->name); if (isset($lc->supersededBy)) { $name .= '
Superseded by '.$lc->supersededBy.''; } $lines[] = $prefix.' '.$name.''; $lines[] = $prefix.' '.count($lc->categories).''; $lines[] = $prefix.' '.self::h($lc->formula).''; $cases = array(); foreach ($lc->categories as $c) { $cases[] = '
  • '.$c->id.''.self::h($c->examples).'
  • '; } $lines[] = $prefix.' '.implode('', $cases).''; $lines[] = $prefix.' '; } $lines[] = $prefix.' '; $lines[] = $prefix.''; return implode("\n", $lines); } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build a HTML table'; } } ----- File: Json.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Json.php ---------------------------------------- name; if (isset($language->supersededBy)) { $item['supersededBy'] = $language->supersededBy; } if (isset($language->script)) { $item['script'] = $language->script; } if (isset($language->territory)) { $item['territory'] = $language->territory; } if (isset($language->baseLanguage)) { $item['baseLanguage'] = $language->baseLanguage; } $item['formula'] = $language->formula; $item['plurals'] = count($language->categories); $item['cases'] = array(); $item['examples'] = array(); foreach ($language->categories as $category) { $item['cases'][] = $category->id; $item['examples'][$category->id] = $category->examples; } $list[$language->id] = $item; } return json_encode($list, static::getEncodeOptions()); } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build a compressed JSON-encoded file'; } } ----- File: Php.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Php.php ---------------------------------------- id.'\' => array('; $lines[] = ' \'name\' => \''.addslashes($lc->name).'\','; if (isset($lc->supersededBy)) { $lines[] = ' \'supersededBy\' => \''.$lc->supersededBy.'\','; } if (isset($lc->script)) { $lines[] = ' \'script\' => \''.addslashes($lc->script).'\','; } if (isset($lc->territory)) { $lines[] = ' \'territory\' => \''.addslashes($lc->territory).'\','; } if (isset($lc->baseLanguage)) { $lines[] = ' \'baseLanguage\' => \''.addslashes($lc->baseLanguage).'\','; } $lines[] = ' \'formula\' => \''.$lc->formula.'\','; $lines[] = ' \'plurals\' => '.count($lc->categories).','; $catNames = array(); foreach ($lc->categories as $c) { $catNames[] = "'{$c->id}'"; } $lines[] = ' \'cases\' => array('.implode(', ', $catNames).'),'; $lines[] = ' \'examples\' => array('; foreach ($lc->categories as $c) { $lines[] = ' \''.$c->id.'\' => \''.$c->examples.'\','; } $lines[] = ' ),'; $lines[] = ' ),'; } $lines[] = ');'; $lines[] = ''; return implode("\n", $lines); } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build a PHP array'; } } ----- File: Po.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Po.php ---------------------------------------- id.'\n"'; $lines[] = '"Plural-Forms: nplurals='.count($language->categories).'; plural='.$language->formula.'\n"'; $lines[] = ''; return implode("\n", $lines); } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build a string to be used for gettext .po files'; } } ----- File: Prettyjson.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\cldr-to-gettext-plural-rules\Exporter\Prettyjson.php ---------------------------------------- loadXML(''); $xLanguages = $xml->firstChild; foreach ($languages as $language) { $xLanguage = $xml->createElement('language'); $xLanguage->setAttribute('id', $language->id); $xLanguage->setAttribute('name', $language->name); if (isset($language->supersededBy)) { $xLanguage->setAttribute('supersededBy', $language->supersededBy); } if (isset($language->script)) { $xLanguage->setAttribute('script', $language->script); } if (isset($language->territory)) { $xLanguage->setAttribute('territory', $language->territory); } if (isset($language->baseLanguage)) { $xLanguage->setAttribute('baseLanguage', $language->baseLanguage); } $xLanguage->setAttribute('formula', $language->formula); foreach ($language->categories as $category) { $xCategory = $xml->createElement('category'); $xCategory->setAttribute('id', $category->id); $xCategory->setAttribute('examples', $category->examples); $xLanguage->appendChild($xCategory); } $xLanguages->appendChild($xLanguage); } $xml->formatOutput = true; return $xml->saveXML(); } /** * @see Exporter::getDescription */ public static function getDescription() { return 'Build an XML file - schema available at http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd'; } } ----- File: Blade.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Blade.php ---------------------------------------- compileString($string); PhpCode::fromString($string, $translations, $options); } } ----- File: Csv.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Csv.php ---------------------------------------- ",", 'enclosure' => '"', 'escape_char' => "\\" ]; /** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $handle = fopen('php://memory', 'w'); fputs($handle, $string); rewind($handle); while ($row = self::fgetcsv($handle, $options)) { $context = array_shift($row); $original = array_shift($row); if ($context === '' && $original === '') { self::extractHeaders(array_shift($row), $translations); continue; } $translation = $translations->insert($context, $original); if (!empty($row)) { $translation->setTranslation(array_shift($row)); $translation->setPluralTranslations($row); } } fclose($handle); } } ----- File: CsvDictionary.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\CsvDictionary.php ---------------------------------------- ",", 'enclosure' => '"', 'escape_char' => "\\" ]; /** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $handle = fopen('php://memory', 'w'); fputs($handle, $string); rewind($handle); while ($row = self::fgetcsv($handle, $options)) { list($original, $translation) = $row + ['', '']; if ($original === '') { self::extractHeaders($translation, $translations); continue; } $translations->insert(null, $original)->setTranslation($translation); } fclose($handle); } } ----- File: Extractor.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Extractor.php ---------------------------------------- setDomain($headers['domain']); } if (!empty($headers['lang'])) { $translations->setLanguage($headers['lang']); } if (!empty($headers['plural-forms'])) { $translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']); } $context_glue = '\u0004'; foreach ($messages as $key => $translation) { $key = explode($context_glue, $key); $context = isset($key[1]) ? array_shift($key) : ''; $translations->insert($context, array_shift($key)) ->setTranslation(array_shift($translation)) ->setPluralTranslations($translation); } } } ----- File: JsCode.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\JsCode.php ---------------------------------------- [], 'functions' => [ 'gettext' => 'gettext', '__' => 'gettext', 'ngettext' => 'ngettext', 'n__' => 'ngettext', 'pgettext' => 'pgettext', 'p__' => 'pgettext', 'dgettext' => 'dgettext', 'd__' => 'dgettext', 'dngettext' => 'dngettext', 'dn__' => 'dngettext', 'dpgettext' => 'dpgettext', 'dp__' => 'dpgettext', 'npgettext' => 'npgettext', 'np__' => 'npgettext', 'dnpgettext' => 'dnpgettext', 'dnp__' => 'dnpgettext', 'noop' => 'noop', 'noop__' => 'noop', ], ]; /** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $functions = new JsFunctionsScanner($string); $functions->saveGettextFunctions($translations, $options); } } ----- File: Json.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Json.php ---------------------------------------- seekto($originals); $table_originals = self::readIntArray($stream, $byteOrder, $total * 2); $stream->seekto($tran); $table_translations = self::readIntArray($stream, $byteOrder, $total * 2); for ($i = 0; $i < $total; ++$i) { $next = $i * 2; $stream->seekto($table_originals[$next + 2]); $original = $stream->read($table_originals[$next + 1]); $stream->seekto($table_translations[$next + 2]); $translated = $stream->read($table_translations[$next + 1]); if ($original === '') { // Headers foreach (explode("\n", $translated) as $headerLine) { if ($headerLine === '') { continue; } $headerChunks = preg_split('/:\s*/', $headerLine, 2); $translations->setHeader($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : ''); } continue; } $chunks = explode("\x04", $original, 2); if (isset($chunks[1])) { $context = $chunks[0]; $original = $chunks[1]; } else { $context = ''; } $chunks = explode("\x00", $original, 2); if (isset($chunks[1])) { $original = $chunks[0]; $plural = $chunks[1]; } else { $plural = ''; } $translation = $translations->insert($context, $original, $plural); if ($translated === '') { continue; } if ($plural === '') { $translation->setTranslation($translated); continue; } $v = explode("\x00", $translated); $translation->setTranslation(array_shift($v)); $translation->setPluralTranslations($v); } } /** * @param StringReader $stream * @param string $byteOrder */ private static function readInt(StringReader $stream, $byteOrder) { if (($read = $stream->read(4)) === false) { return false; } $read = unpack($byteOrder, $read); return array_shift($read); } /** * @param StringReader $stream * @param string $byteOrder * @param int $count */ private static function readIntArray(StringReader $stream, $byteOrder, $count) { return unpack($byteOrder.$count, $stream->read(4 * $count)); } } ----- File: PhpArray.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\PhpArray.php ---------------------------------------- false, 'constants' => [], 'functions' => [ 'gettext' => 'gettext', '__' => 'gettext', 'ngettext' => 'ngettext', 'n__' => 'ngettext', 'pgettext' => 'pgettext', 'p__' => 'pgettext', 'dgettext' => 'dgettext', 'd__' => 'dgettext', 'dngettext' => 'dngettext', 'dn__' => 'dngettext', 'dpgettext' => 'dpgettext', 'dp__' => 'dpgettext', 'npgettext' => 'npgettext', 'np__' => 'npgettext', 'dnpgettext' => 'dnpgettext', 'dnp__' => 'dnpgettext', 'noop' => 'noop', 'noop__' => 'noop', ], ]; /** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $functions = new PhpFunctionsScanner($string); if ($options['extractComments'] !== false) { $functions->enableCommentsExtraction($options['extractComments']); } $functions->saveGettextFunctions($translations, $options); } /** * Decodes a T_CONSTANT_ENCAPSED_STRING string. * * @param string $value * * @return string */ public static function convertString($value) { if (strpos($value, '\\') === false) { return substr($value, 1, -1); } if ($value[0] === "'") { return strtr(substr($value, 1, -1), ['\\\\' => '\\', '\\\'' => '\'']); } $value = substr($value, 1, -1); return preg_replace_callback( '/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/', function ($match) { switch ($match[1][0]) { case 'n': return "\n"; case 'r': return "\r"; case 't': return "\t"; case 'v': return "\v"; case 'e': return "\e"; case 'f': return "\f"; case '$': return '$'; case '"': return '"'; case '\\': return '\\'; case 'x': return chr(hexdec(substr($match[0], 1))); case 'u': return self::unicodeChar(hexdec(substr($match[0], 1))); default: return chr(octdec($match[0])); } }, $value ); } //http://php.net/manual/en/function.chr.php#118804 private static function unicodeChar($dec) { if ($dec < 0x80) { return chr($dec); } if ($dec < 0x0800) { return chr(0xC0 + ($dec >> 6)) .chr(0x80 + ($dec & 0x3f)); } if ($dec < 0x010000) { return chr(0xE0 + ($dec >> 12)) .chr(0x80 + (($dec >> 6) & 0x3f)) .chr(0x80 + ($dec & 0x3f)); } if ($dec < 0x200000) { return chr(0xF0 + ($dec >> 18)) .chr(0x80 + (($dec >> 12) & 0x3f)) .chr(0x80 + (($dec >> 6) & 0x3f)) .chr(0x80 + ($dec & 0x3f)); } } } ----- File: Po.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Po.php ---------------------------------------- is('', '')) { self::extractHeaders($translation->getTranslation(), $translations); } elseif ($translation->hasOriginal()) { $translations[] = $translation; } $translation = new Translation('', ''); continue; } $splitLine = preg_split('/\s+/', $line, 2); $key = $splitLine[0]; $data = isset($splitLine[1]) ? $splitLine[1] : ''; switch ($key) { case '#': $translation->addComment($data); $append = null; break; case '#.': $translation->addExtractedComment($data); $append = null; break; case '#,': foreach (array_map('trim', explode(',', trim($data))) as $value) { $translation->addFlag($value); } $append = null; break; case '#:': foreach (preg_split('/\s+/', trim($data)) as $value) { if (preg_match('/^(.+)(:(\d*))?$/U', $value, $matches)) { $translation->addReference($matches[1], isset($matches[3]) ? $matches[3] : null); } } $append = null; break; case 'msgctxt': $translation = $translation->getClone(self::convertString($data)); $append = 'Context'; break; case 'msgid': $translation = $translation->getClone(null, self::convertString($data)); $append = 'Original'; break; case 'msgid_plural': $translation->setPlural(self::convertString($data)); $append = 'Plural'; break; case 'msgstr': case 'msgstr[0]': $translation->setTranslation(self::convertString($data)); $append = 'Translation'; break; case 'msgstr[1]': $translation->setPluralTranslations([self::convertString($data)]); $append = 'PluralTranslation'; break; default: if (strpos($key, 'msgstr[') === 0) { $p = $translation->getPluralTranslations(); $p[] = self::convertString($data); $translation->setPluralTranslations($p); $append = 'PluralTranslation'; break; } if (isset($append)) { if ($append === 'Context') { $translation = $translation->getClone($translation->getContext() ."\n" .self::convertString($data)); break; } if ($append === 'Original') { $translation = $translation->getClone(null, $translation->getOriginal() ."\n" .self::convertString($data)); break; } if ($append === 'PluralTranslation') { $p = $translation->getPluralTranslations(); $p[] = array_pop($p)."\n".self::convertString($data); $translation->setPluralTranslations($p); break; } $getMethod = 'get'.$append; $setMethod = 'set'.$append; $translation->$setMethod($translation->$getMethod()."\n".self::convertString($data)); } break; } } if ($translation->hasOriginal() && !in_array($translation, iterator_to_array($translations))) { $translations[] = $translation; } } /** * Gets one string from multiline strings. * * @param string $line * @param array $lines * @param int &$i * * @return string */ private static function fixMultiLines($line, array $lines, &$i) { for ($j = $i, $t = count($lines); $j < $t; ++$j) { if (substr($line, -1, 1) == '"' && isset($lines[$j + 1]) && substr(trim($lines[$j + 1]), 0, 1) == '"' ) { $line = substr($line, 0, -1).substr(trim($lines[$j + 1]), 1); } else { $i = $j; break; } } return $line; } /** * Convert a string from its PO representation. * * @param string $value * * @return string */ public static function convertString($value) { if (!$value) { return ''; } if ($value[0] === '"') { $value = substr($value, 1, -1); } return strtr( $value, [ '\\\\' => '\\', '\\a' => "\x07", '\\b' => "\x08", '\\t' => "\t", '\\n' => "\n", '\\v' => "\x0b", '\\f' => "\x0c", '\\r' => "\r", '\\"' => '"', ] ); } } ----- File: Twig.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Twig.php ---------------------------------------- 'notes:', 'twig' => null, ]; /** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $twig = $options['twig'] ?: self::createTwig(); PhpCode::fromString($twig->compileSource(new Twig_Source($string, '')), $translations, $options); } /** * Returns a Twig instance. * * @return Twig_Environment */ private static function createTwig() { $twig = new Twig_Environment(new Twig_Loader_Array(['' => ''])); $twig->addExtension(new Twig_Extensions_Extension_I18n()); return static::$options['twig'] = $twig; } } ----- File: Xliff.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Xliff.php ---------------------------------------- file as $file) { if (isset($file->notes)) { foreach ($file->notes->note as $note) { $translations->setHeader($note['id'], (string) $note); } } foreach ($file->unit as $unit) { foreach ($unit->segment as $segment) { $targets = []; foreach ($segment->target as $target) { $targets[] = (string) $target; } $translation = new Translation(null, (string) $segment->source); $translation->setTranslation(array_shift($targets)); $translation->setPluralTranslations($targets); if (isset($unit->notes)) { foreach ($unit->notes->note as $note) { switch ($note['category']) { case 'context': $translation = $translation->getClone((string) $note); break; case 'extracted-comment': $translation->addExtractedComment((string) $note); break; case 'flag': $translation->addFlag((string) $note); break; case 'reference': $ref = explode(':', (string) $note, 2); $translation->addReference($ref[0], isset($ref[1]) ? $ref[1] : null); break; default: $translation->addComment((string) $note); break; } } } $translations[] = $translation; } } } } } ----- File: Yaml.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Extractors\Yaml.php ---------------------------------------- false, 'delimiter' => ",", 'enclosure' => '"', 'escape_char' => "\\" ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; $handle = fopen('php://memory', 'w'); if ($options['includeHeaders']) { self::fputcsv($handle, ['', '', self::generateHeaders($translations)], $options); } foreach ($translations as $translation) { $line = [$translation->getContext(), $translation->getOriginal(), $translation->getTranslation()]; if ($translation->hasPluralTranslations(true)) { $line = array_merge($line, $translation->getPluralTranslations()); } self::fputcsv($handle, $line, $options); } rewind($handle); $csv = stream_get_contents($handle); fclose($handle); return $csv; } } ----- File: CsvDictionary.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\CsvDictionary.php ---------------------------------------- false, 'delimiter' => ",", 'enclosure' => '"', 'escape_char' => "\\" ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; $handle = fopen('php://memory', 'w'); foreach (self::toArray($translations, $options['includeHeaders']) as $original => $translation) { self::fputcsv($handle, [$original, $translation], $options); } rewind($handle); $csv = stream_get_contents($handle); fclose($handle); return $csv; } } ----- File: Generator.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\Generator.php ---------------------------------------- 0, ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $domain = $translations->getDomain() ?: 'messages'; $options += static::$options; return json_encode([ $domain => [ '' => [ 'domain' => $domain, 'lang' => $translations->getLanguage() ?: 'en', 'plural-forms' => $translations->getHeader('Plural-Forms') ?: 'nplurals=2; plural=(n != 1);', ], ] + self::buildMessages($translations), ], $options['json']); } /** * Generates an array with all translations. * * @param Translations $translations * * @return array */ private static function buildMessages(Translations $translations) { $pluralForm = $translations->getPluralForms(); $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; $messages = []; $context_glue = '\u0004'; foreach ($translations as $translation) { $key = ($translation->hasContext() ? $translation->getContext().$context_glue : '') .$translation->getOriginal(); if ($translation->hasPluralTranslations(true)) { $message = $translation->getPluralTranslations($pluralSize); array_unshift($message, $translation->getTranslation()); } else { $message = [$translation->getTranslation()]; } $messages[$key] = $message; } return $messages; } } ----- File: Json.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\Json.php ---------------------------------------- 0, 'includeHeaders' => false, ]; /** * {@inheritdoc} */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; return json_encode(self::toArray($translations, $options['includeHeaders'], true), $options['json']); } } ----- File: JsonDictionary.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\JsonDictionary.php ---------------------------------------- 0, 'includeHeaders' => false, ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; return json_encode(self::toArray($translations, $options['includeHeaders']), $options['json']); } } ----- File: Mo.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\Mo.php ---------------------------------------- true, ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; $messages = []; if ($options['includeHeaders']) { $messages[''] = self::generateHeaders($translations); } foreach ($translations as $translation) { if (!$translation->hasTranslation()) { continue; } if ($translation->hasContext()) { $originalString = $translation->getContext()."\x04".$translation->getOriginal(); } else { $originalString = $translation->getOriginal(); } $messages[$originalString] = $translation; } ksort($messages); $numEntries = count($messages); $originalsTable = ''; $translationsTable = ''; $originalsIndex = []; $translationsIndex = []; $pluralForm = $translations->getPluralForms(); $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; foreach ($messages as $originalString => $translation) { if (is_string($translation)) { // Headers $translationString = $translation; } else { /* @var $translation \Gettext\Translation */ if ($translation->hasPlural() && $translation->hasPluralTranslations(true)) { $originalString .= "\x00".$translation->getPlural(); $translationString = $translation->getTranslation(); $translationString .= "\x00".implode("\x00", $translation->getPluralTranslations($pluralSize)); } else { $translationString = $translation->getTranslation(); } } $originalsIndex[] = [ 'relativeOffset' => strlen($originalsTable), 'length' => strlen($originalString) ]; $originalsTable .= $originalString."\x00"; $translationsIndex[] = [ 'relativeOffset' => strlen($translationsTable), 'length' => strlen($translationString) ]; $translationsTable .= $translationString."\x00"; } // Offset of table with the original strings index: right after the header (which is 7 words) $originalsIndexOffset = 7 * 4; // Size of table with the original strings index $originalsIndexSize = $numEntries * (4 + 4); // Offset of table with the translation strings index: right after the original strings index table $translationsIndexOffset = $originalsIndexOffset + $originalsIndexSize; // Size of table with the translation strings index $translationsIndexSize = $numEntries * (4 + 4); // Hashing table starts after the header and after the index table $originalsStringsOffset = $translationsIndexOffset + $translationsIndexSize; // Translations start after the keys $translationsStringsOffset = $originalsStringsOffset + strlen($originalsTable); // Let's generate the .mo file binary data $mo = ''; // Magic number $mo .= pack('L', 0x950412de); // File format revision $mo .= pack('L', 0); // Number of strings $mo .= pack('L', $numEntries); // Offset of table with original strings $mo .= pack('L', $originalsIndexOffset); // Offset of table with translation strings $mo .= pack('L', $translationsIndexOffset); // Size of hashing table: we don't use it. $mo .= pack('L', 0); // Offset of hashing table: it would start right after the translations index table $mo .= pack('L', $translationsIndexOffset + $translationsIndexSize); // Write the lengths & offsets of the original strings foreach ($originalsIndex as $info) { $mo .= pack('L', $info['length']); $mo .= pack('L', $originalsStringsOffset + $info['relativeOffset']); } // Write the lengths & offsets of the translated strings foreach ($translationsIndex as $info) { $mo .= pack('L', $info['length']); $mo .= pack('L', $translationsStringsOffset + $info['relativeOffset']); } // Write original strings $mo .= $originalsTable; // Write translation strings $mo .= $translationsTable; return $mo; } } ----- File: PhpArray.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\PhpArray.php ---------------------------------------- true, ]; /** * {@inheritdoc} */ public static function toString(Translations $translations, array $options = []) { $array = self::generate($translations, $options); return ' false, ]; /** * {@parentDoc}. */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; $pluralForm = $translations->getPluralForms(); $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; $lines = ['msgid ""', 'msgstr ""']; foreach ($translations->getHeaders() as $name => $value) { $lines[] = sprintf('"%s: %s\\n"', $name, $value); } $lines[] = ''; //Translations foreach ($translations as $translation) { if ($translation->hasComments()) { foreach ($translation->getComments() as $comment) { $lines[] = '# '.$comment; } } if ($translation->hasExtractedComments()) { foreach ($translation->getExtractedComments() as $comment) { $lines[] = '#. '.$comment; } } if (!$options['noLocation'] && $translation->hasReferences()) { foreach ($translation->getReferences() as $reference) { $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); } } if ($translation->hasFlags()) { $lines[] = '#, '.implode(',', $translation->getFlags()); } if ($translation->hasContext()) { $lines[] = 'msgctxt '.self::convertString($translation->getContext()); } self::addLines($lines, 'msgid', $translation->getOriginal()); if ($translation->hasPlural()) { self::addLines($lines, 'msgid_plural', $translation->getPlural()); self::addLines($lines, 'msgstr[0]', $translation->getTranslation()); foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { self::addLines($lines, 'msgstr['.($k + 1).']', $v); } } else { self::addLines($lines, 'msgstr', $translation->getTranslation()); } $lines[] = ''; } return implode("\n", $lines); } /** * Escapes and adds double quotes to a string. * * @param string $string * * @return string */ private static function multilineQuote($string) { $lines = explode("\n", $string); $last = count($lines) - 1; foreach ($lines as $k => $line) { if ($k === $last) { $lines[$k] = self::convertString($line); } else { $lines[$k] = self::convertString($line."\n"); } } return $lines; } /** * Add one or more lines depending whether the string is multiline or not. * * @param array &$lines * @param string $name * @param string $value */ private static function addLines(array &$lines, $name, $value) { $newLines = self::multilineQuote($value); if (count($newLines) === 1) { $lines[] = $name.' '.$newLines[0]; } else { $lines[] = $name.' ""'; foreach ($newLines as $line) { $lines[] = $line; } } } /** * Convert a string to its PO representation. * * @param string $value * * @return string */ public static function convertString($value) { return '"'.strtr( $value, [ "\x00" => '', '\\' => '\\\\', "\t" => '\t', "\n" => '\n', '"' => '\\"', ] ).'"'; } } ----- File: Xliff.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\Xliff.php ---------------------------------------- formatOutput = true; $xliff = $dom->appendChild($dom->createElement('xliff')); $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0'); $xliff->setAttribute('version', '2.0'); $xliff->setAttribute('srcLang', $translations->getLanguage()); $xliff->setAttribute('trgLang', $translations->getLanguage()); $file = $xliff->appendChild($dom->createElement('file')); $file->setAttribute('id', $translations->getDomain().'.'.$translations->getLanguage()); //Save headers as notes $notes = $dom->createElement('notes'); foreach ($translations->getHeaders() as $name => $value) { $notes->appendChild(self::createTextNode($dom, 'note', $value))->setAttribute('id', $name); } if ($notes->hasChildNodes()) { $file->appendChild($notes); } foreach ($translations as $translation) { $unit = $dom->createElement('unit'); $unit->setAttribute('id', md5($translation->getContext().$translation->getOriginal())); //Save comments as notes $notes = $dom->createElement('notes'); $notes->appendChild(self::createTextNode($dom, 'note', $translation->getContext())) ->setAttribute('category', 'context'); foreach ($translation->getComments() as $comment) { $notes->appendChild(self::createTextNode($dom, 'note', $comment)) ->setAttribute('category', 'comment'); } foreach ($translation->getExtractedComments() as $comment) { $notes->appendChild(self::createTextNode($dom, 'note', $comment)) ->setAttribute('category', 'extracted-comment'); } foreach ($translation->getFlags() as $flag) { $notes->appendChild(self::createTextNode($dom, 'note', $flag)) ->setAttribute('category', 'flag'); } foreach ($translation->getReferences() as $reference) { $notes->appendChild(self::createTextNode($dom, 'note', $reference[0].':'.$reference[1])) ->setAttribute('category', 'reference'); } $unit->appendChild($notes); $segment = $unit->appendChild($dom->createElement('segment')); $segment->appendChild(self::createTextNode($dom, 'source', $translation->getOriginal())); $segment->appendChild(self::createTextNode($dom, 'target', $translation->getTranslation())); foreach ($translation->getPluralTranslations() as $plural) { if ($plural !== '') { $segment->appendChild(self::createTextNode($dom, 'target', $plural)); } } $file->appendChild($unit); } return $dom->saveXML(); } private static function createTextNode(DOMDocument $dom, $name, $string) { $node = $dom->createElement($name); $text = (preg_match('/[&<>]/', $string) === 1) ? $dom->createCDATASection($string) : $dom->createTextNode($string); $node->appendChild($text); return $node; } } ----- File: Yaml.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\Yaml.php ---------------------------------------- false, 'indent' => 2, 'inline' => 4, ]; /** * {@inheritdoc} */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; return YamlDumper::dump( self::toArray($translations, $options['includeHeaders']), $options['inline'], $options['indent'] ); } } ----- File: YamlDictionary.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Generators\YamlDictionary.php ---------------------------------------- false, 'indent' => 2, 'inline' => 3, ]; /** * {@inheritdoc} */ public static function toString(Translations $translations, array $options = []) { $options += static::$options; return YamlDumper::dump( self::toArray($translations, $options['includeHeaders']), $options['inline'], $options['indent'] ); } } ----- File: CsvTrait.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\CsvTrait.php ---------------------------------------- = 0; } return self::$csvEscapeChar; } /** * @param resource $handle * @param array $options * * @return array */ private static function fgetcsv($handle, $options) { if (self::supportsCsvEscapeChar()) { return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); } return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure']); } /** * @param resource $handle * @param array $fields * @param array $options * * @return bool|int */ private static function fputcsv($handle, $fields, $options) { if (self::supportsCsvEscapeChar()) { return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); } return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure']); } } ----- File: DictionaryTrait.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\DictionaryTrait.php ---------------------------------------- singular-translation). */ trait DictionaryTrait { use HeadersGeneratorTrait; use HeadersExtractorTrait; /** * Returns a plain dictionary with the format [original => translation]. * * @param Translations $translations * @param bool $includeHeaders * * @return array */ private static function toArray(Translations $translations, $includeHeaders) { $messages = []; if ($includeHeaders) { $messages[''] = self::generateHeaders($translations); } foreach ($translations as $translation) { $messages[$translation->getOriginal()] = $translation->getTranslation(); } return $messages; } /** * Extract the entries from a dictionary. * * @param array $messages * @param Translations $translations */ private static function fromArray(array $messages, Translations $translations) { foreach ($messages as $original => $translation) { if ($original === '') { self::extractHeaders($translation, $translations); continue; } $translations->insert(null, $original)->setTranslation($translation); } } } ----- File: FunctionsScanner.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\FunctionsScanner.php ---------------------------------------- getFunctions($options['constants']) as $function) { list($name, $line, $args) = $function; if (!isset($functions[$name])) { continue; } $domain = $context = $original = $plural = null; switch ($functions[$name]) { case 'noop': case 'gettext': if (!isset($args[0])) { continue 2; } $original = $args[0]; break; case 'ngettext': if (!isset($args[1])) { continue 2; } list($original, $plural) = $args; break; case 'pgettext': if (!isset($args[1])) { continue 2; } list($context, $original) = $args; break; case 'dgettext': if (!isset($args[1])) { continue 2; } list($domain, $original) = $args; break; case 'dpgettext': if (!isset($args[2])) { continue 2; } list($domain, $context, $original) = $args; break; case 'npgettext': if (!isset($args[2])) { continue 2; } list($context, $original, $plural) = $args; break; case 'dnpgettext': if (!isset($args[3])) { continue 2; } list($domain, $context, $original, $plural) = $args; break; case 'dngettext': if (!isset($args[2])) { continue 2; } list($domain, $original, $plural) = $args; break; default: throw new Exception(sprintf('Not valid function %s', $functions[$name])); } if ((string) $original !== '' && ($domain === null || $domain === $translations->getDomain())) { $translation = $translations->insert($context, $original, $plural); $translation->addReference($file, $line); if (isset($function[3])) { foreach ($function[3] as $extractedComment) { $translation->addExtractedComment($extractedComment); } } } } } } ----- File: HeadersExtractorTrait.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\HeadersExtractorTrait.php ---------------------------------------- setHeader($currentHeader, $header[1]); } else { $entry = $translations->getHeader($currentHeader); $translations->setHeader($currentHeader, $entry.$line); } } } /** * Checks if it is a header definition line. Useful for distguishing between header definitions * and possible continuations of a header entry. * * @param string $line Line to parse * * @return bool */ private static function isHeaderDefinition($line) { return (bool) preg_match('/^[\w-]+:/', $line); } /** * Normalize a string. * * @param string $value * * @return string */ public static function convertString($value) { return $value; } } ----- File: HeadersGeneratorTrait.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\HeadersGeneratorTrait.php ---------------------------------------- getHeaders() as $name => $value) { $headers .= sprintf("%s: %s\n", $name, $value); } return $headers; } } ----- File: JsFunctionsScanner.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\JsFunctionsScanner.php ---------------------------------------- code = $code; } /** * {@inheritdoc} */ public function getFunctions(array $constants = []) { $length = strlen($this->code); $line = 1; $buffer = ''; $functions = []; $bufferFunctions = []; $char = null; for ($pos = 0; $pos < $length; ++$pos) { $prev = $char; $char = $this->code[$pos]; $next = isset($this->code[$pos + 1]) ? $this->code[$pos + 1] : null; switch ($char) { case '\\': $prev = $char; $char = $next; $pos++; $next = isset($this->code[$pos]) ? $this->code[$pos] : null; break; case "\n": ++$line; if ($this->status('line-comment')) { $this->upStatus(); } break; case '/': switch ($this->status()) { case 'simple-quote': case 'double-quote': case 'line-comment': break; case 'block-comment': if ($prev === '*') { $this->upStatus(); } break; default: if ($next === '/') { $this->downStatus('line-comment'); } elseif ($next === '*') { $this->downStatus('block-comment'); } break; } break; case "'": switch ($this->status()) { case 'simple-quote': $this->upStatus(); break; case 'line-comment': case 'block-comment': case 'double-quote': break; default: $this->downStatus('simple-quote'); break; } break; case '"': switch ($this->status()) { case 'double-quote': $this->upStatus(); break; case 'line-comment': case 'block-comment': case 'simple-quote': break; default: $this->downStatus('double-quote'); break; } break; case '(': switch ($this->status()) { case 'simple-quote': case 'double-quote': case 'line-comment': case 'block-comment': case 'line-comment': break; default: if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) { $this->downStatus('function'); array_unshift($bufferFunctions, [$matches[1], $line, []]); $buffer = ''; continue 3; } break; } break; case ')': switch ($this->status()) { case 'function': if (($argument = self::prepareArgument($buffer))) { $bufferFunctions[0][2][] = $argument; } if (!empty($bufferFunctions)) { $functions[] = array_shift($bufferFunctions); } $this->upStatus(); $buffer = ''; continue 3; } break; case ',': switch ($this->status()) { case 'function': if (($argument = self::prepareArgument($buffer))) { $bufferFunctions[0][2][] = $argument; } $buffer = ''; continue 3; } break; case ' ': case '\t': switch ($this->status()) { case 'double-quote': case 'simple-quote': break; default: continue 3; } break; } switch ($this->status()) { case 'line-comment': case 'block-comment': break; default: $buffer .= $char; break; } } return $functions; } /** * Get the current context of the scan. * * @param null|string $match To check whether the current status is this value * * @return string|bool */ protected function status($match = null) { $status = isset($this->status[0]) ? $this->status[0] : null; if ($match !== null) { return $status === $match; } return $status; } /** * Add a new status to the stack. * * @param string $status */ protected function downStatus($status) { array_unshift($this->status, $status); } /** * Removes and return the current status. * * @return string|null */ protected function upStatus() { return array_shift($this->status); } /** * Prepares the arguments found in functions. * * @param string $argument * * @return string */ protected static function prepareArgument($argument) { if ($argument && ($argument[0] === '"' || $argument[0] === "'")) { return substr($argument, 1, -1); } } } ----- File: MultidimensionalArrayTrait.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\MultidimensionalArrayTrait.php ---------------------------------------- [original => [translation, plural1, pluraln...]]). */ trait MultidimensionalArrayTrait { use HeadersGeneratorTrait; use HeadersExtractorTrait; /** * Returns a multidimensional array. * * @param Translations $translations * @param bool $includeHeaders * @param bool $forceArray * * @return array */ private static function toArray(Translations $translations, $includeHeaders, $forceArray = false) { $pluralForm = $translations->getPluralForms(); $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; $messages = []; if ($includeHeaders) { $messages[''] = [ '' => [self::generateHeaders($translations)], ]; } foreach ($translations as $translation) { $context = $translation->getContext(); $original = $translation->getOriginal(); if (!isset($messages[$context])) { $messages[$context] = []; } if ($translation->hasPluralTranslations(true)) { $messages[$context][$original] = $translation->getPluralTranslations($pluralSize); array_unshift($messages[$context][$original], $translation->getTranslation()); } elseif ($forceArray) { $messages[$context][$original] = [$translation->getTranslation()]; } else { $messages[$context][$original] = $translation->getTranslation(); } } return [ 'domain' => $translations->getDomain(), 'plural-forms' => $translations->getHeader('Plural-Forms'), 'messages' => $messages, ]; } /** * Extract the entries from a multidimensional array. * * @param array $messages * @param Translations $translations */ private static function fromArray(array $messages, Translations $translations) { if (!empty($messages['domain'])) { $translations->setDomain($messages['domain']); } if (!empty($messages['plural-forms'])) { $translations->setHeader(Translations::HEADER_PLURAL, $messages['plural-forms']); } foreach ($messages['messages'] as $context => $contextTranslations) { foreach ($contextTranslations as $original => $value) { if ($context === '' && $original === '') { self::extractHeaders(is_array($value) ? array_shift($value) : $value, $translations); continue; } $translation = $translations->insert($context, $original); if (is_array($value)) { $translation->setTranslation(array_shift($value)); $translation->setPluralTranslations($value); } else { $translation->setTranslation($value); } } } } } ----- File: ParsedComment.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\ParsedComment.php ---------------------------------------- comment = $comment; $this->firstLine = $firstLine; $this->lastLine = $lastLine; } /** * Create new object from raw comment data. * * @param string $value The PHP comment string. * @param int $line The line where the comment starts. * * @return self The parsed comment. */ public static function create($value, $line) { $lastLine = $line + substr_count($value, "\n"); $lines = array_map(function ($line) { if ('' === trim($line)) { return null; } $line = ltrim($line, '#*/ '); $line = rtrim($line, '#*/ '); return trim($line); }, explode("\n", $value)); // Remove empty lines. $lines = array_filter($lines); $value = implode(' ', $lines); return new self($value, $line, $lastLine); } /** * Return the line where the comment starts. * * @return int Line number. */ public function getFirstLine() { return $this->firstLine; } /** * Return the line where the comment ends. * * @return int Line number. */ public function getLastLine() { return $this->lastLine; } /** * Return the actual comment string. * * @return string The comment. */ public function getComment() { return $this->comment; } /** * Whether this comment is related with a given function. * * @param ParsedFunction $function The function to check. * @return bool Whether the comment is related or not. */ public function isRelatedWith(ParsedFunction $function) { return $this->getLastLine() === $function->getLine() || $this->getLastLine() === $function->getLine() - 1; } /** * Whether the comment matches the required prefixes. * * @param array $prefixes An array of prefixes to check. * @return bool Whether the comment matches the prefixes or not. */ public function checkPrefixes(array $prefixes) { if ('' === $this->comment) { return false; } if (empty($prefixes)) { return true; } foreach ($prefixes as $prefix) { if (strpos($this->comment, $prefix) === 0) { return true; } } return false; } } ----- File: ParsedFunction.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\ParsedFunction.php ---------------------------------------- name = $name; $this->line = $line; $this->arguments = []; $this->argumentIndex = -1; $this->argumentStopped = false; $this->comments = null; } /** * Stop extracting strings from the current argument (because we found something that's not a string). */ public function stopArgument() { if ($this->argumentIndex === -1) { $this->argumentIndex = 0; } $this->argumentStopped = true; } /** * Go to the next argument because we a comma was found. */ public function nextArgument() { if ($this->argumentIndex === -1) { // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. $this->argumentIndex = 1; } else { ++$this->argumentIndex; } $this->argumentStopped = false; } /** * Add a string to the current argument. * * @param string|null $chunk */ public function addArgumentChunk($chunk) { if ($this->argumentStopped === false) { if ($this->argumentIndex === -1) { $this->argumentIndex = 0; } if (isset($this->arguments[$this->argumentIndex])) { $this->arguments[$this->argumentIndex] .= $chunk; } else { $this->arguments[$this->argumentIndex] = $chunk; } } } /** * Add a comment associated to this function. * * @param string $comment */ public function addComment($comment) { if ($this->comments === null) { $this->comments = []; } $this->comments[] = $comment; } /** * Return the line the function starts. * * @return int Line number. */ public function getLine() { return $this->line; } /** * A closing parenthesis was found: return the final data. * The array returned has the following values: * 0 => string The function name. * 1 => int The line where the function starts. * 2 => string[] the strings extracted from the function arguments. * 3 => string[] the comments associated to the function. * * @return array */ public function close() { $arguments = []; for ($i = 0; $i <= $this->argumentIndex; ++$i) { $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; } return [ $this->name, $this->line, $arguments, $this->comments, ]; } } ----- File: PhpFunctionsScanner.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\PhpFunctionsScanner.php ---------------------------------------- extractComments = $tag; } /** * Disable comments extraction. */ public function disableCommentsExtraction() { $this->extractComments = false; } /** * Constructor. * * @param string $code The php code to scan */ public function __construct($code) { $this->tokens = array_values( array_filter( token_get_all($code), function ($token) { return !is_array($token) || $token[0] !== 397; //T_WHITESPACE; } ) ); } /** * {@inheritdoc} */ public function getFunctions(array $constants = []) { $count = count($this->tokens); /* @var ParsedFunction[] $bufferFunctions */ $bufferFunctions = []; /* @var ParsedComment[] $bufferComments */ $bufferComments = []; /* @var array $functions */ $functions = []; for ($k = 0; $k < $count; ++$k) { $value = $this->tokens[$k]; if (is_string($value)) { if (isset($bufferFunctions[0])) { switch ($value) { case ',': $bufferFunctions[0]->nextArgument(); break; case ')': $functions[] = array_shift($bufferFunctions)->close(); break; case '.': break; default: $bufferFunctions[0]->stopArgument(); break; } } continue; } switch ($value[0]) { case 320: //T_CONSTANT_ENCAPSED_STRING: //add an argument to the current function if (isset($bufferFunctions[0])) { $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); } break; case 313: //T_STRING: if (isset($bufferFunctions[0])) { if (isset($constants[$value[1]])) { $bufferFunctions[0]->addArgumentChunk($constants[$value[1]]); break; } if (strtolower($value[1]) === 'null') { $bufferFunctions[0]->addArgumentChunk(null); break; } $bufferFunctions[0]->stopArgument(); } //new function found for ($j = $k + 1; $j < $count; ++$j) { $nextToken = $this->tokens[$j]; if (is_array($nextToken) && $nextToken[0] === 392) { //T_COMMENT) { continue; } if ($nextToken === '(') { $newFunction = new ParsedFunction($value[1], $value[2]); // add comment that was on the line before. if (isset($bufferComments[0])) { $comment = $bufferComments[0]; if ($comment->isRelatedWith($newFunction)) { $newFunction->addComment($comment->getComment()); } } array_unshift($bufferFunctions, $newFunction); $k = $j; } break; } break; case 392: //T_COMMENT: $comment = $this->parsePhpComment($value[1], $value[2]); if ($comment) { array_unshift($bufferComments, $comment); // The comment is inside the function call. if (isset($bufferFunctions[0])) { $bufferFunctions[0]->addComment($comment->getComment()); } } break; default: if (isset($bufferFunctions[0])) { $bufferFunctions[0]->stopArgument(); } break; } } return $functions; } /** * Extract the actual text from a PHP comment. * * If set, only returns comments that match the prefix(es). * * @param string $value The PHP comment. * @param int $line Line number. * * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. */ protected function parsePhpComment($value, $line) { if ($this->extractComments === false) { return null; } //this returns a comment or null $comment = ParsedComment::create($value, $line); $prefixes = array_filter((array) $this->extractComments); if ($comment && $comment->checkPrefixes($prefixes)) { return $comment; } return null; } } ----- File: StringReader.php Path completo: C:\Users\HP\Documents\Progetti\Framework\classes\vendor\Gettext\Utils\StringReader.php ---------------------------------------- str = $str; $this->strlen = strlen($this->str); } /** * Read and returns a part of the string. * * @param int $bytes The number of bytes to read * * @return string */ public function read($bytes) { $data = substr($this->str, $this->pos, $bytes); $this->seekto($this->pos + $bytes); return $data; } /** * Move the cursor to a specific position. * * @param int $pos The amount of bytes to move * * @return int The new position */ public function seekto($pos) { $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; return $this->pos; } }