@@ -3,10 +3,10 @@ |
||
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
| 6 | -use Nette\Http\Session, |
|
| 7 | - Nette\Http\SessionSection, |
|
| 8 | - Nette\Http\RequestFactory, |
|
| 9 | - Nette\Http\Response; |
|
| 6 | +use Nette\Http\Session; |
|
| 7 | +use Nette\Http\SessionSection; |
|
| 8 | +use Nette\Http\RequestFactory; |
|
| 9 | +use Nette\Http\Response; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * SessionLocaleResolver |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | protected $varName = "lang"; |
| 27 | 27 | |
| 28 | 28 | function __construct(Session $session = NULL) { |
| 29 | - if(is_null($session)) { |
|
| 29 | + if (is_null($session)) { |
|
| 30 | 30 | $request = (new RequestFactory)->createHttpRequest(); |
| 31 | 31 | $response = new Response; |
| 32 | 32 | $session = new Session($request, $response); |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | $this->section = $session->getSection(get_class($this)); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - function getLang(): ?string { |
|
| 39 | - if(empty($this->section->{$this->varName})) { |
|
| 38 | + function getLang(): ? string { |
|
| 39 | + if (empty($this->section->{$this->varName})) { |
|
| 40 | 40 | return NULL; |
| 41 | 41 | } |
| 42 | 42 | return $this->section->{$this->varName}; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * Resolve language |
| 59 | 59 | */ |
| 60 | - function resolve(): ?string { |
|
| 60 | + function resolve(): ? string { |
|
| 61 | 61 | return $this->getLang(); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
| 6 | -use Nette\Utils\Arrays, |
|
| 7 | - Nette\Utils\Strings, |
|
| 8 | - Nette\Localization\ITranslator, |
|
| 9 | - Nexendrie\Translation\Loaders\ILoader, |
|
| 10 | - Nexendrie\Utils\Intervals; |
|
| 6 | +use Nette\Utils\Arrays; |
|
| 7 | +use Nette\Utils\Strings; |
|
| 8 | +use Nette\Localization\ITranslator; |
|
| 9 | +use Nexendrie\Translation\Loaders\ILoader; |
|
| 10 | +use Nexendrie\Utils\Intervals; |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Translator |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return string[] |
| 52 | 52 | */ |
| 53 | 53 | protected function extractDomainAndMessage(string $message): array { |
| 54 | - if(!Strings::contains($message, ".")) { |
|
| 54 | + if (!Strings::contains($message, ".")) { |
|
| 55 | 55 | return ["messages", $message]; |
| 56 | 56 | } |
| 57 | 57 | return explode(".", $message, 2); |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | protected function multiLevelTrans(array $message, array $texts): string { |
| 64 | 64 | $text = $texts; |
| 65 | - foreach($message as $part) { |
|
| 65 | + foreach ($message as $part) { |
|
| 66 | 66 | $text = Arrays::get($text, $part, ""); |
| 67 | - if($text === "") { |
|
| 67 | + if ($text === "") { |
|
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | protected function multiChoiceTrans(string $message, int $count): string { |
| 78 | 78 | $variants = explode("|", $message); |
| 79 | - foreach($variants as $variant) { |
|
| 79 | + foreach ($variants as $variant) { |
|
| 80 | 80 | $interval = Intervals::findInterval($variant); |
| 81 | - if(is_string($interval) AND Intervals::isInInterval($count, $interval)) { |
|
| 81 | + if (is_string($interval) AND Intervals::isInInterval($count, $interval)) { |
|
| 82 | 82 | return Strings::trim(Strings::after($variant, $interval)); |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -101,19 +101,19 @@ discard block |
||
| 101 | 101 | list($domain, $m) = $this->extractDomainAndMessage($message); |
| 102 | 102 | $texts = Arrays::get($this->loader->getTexts(), $domain, []); |
| 103 | 103 | $parts = explode(".", $m); |
| 104 | - if(count($parts) === 1) { |
|
| 104 | + if (count($parts) === 1) { |
|
| 105 | 105 | $parts = [$m]; |
| 106 | 106 | } |
| 107 | 107 | $text = $this->multiLevelTrans($parts, $texts); |
| 108 | - if($text === "") { |
|
| 108 | + if ($text === "") { |
|
| 109 | 109 | $this->onUntranslated($message); |
| 110 | 110 | return $message; |
| 111 | 111 | } |
| 112 | - if(is_string(Intervals::findInterval($text))) { |
|
| 112 | + if (is_string(Intervals::findInterval($text))) { |
|
| 113 | 113 | $text = $this->multiChoiceTrans($text, $count); |
| 114 | 114 | } |
| 115 | 115 | $params["count"] = $count; |
| 116 | - foreach($params as $key => $value) { |
|
| 116 | + foreach ($params as $key => $value) { |
|
| 117 | 117 | $text = str_replace("%$key%", $value, $text); |
| 118 | 118 | } |
| 119 | 119 | return $text; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** @var string|NULL */ |
| 17 | 17 | protected $lang = NULL; |
| 18 | 18 | |
| 19 | - function getLang(): ?string { |
|
| 19 | + function getLang(): ? string { |
|
| 20 | 20 | return $this->lang; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $this->lang = $lang; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - function resolve(): ?string { |
|
| 27 | + function resolve(): ? string { |
|
| 28 | 28 | return $this->getLang(); |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -21,10 +21,10 @@ discard block |
||
| 21 | 21 | $this[] = $resolver; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - function resolve(): ?string { |
|
| 25 | - foreach($this as $resolver) { |
|
| 24 | + function resolve(): ? string { |
|
| 25 | + foreach ($this as $resolver) { |
|
| 26 | 26 | $lang = $resolver->resolve(); |
| 27 | - if(!is_null($lang)) { |
|
| 27 | + if (!is_null($lang)) { |
|
| 28 | 28 | return $lang; |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | /** @var string */ |
| 18 | 18 | protected $varName = "TRANSLATOR_LANGUAGE"; |
| 19 | 19 | |
| 20 | - function getLang(): ?string { |
|
| 20 | + function getLang(): ? string { |
|
| 21 | 21 | $lang = getenv($this->varName); |
| 22 | - if($lang) { |
|
| 22 | + if ($lang) { |
|
| 23 | 23 | return $lang; |
| 24 | 24 | } |
| 25 | 25 | return NULL; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $this->varName = $varName; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - function resolve(): ?string { |
|
| 40 | + function resolve(): ? string { |
|
| 41 | 41 | return $this->getLang(); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return NULL |
| 20 | 20 | */ |
| 21 | - function resolve(): ?string { |
|
| 21 | + function resolve(): ? string { |
|
| 22 | 22 | return NULL; |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation\Resolvers; |
| 5 | 5 | |
@@ -12,6 +12,6 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * Resolve language |
| 14 | 14 | */ |
| 15 | - function resolve(): ?string; |
|
| 15 | + function resolve(): ? string; |
|
| 16 | 16 | } |
| 17 | 17 | ?> |
| 18 | 18 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Nexendrie\Translation; |
| 5 | 5 | |