@@ -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 | } |
@@ -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; |
@@ -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", |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function testSetFolders(): void |
| 44 | 44 | { |
| 45 | - Assert::exception(function (): void { |
|
| 45 | + Assert::exception(function(): void { |
|
| 46 | 46 | $this->loader->folders = [""]; |
| 47 | 47 | }, InvalidFolderException::class, "Folder does not exist."); |
| 48 | 48 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | Assert::count(2, $resources["book"]); |
| 72 | 72 | Assert::count(2, $resources["abc"]); |
| 73 | 73 | // the language does not exist, 1 (default) resource for each domain |
| 74 | - if ($this->loader instanceof MessagesCatalogue) { |
|
| 74 | + if($this->loader instanceof MessagesCatalogue) { |
|
| 75 | 75 | return; // the following tests for some reason fail with MessagesCatalogue |
| 76 | 76 | } |
| 77 | 77 | $this->loader->lang = "xyz"; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | Assert::count(3, $texts["messages"]); |
| 102 | 102 | Assert::type("array", $texts["book"]); |
| 103 | 103 | Assert::count(5, $texts["book"]); |
| 104 | - if ($this->loader instanceof MessagesCatalogue) { |
|
| 104 | + if($this->loader instanceof MessagesCatalogue) { |
|
| 105 | 105 | return; // the following tests for some reason fail with MessagesCatalogue |
| 106 | 106 | } |
| 107 | 107 | $this->loader->lang = "xyz"; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | public function testNoFolder(): void |
| 118 | 118 | { |
| 119 | - Assert::exception(function (): void { |
|
| 119 | + Assert::exception(function(): void { |
|
| 120 | 120 | $class = get_class($this->loader); |
| 121 | 121 | $this->loader = new $class(); |
| 122 | 122 | $this->loader->getTexts(); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | Assert::count(2, $result); |
| 131 | 131 | Assert::contains("en", $result); |
| 132 | 132 | Assert::contains("cs", $result); |
| 133 | - Assert::exception(function (): void { |
|
| 133 | + Assert::exception(function(): void { |
|
| 134 | 134 | $class = get_class($this->loader); |
| 135 | 135 | $this->loader = new $class(); |
| 136 | 136 | $this->loader->getAvailableLanguages(); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ] |
| 115 | 115 | ] |
| 116 | 116 | ]; |
| 117 | - Assert::exception(function () use ($config) { |
|
| 117 | + Assert::exception(function() use ($config) { |
|
| 118 | 118 | $this->refreshContainer($config); |
| 119 | 119 | }, InvalidLoaderException::class); |
| 120 | 120 | $config = [ |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | ] |
| 125 | 125 | ] |
| 126 | 126 | ]; |
| 127 | - Assert::exception(function () use ($config) { |
|
| 127 | + Assert::exception(function() use ($config) { |
|
| 128 | 128 | $this->refreshContainer($config); |
| 129 | 129 | }, InvalidLoaderException::class); |
| 130 | 130 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | "localeResolver" => "invalid" |
| 176 | 176 | ] |
| 177 | 177 | ]; |
| 178 | - Assert::exception(function () use ($config) { |
|
| 178 | + Assert::exception(function() use ($config) { |
|
| 179 | 179 | $this->refreshContainer($config); |
| 180 | 180 | }, InvalidLocaleResolverException::class); |
| 181 | 181 | $config = [ |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | "localeResolver" => \stdClass::class |
| 184 | 184 | ] |
| 185 | 185 | ]; |
| 186 | - Assert::exception(function () use ($config) { |
|
| 186 | + Assert::exception(function() use ($config) { |
|
| 187 | 187 | $this->refreshContainer($config); |
| 188 | 188 | }, InvalidLocaleResolverException::class); |
| 189 | 189 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | ] |
| 251 | 251 | ] |
| 252 | 252 | ]; |
| 253 | - Assert::exception(function () use ($config) { |
|
| 253 | + Assert::exception(function() use ($config) { |
|
| 254 | 254 | $this->refreshContainer($config); |
| 255 | 255 | }, InvalidFolderException::class); |
| 256 | 256 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | "messageSelector" => \stdClass::class |
| 283 | 283 | ] |
| 284 | 284 | ]; |
| 285 | - Assert::exception(function () use ($config) { |
|
| 285 | + Assert::exception(function() use ($config) { |
|
| 286 | 286 | $this->refreshContainer($config); |
| 287 | 287 | }, InvalidMessageSelectorException::class); |
| 288 | 288 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | "debugger" => false |
| 299 | 299 | ] |
| 300 | 300 | ]; |
| 301 | - Assert::exception(function () use ($config) { |
|
| 301 | + Assert::exception(function() use ($config) { |
|
| 302 | 302 | $this->refreshContainer($config); |
| 303 | 303 | $panel = $this->getService(TranslationPanel::class); |
| 304 | 304 | Assert::type(TranslationPanel::class, $panel); |
@@ -41,24 +41,24 @@ |
||
| 41 | 41 | $text = (string) $r->p; |
| 42 | 42 | Assert::same("Untranslated messages: 0, loaded resources 0", $text); |
| 43 | 43 | Assert::same("Resolved language", (string) $r->div->div->h1); |
| 44 | - foreach ($r->div->div->table->tr->children() as $i => $td) { |
|
| 45 | - if ($i === 0) { |
|
| 44 | + foreach($r->div->div->table->tr->children() as $i => $td) { |
|
| 45 | + if($i === 0) { |
|
| 46 | 46 | Assert::same("ManualLocaleResolver", (string) $td); |
| 47 | - } elseif ($i === 1) { |
|
| 47 | + } elseif($i === 1) { |
|
| 48 | 48 | Assert::same("en", (string) $td); |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | - foreach ($r->children() as $i1 => $div) { |
|
| 52 | - if ($i1 === 1) { |
|
| 51 | + foreach($r->children() as $i1 => $div) { |
|
| 52 | + if($i1 === 1) { |
|
| 53 | 53 | Assert::same("Loaded resources", (string) $div->h1); |
| 54 | - foreach ($div->table->th as $i2 => $td) { |
|
| 55 | - if ($i2 === 0) { |
|
| 54 | + foreach($div->table->th as $i2 => $td) { |
|
| 55 | + if($i2 === 0) { |
|
| 56 | 56 | Assert::same("Domain", (string) $td); |
| 57 | - } elseif ($i2 === 1) { |
|
| 57 | + } elseif($i2 === 1) { |
|
| 58 | 58 | Assert::same("Filename", (string) $td); |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | - } elseif ($i1 === 2) { |
|
| 61 | + } elseif($i1 === 2) { |
|
| 62 | 62 | Assert::count(0, $div->children()); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function testResolve(): void |
| 34 | 34 | { |
| 35 | 35 | $parameters = [ |
| 36 | - "callback" => function () { |
|
| 36 | + "callback" => function() { |
|
| 37 | 37 | return ""; |
| 38 | 38 | } |
| 39 | 39 | ]; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $this->resolver->param = "language"; |
| 56 | 56 | $parameters = [ |
| 57 | - "callback" => function () { |
|
| 57 | + "callback" => function() { |
|
| 58 | 58 | return ""; |
| 59 | 59 | }, "language" => "en", |
| 60 | 60 | ]; |
@@ -20,13 +20,13 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function choose(string $message, int $count): string |
| 22 | 22 | { |
| 23 | - if (!$this->isMultiChoice($message)) { |
|
| 23 | + if(!$this->isMultiChoice($message)) { |
|
| 24 | 24 | return $message; |
| 25 | 25 | } |
| 26 | 26 | $variants = explode("|", $message); |
| 27 | - foreach ($variants as $variant) { |
|
| 27 | + foreach($variants as $variant) { |
|
| 28 | 28 | $interval = Intervals::findInterval($variant); |
| 29 | - if (is_string($interval) && Intervals::isInInterval($count, $interval)) { |
|
| 29 | + if(is_string($interval) && Intervals::isInInterval($count, $interval)) { |
|
| 30 | 30 | return Strings::trim((string) Strings::after($variant, $interval)); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | public function testResolve(): void |
| 31 | 31 | { |
| 32 | 32 | $resolver = new HeaderLocaleResolver(); |
| 33 | - Assert::exception(function () use ($resolver) { |
|
| 33 | + Assert::exception(function() use ($resolver) { |
|
| 34 | 34 | $resolver->resolve(); |
| 35 | 35 | }, LoaderNotSetException::class); |
| 36 | 36 | /** @var Loader $loader */ |