Commaaa2
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
2
vendor/symfony/translation-contracts/LICENSE
vendored
2
vendor/symfony/translation-contracts/LICENSE
vendored
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2018-2022 Fabien Potencier
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -16,6 +16,8 @@ interface LocaleAwareInterface
|
||||
/**
|
||||
* Sets the current locale.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function setLocale(string $locale);
|
||||
|
||||
@@ -3,7 +3,7 @@ Symfony Translation Contracts
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful - and
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
|
||||
@@ -30,7 +30,7 @@ use Symfony\Contracts\Translation\TranslatorTrait;
|
||||
*/
|
||||
class TranslatorTest extends TestCase
|
||||
{
|
||||
private $defaultLocale;
|
||||
private string $defaultLocale;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@@ -114,7 +114,7 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
public function getTransTests()
|
||||
public static function getTransTests()
|
||||
{
|
||||
return [
|
||||
['Symfony is great!', 'Symfony is great!', []],
|
||||
@@ -122,7 +122,7 @@ class TranslatorTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransChoiceTests()
|
||||
public static function getTransChoiceTests()
|
||||
{
|
||||
return [
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
@@ -137,7 +137,7 @@ class TranslatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInternal
|
||||
* @dataProvider getInterval
|
||||
*/
|
||||
public function testInterval($expected, $number, $interval)
|
||||
{
|
||||
@@ -146,7 +146,7 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals($expected, $translator->trans($interval.' foo|[1,Inf[ bar', ['%count%' => $number]));
|
||||
}
|
||||
|
||||
public function getInternal()
|
||||
public static function getInterval()
|
||||
{
|
||||
return [
|
||||
['foo', 3, '{1,2, 3 ,4}'],
|
||||
@@ -183,13 +183,14 @@ class TranslatorTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number)
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$translator->trans($id, ['%count%' => $number]);
|
||||
}
|
||||
|
||||
public function getNonMatchingMessages()
|
||||
public static function getNonMatchingMessages()
|
||||
{
|
||||
return [
|
||||
['{0} There are no apples|{1} There is one apple', 2],
|
||||
@@ -199,7 +200,7 @@ class TranslatorTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function getChooseTests()
|
||||
public static function getChooseTests()
|
||||
{
|
||||
return [
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
@@ -255,13 +256,13 @@ class TranslatorTest extends TestCase
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with double-quotes and id split accros lines
|
||||
// with double-quotes and id split across lines
|
||||
['This is a text with a
|
||||
new-line in it. Selector = 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 1],
|
||||
// with single-quotes and id split accros lines
|
||||
// with single-quotes and id split across lines
|
||||
['This is a text with a
|
||||
new-line in it. Selector > 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
@@ -269,9 +270,9 @@ class TranslatorTest extends TestCase
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with single-quotes and \n in text
|
||||
['This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0],
|
||||
// with double-quotes and id split accros lines
|
||||
// with double-quotes and id split across lines
|
||||
["This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1],
|
||||
// esacape pipe
|
||||
// escape pipe
|
||||
['This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0],
|
||||
// Empty plural set (2 plural forms) from a .PO file
|
||||
['', '|', 1],
|
||||
@@ -315,7 +316,7 @@ class TranslatorTest extends TestCase
|
||||
*
|
||||
* As it is impossible to have this ever complete we should try as hard as possible to have it almost complete.
|
||||
*/
|
||||
public function successLangcodes(): array
|
||||
public static function successLangcodes(): array
|
||||
{
|
||||
return [
|
||||
['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']],
|
||||
@@ -334,7 +335,7 @@ class TranslatorTest extends TestCase
|
||||
*
|
||||
* @return array with nplural together with langcodes
|
||||
*/
|
||||
public function failingLangcodes(): array
|
||||
public static function failingLangcodes(): array
|
||||
{
|
||||
return [
|
||||
['1', ['fa']],
|
||||
|
||||
@@ -16,5 +16,5 @@ namespace Symfony\Contracts\Translation;
|
||||
*/
|
||||
interface TranslatableInterface
|
||||
{
|
||||
public function trans(TranslatorInterface $translator, string $locale = null): string;
|
||||
public function trans(TranslatorInterface $translator, ?string $locale = null): string;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ interface TranslatorInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string;
|
||||
public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string;
|
||||
|
||||
/**
|
||||
* Returns the default locale.
|
||||
|
||||
@@ -23,25 +23,19 @@ trait TranslatorTrait
|
||||
private ?string $locale = null;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
public function setLocale(string $locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLocale(): string
|
||||
{
|
||||
return $this->locale ?: (class_exists(\Locale::class) ? \Locale::getDefault() : 'en');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string
|
||||
public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
|
||||
{
|
||||
if (null === $id || '' === $id) {
|
||||
return '';
|
||||
@@ -140,121 +134,92 @@ EOF;
|
||||
{
|
||||
$number = abs($number);
|
||||
|
||||
switch ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) {
|
||||
case 'af':
|
||||
case 'bn':
|
||||
case 'bg':
|
||||
case 'ca':
|
||||
case 'da':
|
||||
case 'de':
|
||||
case 'el':
|
||||
case 'en':
|
||||
case 'en_US_POSIX':
|
||||
case 'eo':
|
||||
case 'es':
|
||||
case 'et':
|
||||
case 'eu':
|
||||
case 'fa':
|
||||
case 'fi':
|
||||
case 'fo':
|
||||
case 'fur':
|
||||
case 'fy':
|
||||
case 'gl':
|
||||
case 'gu':
|
||||
case 'ha':
|
||||
case 'he':
|
||||
case 'hu':
|
||||
case 'is':
|
||||
case 'it':
|
||||
case 'ku':
|
||||
case 'lb':
|
||||
case 'ml':
|
||||
case 'mn':
|
||||
case 'mr':
|
||||
case 'nah':
|
||||
case 'nb':
|
||||
case 'ne':
|
||||
case 'nl':
|
||||
case 'nn':
|
||||
case 'no':
|
||||
case 'oc':
|
||||
case 'om':
|
||||
case 'or':
|
||||
case 'pa':
|
||||
case 'pap':
|
||||
case 'ps':
|
||||
case 'pt':
|
||||
case 'so':
|
||||
case 'sq':
|
||||
case 'sv':
|
||||
case 'sw':
|
||||
case 'ta':
|
||||
case 'te':
|
||||
case 'tk':
|
||||
case 'ur':
|
||||
case 'zu':
|
||||
return (1 == $number) ? 0 : 1;
|
||||
|
||||
case 'am':
|
||||
case 'bh':
|
||||
case 'fil':
|
||||
case 'fr':
|
||||
case 'gun':
|
||||
case 'hi':
|
||||
case 'hy':
|
||||
case 'ln':
|
||||
case 'mg':
|
||||
case 'nso':
|
||||
case 'pt_BR':
|
||||
case 'ti':
|
||||
case 'wa':
|
||||
return ($number < 2) ? 0 : 1;
|
||||
|
||||
case 'be':
|
||||
case 'bs':
|
||||
case 'hr':
|
||||
case 'ru':
|
||||
case 'sh':
|
||||
case 'sr':
|
||||
case 'uk':
|
||||
return ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
|
||||
|
||||
case 'cs':
|
||||
case 'sk':
|
||||
return (1 == $number) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
|
||||
|
||||
case 'ga':
|
||||
return (1 == $number) ? 0 : ((2 == $number) ? 1 : 2);
|
||||
|
||||
case 'lt':
|
||||
return ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
|
||||
|
||||
case 'sl':
|
||||
return (1 == $number % 100) ? 0 : ((2 == $number % 100) ? 1 : (((3 == $number % 100) || (4 == $number % 100)) ? 2 : 3));
|
||||
|
||||
case 'mk':
|
||||
return (1 == $number % 10) ? 0 : 1;
|
||||
|
||||
case 'mt':
|
||||
return (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3));
|
||||
|
||||
case 'lv':
|
||||
return (0 == $number) ? 0 : (((1 == $number % 10) && (11 != $number % 100)) ? 1 : 2);
|
||||
|
||||
case 'pl':
|
||||
return (1 == $number) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2);
|
||||
|
||||
case 'cy':
|
||||
return (1 == $number) ? 0 : ((2 == $number) ? 1 : (((8 == $number) || (11 == $number)) ? 2 : 3));
|
||||
|
||||
case 'ro':
|
||||
return (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
|
||||
|
||||
case 'ar':
|
||||
return (0 == $number) ? 0 : ((1 == $number) ? 1 : ((2 == $number) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5))));
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return match ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) {
|
||||
'af',
|
||||
'bn',
|
||||
'bg',
|
||||
'ca',
|
||||
'da',
|
||||
'de',
|
||||
'el',
|
||||
'en',
|
||||
'en_US_POSIX',
|
||||
'eo',
|
||||
'es',
|
||||
'et',
|
||||
'eu',
|
||||
'fa',
|
||||
'fi',
|
||||
'fo',
|
||||
'fur',
|
||||
'fy',
|
||||
'gl',
|
||||
'gu',
|
||||
'ha',
|
||||
'he',
|
||||
'hu',
|
||||
'is',
|
||||
'it',
|
||||
'ku',
|
||||
'lb',
|
||||
'ml',
|
||||
'mn',
|
||||
'mr',
|
||||
'nah',
|
||||
'nb',
|
||||
'ne',
|
||||
'nl',
|
||||
'nn',
|
||||
'no',
|
||||
'oc',
|
||||
'om',
|
||||
'or',
|
||||
'pa',
|
||||
'pap',
|
||||
'ps',
|
||||
'pt',
|
||||
'so',
|
||||
'sq',
|
||||
'sv',
|
||||
'sw',
|
||||
'ta',
|
||||
'te',
|
||||
'tk',
|
||||
'ur',
|
||||
'zu' => (1 == $number) ? 0 : 1,
|
||||
'am',
|
||||
'bh',
|
||||
'fil',
|
||||
'fr',
|
||||
'gun',
|
||||
'hi',
|
||||
'hy',
|
||||
'ln',
|
||||
'mg',
|
||||
'nso',
|
||||
'pt_BR',
|
||||
'ti',
|
||||
'wa' => ($number < 2) ? 0 : 1,
|
||||
'be',
|
||||
'bs',
|
||||
'hr',
|
||||
'ru',
|
||||
'sh',
|
||||
'sr',
|
||||
'uk' => ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2),
|
||||
'cs',
|
||||
'sk' => (1 == $number) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2),
|
||||
'ga' => (1 == $number) ? 0 : ((2 == $number) ? 1 : 2),
|
||||
'lt' => ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2),
|
||||
'sl' => (1 == $number % 100) ? 0 : ((2 == $number % 100) ? 1 : (((3 == $number % 100) || (4 == $number % 100)) ? 2 : 3)),
|
||||
'mk' => (1 == $number % 10) ? 0 : 1,
|
||||
'mt' => (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)),
|
||||
'lv' => (0 == $number) ? 0 : (((1 == $number % 10) && (11 != $number % 100)) ? 1 : 2),
|
||||
'pl' => (1 == $number) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2),
|
||||
'cy' => (1 == $number) ? 0 : ((2 == $number) ? 1 : (((8 == $number) || (11 == $number)) ? 2 : 3)),
|
||||
'ro' => (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2),
|
||||
'ar' => (0 == $number) ? 0 : ((1 == $number) ? 1 : ((2 == $number) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))),
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.0.2"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/translation-implementation": ""
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\Translation\\": "" }
|
||||
"psr-4": { "Symfony\\Contracts\\Translation\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.0-dev"
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
|
||||
Reference in New Issue
Block a user