@@ -8,8 +8,7 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jakub Konečný |
| 10 | 10 | */ |
| 11 | -interface FileLoader extends Loader |
|
| 12 | -{ |
|
| 11 | +interface FileLoader extends Loader { |
|
| 13 | 12 | /** |
| 14 | 13 | * @return string[] |
| 15 | 14 | */ |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
| 6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
| 6 | +if(false) { // @phpstan-ignore if.alwaysFalse |
|
| 7 | 7 | /** @deprecated Use Loader */ |
| 8 | 8 | interface ILoader extends Loader |
| 9 | 9 | { |
| 10 | 10 | } |
| 11 | -} elseif (!interface_exists(ILoader::class)) { |
|
| 11 | +} elseif(!interface_exists(ILoader::class)) { |
|
| 12 | 12 | class_alias(Loader::class, ILoader::class); |
| 13 | 13 | } |
@@ -3,10 +3,10 @@ |
||
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
| 6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
| 6 | +if (false) { |
|
| 7 | +// @phpstan-ignore if.alwaysFalse |
|
| 7 | 8 | /** @deprecated Use Loader */ |
| 8 | - interface ILoader extends Loader |
|
| 9 | - { |
|
| 9 | + interface ILoader extends Loader { |
|
| 10 | 10 | } |
| 11 | 11 | } elseif (!interface_exists(ILoader::class)) { |
| 12 | 12 | class_alias(Loader::class, ILoader::class); |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jakub Konečný |
| 10 | 10 | */ |
| 11 | -interface IMessageSelector |
|
| 12 | -{ |
|
| 11 | +interface IMessageSelector { |
|
| 13 | 12 | /** |
| 14 | 13 | * Does the message contain multiple variants? |
| 15 | 14 | */ |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | private function extractDomainAndMessage(string $message): array |
| 63 | 63 | { |
| 64 | - if (!str_contains($message, ".")) { |
|
| 64 | + if(!str_contains($message, ".")) { |
|
| 65 | 65 | return [self::DEFAULT_DOMAIN, $message]; |
| 66 | 66 | } |
| 67 | 67 | return explode(".", $message, 2); |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | private function multiLevelTrans(array $message, array $texts): string |
| 74 | 74 | { |
| 75 | 75 | $text = $texts; |
| 76 | - foreach ($message as $part) { |
|
| 76 | + foreach($message as $part) { |
|
| 77 | 77 | $text = Arrays::get($text, $part, ""); |
| 78 | - if ($text === "") { |
|
| 78 | + if($text === "") { |
|
| 79 | 79 | break; |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | public function translate($message, ...$parameters): string |
| 99 | 99 | { |
| 100 | 100 | $message = (string) $message; |
| 101 | - if (count($parameters) === 1 && is_array($parameters[0])) { |
|
| 101 | + if(count($parameters) === 1 && is_array($parameters[0])) { |
|
| 102 | 102 | $count = $parameters[0]["count"] ?? 0; |
| 103 | 103 | $params = $parameters[0]; |
| 104 | 104 | } else { |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | [$domain, $m] = $this->extractDomainAndMessage($message); |
| 109 | 109 | $texts = Arrays::get($this->loader->getTexts(), $domain, []); |
| 110 | 110 | $parts = explode(".", $m); |
| 111 | - if (count($parts) === 1) { |
|
| 111 | + if(count($parts) === 1) { |
|
| 112 | 112 | $parts = [$m]; |
| 113 | 113 | } |
| 114 | 114 | $text = $this->multiLevelTrans($parts, $texts); |
| 115 | - if ($text === "") { |
|
| 115 | + if($text === "") { |
|
| 116 | 116 | $this->onUntranslated($message); |
| 117 | 117 | return $message; |
| 118 | 118 | } |
| 119 | - if ($this->messageSelector->isMultiChoice($text)) { |
|
| 119 | + if($this->messageSelector->isMultiChoice($text)) { |
|
| 120 | 120 | $text = $this->messageSelector->choose($text, $count); |
| 121 | 121 | } |
| 122 | - foreach ($params as $key => $value) { |
|
| 122 | + foreach($params as $key => $value) { |
|
| 123 | 123 | $text = str_replace("%$key%", (string) $value, $text); |
| 124 | 124 | } |
| 125 | 125 | return $text; |
@@ -8,7 +8,6 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jakub Konečný |
| 10 | 10 | */ |
| 11 | -interface SettableLocaleResolver extends LocaleResolver |
|
| 12 | -{ |
|
| 11 | +interface SettableLocaleResolver extends LocaleResolver { |
|
| 13 | 12 | public function setLang(string $lang): void; |
| 14 | 13 | } |
@@ -3,6 +3,5 @@ |
||
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
| 6 | -class LoaderNotSetException extends InvalidStateException |
|
| 7 | -{ |
|
| 6 | +class LoaderNotSetException extends InvalidStateException { |
|
| 8 | 7 | } |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jakub Konečný |
| 10 | 10 | */ |
| 11 | -interface LocaleResolver |
|
| 12 | -{ |
|
| 11 | +interface LocaleResolver { |
|
| 13 | 12 | /** |
| 14 | 13 | * Resolve language |
| 15 | 14 | */ |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | declare(strict_types=1); |
| 3 | 3 | |
| 4 | 4 | require __DIR__ . "/../vendor/autoload.php"; |
| 5 | -Testbench\Bootstrap::setup(__DIR__ . '/_temp', function (\Nette\Bootstrap\Configurator $configurator): void { |
|
| 5 | +Testbench\Bootstrap::setup(__DIR__ . '/_temp', function(\Nette\Bootstrap\Configurator $configurator): void { |
|
| 6 | 6 | $configurator->addStaticParameters([ |
| 7 | 7 | "appDir" => __DIR__, |
| 8 | 8 | "tempDir" => __DIR__ . "/_temp", |
@@ -11,10 +11,8 @@ |
||
| 11 | 11 | * @author Jakub Konečný |
| 12 | 12 | * @testCase |
| 13 | 13 | */ |
| 14 | -final class JsonLoaderTest extends FileLoaderTestAbstract |
|
| 15 | -{ |
|
| 16 | - protected function setUp() |
|
| 17 | - { |
|
| 14 | +final class JsonLoaderTest extends FileLoaderTestAbstract { |
|
| 15 | + protected function setUp() { |
|
| 18 | 16 | $folders = [__DIR__ . "/../../../lang", __DIR__ . "/../../../lang2"]; |
| 19 | 17 | $this->loader = new JsonLoader(new ManualLocaleResolver(), $folders); |
| 20 | 18 | } |