2015-09-05 00:24:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-11 09:58:15 +00:00
|
|
|
* PrivateBin
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
2016-07-11 09:58:15 +00:00
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
2015-09-05 00:24:56 +00:00
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
2016-07-19 11:56:52 +00:00
|
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2023-12-15 06:20:20 +00:00
|
|
|
* @version 1.6.2
|
2015-09-05 00:24:56 +00:00
|
|
|
*/
|
2016-12-12 17:43:23 +00:00
|
|
|
|
2016-12-12 17:50:00 +00:00
|
|
|
namespace PrivateBin;
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2023-12-09 10:39:53 +00:00
|
|
|
use AppendIterator;
|
|
|
|
use GlobIterator;
|
|
|
|
|
2015-09-05 00:24:56 +00:00
|
|
|
/**
|
2016-08-09 09:54:42 +00:00
|
|
|
* I18n
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
|
|
|
* provides internationalization tools like translation, browser language detection, etc.
|
|
|
|
*/
|
2016-08-09 09:54:42 +00:00
|
|
|
class I18n
|
2015-09-05 00:24:56 +00:00
|
|
|
{
|
2015-09-06 17:21:17 +00:00
|
|
|
/**
|
|
|
|
* language
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $_language = 'en';
|
|
|
|
|
2015-10-18 18:38:07 +00:00
|
|
|
/**
|
|
|
|
* language fallback
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $_languageFallback = 'en';
|
|
|
|
|
2015-09-19 09:21:13 +00:00
|
|
|
/**
|
|
|
|
* language labels
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $_languageLabels = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* available languages
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $_availableLanguages = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* path to language files
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $_path = '';
|
|
|
|
|
2015-09-05 00:24:56 +00:00
|
|
|
/**
|
|
|
|
* translation cache
|
|
|
|
*
|
2015-09-06 17:21:17 +00:00
|
|
|
* @access protected
|
2015-09-05 00:24:56 +00:00
|
|
|
* @static
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-09-06 17:21:17 +00:00
|
|
|
protected static $_translations = array();
|
2015-09-05 00:24:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* translate a string, alias for translate()
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @param string $messageId
|
|
|
|
* @param mixed $args one or multiple parameters injected into placeholders
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function _($messageId)
|
|
|
|
{
|
2022-10-25 05:15:09 +00:00
|
|
|
return forward_static_call_array('PrivateBin\I18n::translate', func_get_args());
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* translate a string
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @param string $messageId
|
|
|
|
* @param mixed $args one or multiple parameters injected into placeholders
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function translate($messageId)
|
|
|
|
{
|
2016-07-26 06:19:35 +00:00
|
|
|
if (empty($messageId)) {
|
|
|
|
return $messageId;
|
|
|
|
}
|
|
|
|
if (count(self::$_translations) === 0) {
|
|
|
|
self::loadTranslations();
|
|
|
|
}
|
2015-09-06 17:21:17 +00:00
|
|
|
$messages = $messageId;
|
2016-07-26 06:19:35 +00:00
|
|
|
if (is_array($messageId)) {
|
2015-09-06 17:21:17 +00:00
|
|
|
$messageId = count($messageId) > 1 ? $messageId[1] : $messageId[0];
|
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!array_key_exists($messageId, self::$_translations)) {
|
2015-09-06 17:21:17 +00:00
|
|
|
self::$_translations[$messageId] = $messages;
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
$args = func_get_args();
|
2016-07-26 06:19:35 +00:00
|
|
|
if (is_array(self::$_translations[$messageId])) {
|
2015-09-06 17:21:17 +00:00
|
|
|
$number = (int) $args[1];
|
2016-08-15 14:45:47 +00:00
|
|
|
$key = self::_getPluralForm($number);
|
|
|
|
$max = count(self::$_translations[$messageId]) - 1;
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($key > $max) {
|
|
|
|
$key = $max;
|
|
|
|
}
|
2015-09-06 17:21:17 +00:00
|
|
|
|
|
|
|
$args[0] = self::$_translations[$messageId][$key];
|
|
|
|
$args[1] = $number;
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2015-09-06 17:21:17 +00:00
|
|
|
$args[0] = self::$_translations[$messageId];
|
|
|
|
}
|
2020-02-01 07:46:59 +00:00
|
|
|
// encode any non-integer arguments and the message ID, if it doesn't contain a link
|
|
|
|
$argsCount = count($args);
|
|
|
|
if ($argsCount > 1) {
|
|
|
|
for ($i = 0; $i < $argsCount; ++$i) {
|
|
|
|
if (($i > 0 && !is_int($args[$i])) || strpos($args[0], '<a') === false) {
|
2020-02-01 08:15:14 +00:00
|
|
|
$args[$i] = self::encode($args[$i]);
|
2020-02-01 07:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-05 00:24:56 +00:00
|
|
|
return call_user_func_array('sprintf', $args);
|
|
|
|
}
|
|
|
|
|
2020-02-01 08:15:14 +00:00
|
|
|
/**
|
|
|
|
* encode HTML entities for output into an HTML5 document
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @param string $string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function encode($string)
|
|
|
|
{
|
|
|
|
return htmlspecialchars($string, ENT_QUOTES | ENT_HTML5 | ENT_DISALLOWED, 'UTF-8', false);
|
|
|
|
}
|
|
|
|
|
2015-09-05 00:24:56 +00:00
|
|
|
/**
|
|
|
|
* loads translations
|
|
|
|
*
|
2016-07-19 11:56:52 +00:00
|
|
|
* From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
2015-09-19 09:21:13 +00:00
|
|
|
* @access public
|
2015-09-05 00:24:56 +00:00
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
public static function loadTranslations()
|
|
|
|
{
|
2015-09-19 09:21:13 +00:00
|
|
|
$availableLanguages = self::getAvailableLanguages();
|
|
|
|
|
|
|
|
// check if the lang cookie was set and that language exists
|
2017-03-24 23:58:59 +00:00
|
|
|
if (
|
|
|
|
array_key_exists('lang', $_COOKIE) &&
|
|
|
|
($key = array_search($_COOKIE['lang'], $availableLanguages)) !== false
|
|
|
|
) {
|
|
|
|
$match = $availableLanguages[$key];
|
2015-09-19 09:21:13 +00:00
|
|
|
}
|
|
|
|
// find a translation file matching the browsers language preferences
|
2016-07-26 06:19:35 +00:00
|
|
|
else {
|
2015-09-19 09:21:13 +00:00
|
|
|
$match = self::_getMatchingLanguage(
|
|
|
|
self::getBrowserLanguages(), $availableLanguages
|
|
|
|
);
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// load translations
|
2016-08-15 14:45:47 +00:00
|
|
|
self::$_language = $match;
|
2019-05-13 20:31:52 +00:00
|
|
|
self::$_translations = ($match == 'en') ? array() : Json::decode(
|
|
|
|
file_get_contents(self::_getPath($match . '.json'))
|
2015-09-19 09:21:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get list of available translations based on files found
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAvailableLanguages()
|
|
|
|
{
|
2016-07-26 06:19:35 +00:00
|
|
|
if (count(self::$_availableLanguages) == 0) {
|
2023-12-09 10:39:53 +00:00
|
|
|
self::$_availableLanguages[] = 'en'; // en.json is not part of the release archive
|
2023-12-09 11:00:57 +00:00
|
|
|
$languageIterator = new AppendIterator();
|
2023-12-09 10:39:53 +00:00
|
|
|
$languageIterator->append(new GlobIterator(self::_getPath('??.json')));
|
|
|
|
$languageIterator->append(new GlobIterator(self::_getPath('???.json'))); // for jbo
|
|
|
|
foreach ($languageIterator as $file) {
|
|
|
|
$language = $file->getBasename('.json');
|
|
|
|
if ($language != 'en') {
|
|
|
|
self::$_availableLanguages[] = $language;
|
2015-09-19 09:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
2015-09-19 09:21:13 +00:00
|
|
|
return self::$_availableLanguages;
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* detect the clients supported languages and return them ordered by preference
|
|
|
|
*
|
2016-07-19 11:56:52 +00:00
|
|
|
* From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
2015-09-19 09:21:13 +00:00
|
|
|
* @access public
|
|
|
|
* @static
|
2015-09-05 00:24:56 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getBrowserLanguages()
|
|
|
|
{
|
|
|
|
$languages = array();
|
2016-07-26 06:19:35 +00:00
|
|
|
if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$languageRanges = explode(',', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']));
|
2016-07-26 06:19:35 +00:00
|
|
|
foreach ($languageRanges as $languageRange) {
|
2015-09-05 00:24:56 +00:00
|
|
|
if (preg_match(
|
|
|
|
'/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/',
|
|
|
|
trim($languageRange), $match
|
2016-07-26 06:19:35 +00:00
|
|
|
)) {
|
|
|
|
if (!isset($match[2])) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$match[2] = '1.0';
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2015-09-05 00:24:56 +00:00
|
|
|
$match[2] = (string) floatval($match[2]);
|
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!isset($languages[$match[2]])) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$languages[$match[2]] = array();
|
|
|
|
}
|
|
|
|
$languages[$match[2]][] = strtolower($match[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
krsort($languages);
|
|
|
|
}
|
|
|
|
return $languages;
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:21:13 +00:00
|
|
|
/**
|
|
|
|
* get currently loaded language
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getLanguage()
|
|
|
|
{
|
|
|
|
return self::$_language;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get list of language labels
|
|
|
|
*
|
|
|
|
* Only for given language codes, otherwise all labels.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @param array $languages
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getLanguageLabels($languages = array())
|
|
|
|
{
|
|
|
|
$file = self::_getPath('languages.json');
|
2016-07-26 06:19:35 +00:00
|
|
|
if (count(self::$_languageLabels) == 0 && is_readable($file)) {
|
2019-05-13 20:31:52 +00:00
|
|
|
self::$_languageLabels = Json::decode(file_get_contents($file));
|
2015-09-19 09:21:13 +00:00
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (count($languages) == 0) {
|
|
|
|
return self::$_languageLabels;
|
|
|
|
}
|
2015-09-19 09:21:13 +00:00
|
|
|
return array_intersect_key(self::$_languageLabels, array_flip($languages));
|
|
|
|
}
|
|
|
|
|
2023-09-19 05:29:00 +00:00
|
|
|
/**
|
|
|
|
* determines if the current language is written right-to-left (RTL)
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isRtl()
|
|
|
|
{
|
|
|
|
return in_array(self::$_language, array('ar', 'he'));
|
|
|
|
}
|
|
|
|
|
2015-10-18 18:38:07 +00:00
|
|
|
/**
|
|
|
|
* set the default language
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
* @param string $lang
|
|
|
|
*/
|
|
|
|
public static function setLanguageFallback($lang)
|
|
|
|
{
|
2016-07-26 06:19:35 +00:00
|
|
|
if (in_array($lang, self::getAvailableLanguages())) {
|
2015-10-18 18:38:07 +00:00
|
|
|
self::$_languageFallback = $lang;
|
2016-07-26 06:19:35 +00:00
|
|
|
}
|
2015-10-18 18:38:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 09:21:13 +00:00
|
|
|
/**
|
|
|
|
* get language file path
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @param string $file
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected static function _getPath($file = '')
|
|
|
|
{
|
2016-07-26 06:19:35 +00:00
|
|
|
if (strlen(self::$_path) == 0) {
|
2015-09-19 09:21:13 +00:00
|
|
|
self::$_path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'i18n';
|
|
|
|
}
|
|
|
|
return self::$_path . (strlen($file) ? DIRECTORY_SEPARATOR . $file : '');
|
|
|
|
}
|
|
|
|
|
2015-09-06 17:21:17 +00:00
|
|
|
/**
|
|
|
|
* determines the plural form to use based on current language and given number
|
|
|
|
*
|
2022-04-05 05:22:07 +00:00
|
|
|
* From: https://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
|
2015-09-06 17:21:17 +00:00
|
|
|
*
|
2015-09-19 09:21:13 +00:00
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @param int $n
|
2015-09-06 17:21:17 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
protected static function _getPluralForm($n)
|
|
|
|
{
|
|
|
|
switch (self::$_language) {
|
2023-08-01 12:00:45 +00:00
|
|
|
case 'ar':
|
|
|
|
return $n === 0 ? 0 : ($n === 1 ? 1 : ($n === 2 ? 2 : ($n % 100 >= 3 && $n % 100 <= 10 ? 3 : ($n % 100 >= 11 ? 4 : 5))));
|
2019-06-23 10:06:36 +00:00
|
|
|
case 'cs':
|
2022-09-29 03:34:49 +00:00
|
|
|
case 'sk':
|
|
|
|
return $n === 1 ? 0 : ($n >= 2 && $n <= 4 ? 1 : 2);
|
2022-02-24 19:05:19 +00:00
|
|
|
case 'co':
|
2015-09-06 17:21:17 +00:00
|
|
|
case 'fr':
|
2017-01-08 06:56:56 +00:00
|
|
|
case 'oc':
|
2022-04-28 18:05:57 +00:00
|
|
|
case 'tr':
|
2016-04-26 18:21:30 +00:00
|
|
|
case 'zh':
|
2016-10-29 08:24:08 +00:00
|
|
|
return $n > 1 ? 1 : 0;
|
2021-01-07 20:16:03 +00:00
|
|
|
case 'he':
|
|
|
|
return $n === 1 ? 0 : ($n === 2 ? 1 : (($n < 0 || $n > 10) && ($n % 10 === 0) ? 2 : 3));
|
2021-03-09 04:54:06 +00:00
|
|
|
case 'id':
|
2023-08-01 12:00:45 +00:00
|
|
|
case 'ja':
|
2022-02-12 15:17:09 +00:00
|
|
|
case 'jbo':
|
2022-11-07 06:12:40 +00:00
|
|
|
case 'th':
|
2021-03-09 04:54:06 +00:00
|
|
|
return 0;
|
2021-01-07 20:16:03 +00:00
|
|
|
case 'lt':
|
|
|
|
return $n % 10 === 1 && $n % 100 !== 11 ? 0 : (($n % 10 >= 2 && $n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
|
2015-09-06 17:21:17 +00:00
|
|
|
case 'pl':
|
2022-09-29 03:34:49 +00:00
|
|
|
return $n === 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
|
2016-12-16 09:15:37 +00:00
|
|
|
case 'ru':
|
2019-10-18 09:31:40 +00:00
|
|
|
case 'uk':
|
2022-09-29 03:34:49 +00:00
|
|
|
return $n % 10 === 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
|
2017-01-01 13:35:39 +00:00
|
|
|
case 'sl':
|
2022-09-29 03:34:49 +00:00
|
|
|
return $n % 100 === 1 ? 1 : ($n % 100 === 2 ? 2 : ($n % 100 === 3 || $n % 100 === 4 ? 3 : 0));
|
2015-09-06 17:21:17 +00:00
|
|
|
default:
|
2023-06-18 10:54:22 +00:00
|
|
|
// bg, ca, de, el, en, es, et, fi, hu, it, nl, no, pt
|
2022-09-29 03:34:49 +00:00
|
|
|
return $n !== 1 ? 1 : 0;
|
2015-09-06 17:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 00:24:56 +00:00
|
|
|
/**
|
|
|
|
* compares two language preference arrays and returns the preferred match
|
|
|
|
*
|
2016-07-19 11:56:52 +00:00
|
|
|
* From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
2015-09-19 09:21:13 +00:00
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @param array $acceptedLanguages
|
|
|
|
* @param array $availableLanguages
|
2015-09-05 00:24:56 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-07-26 06:19:35 +00:00
|
|
|
protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages)
|
|
|
|
{
|
2015-09-05 00:24:56 +00:00
|
|
|
$matches = array();
|
2016-08-15 14:45:47 +00:00
|
|
|
$any = false;
|
2016-07-26 06:19:35 +00:00
|
|
|
foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$acceptedQuality = floatval($acceptedQuality);
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($acceptedQuality === 0.0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($availableLanguages as $availableValue) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$availableQuality = 1.0;
|
2016-07-26 06:19:35 +00:00
|
|
|
foreach ($acceptedValues as $acceptedValue) {
|
|
|
|
if ($acceptedValue === '*') {
|
2015-09-05 00:24:56 +00:00
|
|
|
$any = true;
|
|
|
|
}
|
|
|
|
$matchingGrade = self::_matchLanguage($acceptedValue, $availableValue);
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($matchingGrade > 0) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$q = (string) ($acceptedQuality * $availableQuality * $matchingGrade);
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!isset($matches[$q])) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$matches[$q] = array();
|
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!in_array($availableValue, $matches[$q])) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$matches[$q][] = $availableValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (count($matches) === 0 && $any) {
|
|
|
|
if (count($availableLanguages) > 0) {
|
2015-09-05 00:24:56 +00:00
|
|
|
$matches['1.0'] = $availableLanguages;
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
if (count($matches) === 0) {
|
2015-10-18 18:38:07 +00:00
|
|
|
return self::$_languageFallback;
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
krsort($matches);
|
|
|
|
$topmatches = current($matches);
|
|
|
|
return current($topmatches);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compare two language IDs and return the degree they match
|
|
|
|
*
|
2016-07-19 11:56:52 +00:00
|
|
|
* From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
|
2015-09-05 00:24:56 +00:00
|
|
|
*
|
2015-09-19 09:21:13 +00:00
|
|
|
* @access protected
|
|
|
|
* @static
|
|
|
|
* @param string $a
|
|
|
|
* @param string $b
|
2015-09-05 00:24:56 +00:00
|
|
|
* @return float
|
|
|
|
*/
|
2016-07-26 06:19:35 +00:00
|
|
|
protected static function _matchLanguage($a, $b)
|
|
|
|
{
|
2015-09-05 00:24:56 +00:00
|
|
|
$a = explode('-', $a);
|
|
|
|
$b = explode('-', $b);
|
2016-08-15 14:45:47 +00:00
|
|
|
for ($i = 0, $n = min(count($a), count($b)); $i < $n; ++$i) {
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($a[$i] !== $b[$i]) {
|
|
|
|
break;
|
|
|
|
}
|
2015-09-05 00:24:56 +00:00
|
|
|
}
|
|
|
|
return $i === 0 ? 0 : (float) $i / count($a);
|
|
|
|
}
|
|
|
|
}
|