init web ems all
This commit is contained in:
247
phpMyAdmin/vendor/phpmyadmin/motranslator/src/Loader.php
vendored
Executable file
247
phpMyAdmin/vendor/phpmyadmin/motranslator/src/Loader.php
vendored
Executable file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2005 Steven Armstrong <sa at c-area dot ch>
|
||||
Copyright (c) 2009 Danilo Segan <danilo@kvota.net>
|
||||
Copyright (c) 2016 Michal Čihař <michal@cihar.com>
|
||||
|
||||
This file is part of MoTranslator.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\MoTranslator;
|
||||
|
||||
class Loader
|
||||
{
|
||||
/**
|
||||
* Loader instance.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @var Loader
|
||||
*/
|
||||
private static $_instance;
|
||||
|
||||
/**
|
||||
* Default gettext domain to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $default_domain = '';
|
||||
|
||||
/**
|
||||
* Configured locale.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $locale = '';
|
||||
|
||||
/**
|
||||
* Loaded domains.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $domains = array();
|
||||
|
||||
/**
|
||||
* Bound paths for domains.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $paths = array('' => './');
|
||||
|
||||
/**
|
||||
* Returns the singleton Loader object.
|
||||
*
|
||||
* @return Loader object
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (empty(self::$_instance)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads global localizaton functions.
|
||||
*/
|
||||
public static function loadFunctions()
|
||||
{
|
||||
require_once __DIR__ . '/functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out all possible locale names and start with the most
|
||||
* specific ones. I.e. for sr_CS.UTF-8@latin, look through all of
|
||||
* sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr.
|
||||
*
|
||||
* @param string $locale Locale code
|
||||
*
|
||||
* @return array list of locales to try for any POSIX-style locale specification
|
||||
*/
|
||||
public static function listLocales($locale)
|
||||
{
|
||||
$locale_names = array();
|
||||
|
||||
$lang = null;
|
||||
$country = null;
|
||||
$charset = null;
|
||||
$modifier = null;
|
||||
|
||||
if ($locale) {
|
||||
if (preg_match('/^(?P<lang>[a-z]{2,3})' // language code
|
||||
. '(?:_(?P<country>[A-Z]{2}))?' // country code
|
||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?' // charset
|
||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/', // @ modifier
|
||||
$locale, $matches)) {
|
||||
extract($matches);
|
||||
|
||||
if ($modifier) {
|
||||
if ($country) {
|
||||
if ($charset) {
|
||||
array_push($locale_names, "${lang}_$country.$charset@$modifier");
|
||||
}
|
||||
array_push($locale_names, "${lang}_$country@$modifier");
|
||||
} elseif ($charset) {
|
||||
array_push($locale_names, "${lang}.$charset@$modifier");
|
||||
}
|
||||
array_push($locale_names, "$lang@$modifier");
|
||||
}
|
||||
if ($country) {
|
||||
if ($charset) {
|
||||
array_push($locale_names, "${lang}_$country.$charset");
|
||||
}
|
||||
array_push($locale_names, "${lang}_$country");
|
||||
} elseif ($charset) {
|
||||
array_push($locale_names, "${lang}.$charset");
|
||||
}
|
||||
array_push($locale_names, $lang);
|
||||
}
|
||||
|
||||
// If the locale name doesn't match POSIX style, just include it as-is.
|
||||
if (!in_array($locale, $locale_names)) {
|
||||
array_push($locale_names, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
return $locale_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Translator object for domain or for default domain.
|
||||
*
|
||||
* @param string $domain Translation domain
|
||||
*
|
||||
* @return Translator
|
||||
*/
|
||||
public function getTranslator($domain = '')
|
||||
{
|
||||
if (empty($domain)) {
|
||||
$domain = $this->default_domain;
|
||||
}
|
||||
|
||||
if (!isset($this->domains[$this->locale])) {
|
||||
$this->domains[$this->locale] = array();
|
||||
}
|
||||
|
||||
if (!isset($this->domains[$this->locale][$domain])) {
|
||||
if (isset($this->paths[$domain])) {
|
||||
$base = $this->paths[$domain];
|
||||
} else {
|
||||
$base = './';
|
||||
}
|
||||
|
||||
$locale_names = $this->listLocales($this->locale);
|
||||
|
||||
$filename = '';
|
||||
foreach ($locale_names as $locale) {
|
||||
$filename = "$base/$locale/LC_MESSAGES/$domain.mo";
|
||||
if (file_exists($filename)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// We don't care about invalid path, we will get fallback
|
||||
// translator here
|
||||
$this->domains[$this->locale][$domain] = new Translator($filename);
|
||||
}
|
||||
|
||||
return $this->domains[$this->locale][$domain];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path for a domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
public function bindtextdomain($domain, $path)
|
||||
{
|
||||
$this->paths[$domain] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
public function textdomain($domain)
|
||||
{
|
||||
$this->default_domain = $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a requested locale.
|
||||
*
|
||||
* @param string $locale Locale name
|
||||
*
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
public function setlocale($locale)
|
||||
{
|
||||
if (!empty($locale)) {
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects currently configured locale.
|
||||
*
|
||||
* It checks:
|
||||
*
|
||||
* - global lang variable
|
||||
* - environment for LC_ALL, LC_MESSAGES and LANG
|
||||
*
|
||||
* @return string with locale name
|
||||
*/
|
||||
public function detectlocale()
|
||||
{
|
||||
if (isset($GLOBALS['lang'])) {
|
||||
return $GLOBALS['lang'];
|
||||
} elseif (getenv('LC_ALL')) {
|
||||
return getenv('LC_ALL');
|
||||
} elseif (getenv('LC_MESSAGES')) {
|
||||
return getenv('LC_MESSAGES');
|
||||
} elseif (getenv('LANG')) {
|
||||
return getenv('LANG');
|
||||
}
|
||||
|
||||
return 'en';
|
||||
}
|
||||
}
|
||||
30
phpMyAdmin/vendor/phpmyadmin/motranslator/src/ReaderException.php
vendored
Executable file
30
phpMyAdmin/vendor/phpmyadmin/motranslator/src/ReaderException.php
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
Copyright (c) 2016 Michal Čihař <michal@cihar.com>
|
||||
|
||||
This file is part of MoTranslator.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\MoTranslator;
|
||||
|
||||
/**
|
||||
* Exception thrown when file can not be read.
|
||||
*/
|
||||
class ReaderException extends \Exception
|
||||
{
|
||||
}
|
||||
97
phpMyAdmin/vendor/phpmyadmin/motranslator/src/StringReader.php
vendored
Executable file
97
phpMyAdmin/vendor/phpmyadmin/motranslator/src/StringReader.php
vendored
Executable file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
Copyright (c) 2016 Michal Čihař <michal@cihar.com>
|
||||
|
||||
This file is part of MoTranslator.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\MoTranslator;
|
||||
|
||||
/**
|
||||
* Simple wrapper around string buffer for
|
||||
* random access and values parsing.
|
||||
*/
|
||||
class StringReader
|
||||
{
|
||||
private $_str;
|
||||
private $_len;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $filename Name of file to load
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->_str = file_get_contents($filename);
|
||||
$this->_len = strlen($this->_str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read number of bytes from given offset.
|
||||
*
|
||||
* @param int $pos Offset
|
||||
* @param int $bytes Number of bytes to read
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read($pos, $bytes)
|
||||
{
|
||||
if ($pos + $bytes > $this->_len) {
|
||||
throw new ReaderException('Not enough bytes!');
|
||||
}
|
||||
|
||||
return substr($this->_str, $pos, $bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a 32bit integer from the stream.
|
||||
*
|
||||
* @param string $unpack Unpack string
|
||||
* @param int $pos Position
|
||||
*
|
||||
* @return int Ingerer from the stream
|
||||
*/
|
||||
public function readint($unpack, $pos)
|
||||
{
|
||||
$data = unpack($unpack, $this->read($pos, 4));
|
||||
$result = $data[1];
|
||||
|
||||
/* We're reading unsigned int, but PHP will happily
|
||||
* give us negative number on 32-bit platforms.
|
||||
*
|
||||
* See also documentation:
|
||||
* https://secure.php.net/manual/en/function.unpack.php#refsect1-function.unpack-notes
|
||||
*/
|
||||
return $result < 0 ? PHP_INT_MAX : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an array of integers from the stream.
|
||||
*
|
||||
* @param string $unpack Unpack string
|
||||
* @param int $pos Position
|
||||
* @param int $count How many elements should be read
|
||||
*
|
||||
* @return array Array of Integers
|
||||
*/
|
||||
public function readintarray($unpack, $pos, $count)
|
||||
{
|
||||
return unpack($unpack . $count, $this->read($pos, 4 * $count));
|
||||
}
|
||||
}
|
||||
375
phpMyAdmin/vendor/phpmyadmin/motranslator/src/Translator.php
vendored
Executable file
375
phpMyAdmin/vendor/phpmyadmin/motranslator/src/Translator.php
vendored
Executable file
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
Copyright (c) 2005 Nico Kaiser <nico@siriux.net>
|
||||
Copyright (c) 2016 Michal Čihař <michal@cihar.com>
|
||||
|
||||
This file is part of MoTranslator.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\MoTranslator;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
|
||||
/**
|
||||
* Provides a simple gettext replacement that works independently from
|
||||
* the system's gettext abilities.
|
||||
* It can read MO files and use them for translating strings.
|
||||
*
|
||||
* It caches ll strings and translations to speed up the string lookup.
|
||||
*/
|
||||
class Translator
|
||||
{
|
||||
/**
|
||||
* None error.
|
||||
*/
|
||||
const ERROR_NONE = 0;
|
||||
/**
|
||||
* File does not exist.
|
||||
*/
|
||||
const ERROR_DOES_NOT_EXIST = 1;
|
||||
/**
|
||||
* File has bad magic number.
|
||||
*/
|
||||
const ERROR_BAD_MAGIC = 2;
|
||||
/**
|
||||
* Error while reading file, probably too short.
|
||||
*/
|
||||
const ERROR_READING = 3;
|
||||
|
||||
/**
|
||||
* Big endian mo file magic bytes.
|
||||
*/
|
||||
const MAGIC_BE = "\x95\x04\x12\xde";
|
||||
/**
|
||||
* Little endian mo file magic bytes.
|
||||
*/
|
||||
const MAGIC_LE = "\xde\x12\x04\x95";
|
||||
|
||||
/**
|
||||
* Parse error code (0 if no error).
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $error = self::ERROR_NONE;
|
||||
|
||||
/**
|
||||
* Cache header field for plural forms.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $pluralequation = null;
|
||||
/**
|
||||
* @var ExpressionLanguage|null Evaluator for plurals
|
||||
*/
|
||||
private $pluralexpression = null;
|
||||
/**
|
||||
* @var int|null number of plurals
|
||||
*/
|
||||
private $pluralcount = null;
|
||||
/**
|
||||
* Array with original -> translation mapping.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $cache_translations = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $filename Name of mo file to load
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (!is_readable($filename)) {
|
||||
$this->error = self::ERROR_DOES_NOT_EXIST;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$stream = new StringReader($filename);
|
||||
|
||||
try {
|
||||
$magic = $stream->read(0, 4);
|
||||
if (strcmp($magic, self::MAGIC_LE) == 0) {
|
||||
$unpack = 'V';
|
||||
} elseif (strcmp($magic, self::MAGIC_BE) == 0) {
|
||||
$unpack = 'N';
|
||||
} else {
|
||||
$this->error = self::ERROR_BAD_MAGIC;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Parse header */
|
||||
$total = $stream->readint($unpack, 8);
|
||||
$originals = $stream->readint($unpack, 12);
|
||||
$translations = $stream->readint($unpack, 16);
|
||||
|
||||
/* get original and translations tables */
|
||||
$table_originals = $stream->readintarray($unpack, $originals, $total * 2);
|
||||
$table_translations = $stream->readintarray($unpack, $translations, $total * 2);
|
||||
|
||||
/* read all strings to the cache */
|
||||
for ($i = 0; $i < $total; ++$i) {
|
||||
$original = $stream->read($table_originals[$i * 2 + 2], $table_originals[$i * 2 + 1]);
|
||||
$translation = $stream->read($table_translations[$i * 2 + 2], $table_translations[$i * 2 + 1]);
|
||||
$this->cache_translations[$original] = $translation;
|
||||
}
|
||||
} catch (ReaderException $e) {
|
||||
$this->error = self::ERROR_READING;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
public function gettext($msgid)
|
||||
{
|
||||
if (array_key_exists($msgid, $this->cache_translations)) {
|
||||
return $this->cache_translations[$msgid];
|
||||
}
|
||||
|
||||
return $msgid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is translated.
|
||||
*
|
||||
* @param string $msgid String to be checked
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($msgid)
|
||||
{
|
||||
return array_key_exists($msgid, $this->cache_translations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize plural form expression for use in ExpressionLanguage.
|
||||
*
|
||||
* @param string $expr Expression to sanitize
|
||||
*
|
||||
* @return string sanitized plural form expression
|
||||
*/
|
||||
public static function sanitizePluralExpression($expr)
|
||||
{
|
||||
// Parse equation
|
||||
$expr = explode(';', $expr);
|
||||
if (count($expr) >= 2) {
|
||||
$expr = $expr[1];
|
||||
} else {
|
||||
$expr = $expr[0];
|
||||
}
|
||||
$expr = trim(strtolower($expr));
|
||||
// Strip plural prefix
|
||||
if (substr($expr, 0, 6) === 'plural') {
|
||||
$expr = ltrim(substr($expr, 6));
|
||||
}
|
||||
// Strip equals
|
||||
if (substr($expr, 0, 1) === '=') {
|
||||
$expr = ltrim(substr($expr, 1));
|
||||
}
|
||||
|
||||
// Cleanup from unwanted chars
|
||||
$expr = preg_replace('@[^n0-9:\(\)\?=!<>/%&| ]@', '', $expr);
|
||||
|
||||
return $expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts number of plurals from plurals form expression.
|
||||
*
|
||||
* @param string $expr Expression to process
|
||||
*
|
||||
* @return int Total number of plurals
|
||||
*/
|
||||
public static function extractPluralCount($expr)
|
||||
{
|
||||
$parts = explode(';', $expr, 2);
|
||||
$nplurals = explode('=', trim($parts[0]), 2);
|
||||
if (strtolower(rtrim($nplurals[0])) != 'nplurals') {
|
||||
return 1;
|
||||
}
|
||||
if (count($nplurals) == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return intval($nplurals[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse full PO header and extract only plural forms line.
|
||||
*
|
||||
* @param string $header Gettext header
|
||||
*
|
||||
* @return string verbatim plural form header field
|
||||
*/
|
||||
public static function extractPluralsForms($header)
|
||||
{
|
||||
$headers = explode("\n", $header);
|
||||
$expr = 'nplurals=2; plural=n == 1 ? 0 : 1;';
|
||||
foreach ($headers as $header) {
|
||||
if (stripos($header, 'Plural-Forms:') === 0) {
|
||||
$expr = substr($header, 13);
|
||||
}
|
||||
}
|
||||
|
||||
return $expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get possible plural forms from MO header.
|
||||
*
|
||||
* @return string plural form header
|
||||
*/
|
||||
private function getPluralForms()
|
||||
{
|
||||
// lets assume message number 0 is header
|
||||
// this is true, right?
|
||||
|
||||
// cache header field for plural forms
|
||||
if (is_null($this->pluralequation)) {
|
||||
if (isset($this->cache_translations[''])) {
|
||||
$header = $this->cache_translations[''];
|
||||
} else {
|
||||
$header = '';
|
||||
}
|
||||
$expr = $this->extractPluralsForms($header);
|
||||
$this->pluralequation = $this->sanitizePluralExpression($expr);
|
||||
$this->pluralcount = $this->extractPluralCount($expr);
|
||||
}
|
||||
|
||||
return $this->pluralequation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects which plural form to take.
|
||||
*
|
||||
* @param int $n count of objects
|
||||
*
|
||||
* @return int array index of the right plural form
|
||||
*/
|
||||
private function selectString($n)
|
||||
{
|
||||
if (is_null($this->pluralexpression)) {
|
||||
$this->pluralexpression = new ExpressionLanguage();
|
||||
}
|
||||
try {
|
||||
$plural = $this->pluralexpression->evaluate(
|
||||
$this->getPluralForms(), array('n' => $n)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$plural = 0;
|
||||
}
|
||||
|
||||
if ($plural >= $this->pluralcount) {
|
||||
$plural = $this->pluralcount - 1;
|
||||
}
|
||||
|
||||
return $plural;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext.
|
||||
*
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
public function ngettext($msgid, $msgidPlural, $number)
|
||||
{
|
||||
// this should contains all strings separated by NULLs
|
||||
$key = implode(chr(0), array($msgid, $msgidPlural));
|
||||
if (!array_key_exists($key, $this->cache_translations)) {
|
||||
return ($number != 1) ? $msgidPlural : $msgid;
|
||||
}
|
||||
|
||||
// find out the appropriate form
|
||||
$select = $this->selectString($number);
|
||||
|
||||
$result = $this->cache_translations[$key];
|
||||
$list = explode(chr(0), $result);
|
||||
|
||||
if (!isset($list[$select])) {
|
||||
return $list[0];
|
||||
}
|
||||
|
||||
return $list[$select];
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with context.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
public function pgettext($msgctxt, $msgid)
|
||||
{
|
||||
$key = implode(chr(4), array($msgctxt, $msgid));
|
||||
$ret = $this->gettext($key);
|
||||
if (strpos($ret, chr(4)) !== false) {
|
||||
return $msgid;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of pgettext.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
public function npgettext($msgctxt, $msgid, $msgidPlural, $number)
|
||||
{
|
||||
$key = implode(chr(4), array($msgctxt, $msgid));
|
||||
$ret = $this->ngettext($key, $msgidPlural, $number);
|
||||
if (strpos($ret, chr(4)) !== false) {
|
||||
return $msgid;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set translation in place
|
||||
*
|
||||
* @param string $msgid String to be set
|
||||
* @param string $msgstr Translation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setTranslation($msgid, $msgstr)
|
||||
{
|
||||
$this->cache_translations[$msgid] = $msgstr;
|
||||
}
|
||||
}
|
||||
215
phpMyAdmin/vendor/phpmyadmin/motranslator/src/functions.php
vendored
Executable file
215
phpMyAdmin/vendor/phpmyadmin/motranslator/src/functions.php
vendored
Executable file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2005 Steven Armstrong <sa at c-area dot ch>
|
||||
Copyright (c) 2009 Danilo Segan <danilo@kvota.net>
|
||||
Copyright (c) 2016 Michal Čihař <michal@cihar.com>
|
||||
|
||||
This file is part of MoTranslator.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\MoTranslator\Loader;
|
||||
|
||||
/**
|
||||
* Sets a requested locale.
|
||||
*
|
||||
* @param int $category Locale category, ignored
|
||||
* @param string $locale Locale name
|
||||
*
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
function _setlocale($category, $locale)
|
||||
{
|
||||
return Loader::getInstance()->setlocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path for a domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
function _bindtextdomain($domain, $path)
|
||||
{
|
||||
Loader::getInstance()->bindtextdomain($domain, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy compatibility function, MoTranslator assumes
|
||||
* everything is using same character set on input and
|
||||
* output.
|
||||
*
|
||||
* Generally it is wise to output in UTF-8 and have
|
||||
* mo files in UTF-8.
|
||||
*
|
||||
* @param mixed $domain Domain where to set character set
|
||||
* @param mixed $codeset Character set to set
|
||||
*/
|
||||
function _bind_textdomain_codeset($domain, $codeset)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
function _textdomain($domain)
|
||||
{
|
||||
Loader::getInstance()->textdomain($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function _gettext($msgid)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string, alias for _gettext.
|
||||
*
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __($msgid)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext.
|
||||
*
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _ngettext($msgid, $msgidPlural, $number)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator()->ngettext(
|
||||
$msgid, $msgidPlural, $number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with context.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _pgettext($msgctxt, $msgid)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator()->pgettext(
|
||||
$msgctxt, $msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of pgettext.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _npgettext($msgctxt, $msgid, $msgidPlural, $number)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator()->npgettext(
|
||||
$msgctxt, $msgid, $msgidPlural, $number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function _dgettext($domain, $msgid)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator($domain)->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _dngettext($domain, $msgid, $msgidPlural, $number)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator($domain)->ngettext(
|
||||
$msgid, $msgidPlural, $number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with context.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _dpgettext($domain, $msgctxt, $msgid)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator($domain)->pgettext(
|
||||
$msgctxt, $msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of pgettext.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function _dnpgettext($domain, $msgctxt, $msgid, $msgidPlural, $number)
|
||||
{
|
||||
return Loader::getInstance()->getTranslator($domain)->npgettext(
|
||||
$msgctxt, $msgid, $msgidPlural, $number
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user