@@ -24,7 +24,7 @@ |
||
| 24 | 24 | return match (true) { |
| 25 | 25 | $string === $pattern => true, |
| 26 | 26 | !$this->isPattern($pattern) => false, |
| 27 | - default => (bool) \preg_match($this->getRegex($pattern), $string) |
|
| 27 | + default => (bool)\preg_match($this->getRegex($pattern), $string) |
|
| 28 | 28 | }; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | protected string $locale, |
| 14 | 14 | int $code = 0, |
| 15 | 15 | \Throwable $previous = null |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | parent::__construct(\sprintf('Undefined locale \'%s\'', $locale), $code, $previous); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | protected function say(string $string, array $options = [], string $bundle = null): string |
| 35 | 35 | { |
| 36 | - if (Translator::isMessage($string)) { |
|
| 36 | + if (Translator::isMessage($string)){ |
|
| 37 | 37 | //Cut [[ and ]] |
| 38 | 38 | $string = \substr($string, 2, -2); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $container = ContainerScope::getContainer(); |
| 42 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 42 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
| 43 | 43 | return Translator::interpolate($string, $options); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | $translator = $container->get(TranslatorInterface::class); |
| 50 | 50 | |
| 51 | - if (\is_null($bundle)) { |
|
| 51 | + if (\is_null($bundle)){ |
|
| 52 | 52 | $bundle = $translator->getDomain(static::class); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -33,13 +33,15 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | protected function say(string $string, array $options = [], string $bundle = null): string |
| 35 | 35 | { |
| 36 | - if (Translator::isMessage($string)) { |
|
| 36 | + if (Translator::isMessage($string)) |
|
| 37 | + { |
|
| 37 | 38 | //Cut [[ and ]] |
| 38 | 39 | $string = \substr($string, 2, -2); |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | $container = ContainerScope::getContainer(); |
| 42 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 43 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
| 44 | + { |
|
| 43 | 45 | return Translator::interpolate($string, $options); |
| 44 | 46 | } |
| 45 | 47 | |
@@ -48,7 +50,8 @@ discard block |
||
| 48 | 50 | */ |
| 49 | 51 | $translator = $container->get(TranslatorInterface::class); |
| 50 | 52 | |
| 51 | - if (\is_null($bundle)) { |
|
| 53 | + if (\is_null($bundle)) |
|
| 54 | + { |
|
| 52 | 55 | $bundle = $translator->getDomain(static::class); |
| 53 | 56 | } |
| 54 | 57 | |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly string $locale, |
| 11 | - ) { |
|
| 11 | + ){ |
|
| 12 | 12 | } |
| 13 | 13 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
| 8 | 8 | use Spiral\Translator\TranslatorInterface; |
| 9 | 9 | |
| 10 | -if (!\function_exists('l')) { |
|
| 10 | +if (!\function_exists('l')){ |
|
| 11 | 11 | /** |
| 12 | 12 | * Translate message using default or specific bundle name. |
| 13 | 13 | * |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | /** @psalm-suppress InternalMethod */ |
| 24 | 24 | $container = ContainerScope::getContainer(); |
| 25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
| 25 | + if ($container === null || !$container->has(TranslatorInterface::class)){ |
|
| 26 | 26 | throw new ScopeException( |
| 27 | 27 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 28 | 28 | ); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -if (!\function_exists('p')) { |
|
| 38 | +if (!\function_exists('p')){ |
|
| 39 | 39 | /** |
| 40 | 40 | * Pluralize string using language pluralization options and specified numeric value. |
| 41 | 41 | * |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | /** @psalm-suppress InternalMethod */ |
| 53 | 53 | $container = ContainerScope::getContainer(); |
| 54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 54 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
| 55 | 55 | throw new ScopeException( |
| 56 | 56 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 57 | 57 | ); |
@@ -7,7 +7,8 @@ discard block |
||
| 7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
| 8 | 8 | use Spiral\Translator\TranslatorInterface; |
| 9 | 9 | |
| 10 | -if (!\function_exists('l')) { |
|
| 10 | +if (!\function_exists('l')) |
|
| 11 | +{ |
|
| 11 | 12 | /** |
| 12 | 13 | * Translate message using default or specific bundle name. |
| 13 | 14 | * |
@@ -22,7 +23,8 @@ discard block |
||
| 22 | 23 | { |
| 23 | 24 | /** @psalm-suppress InternalMethod */ |
| 24 | 25 | $container = ContainerScope::getContainer(); |
| 25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
| 26 | + if ($container === null || !$container->has(TranslatorInterface::class)) |
|
| 27 | + { |
|
| 26 | 28 | throw new ScopeException( |
| 27 | 29 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 28 | 30 | ); |
@@ -35,7 +37,8 @@ discard block |
||
| 35 | 37 | } |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | -if (!\function_exists('p')) { |
|
| 40 | +if (!\function_exists('p')) |
|
| 41 | +{ |
|
| 39 | 42 | /** |
| 40 | 43 | * Pluralize string using language pluralization options and specified numeric value. |
| 41 | 44 | * |
@@ -51,7 +54,8 @@ discard block |
||
| 51 | 54 | { |
| 52 | 55 | /** @psalm-suppress InternalMethod */ |
| 53 | 56 | $container = ContainerScope::getContainer(); |
| 54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 57 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
| 58 | + { |
|
| 55 | 59 | throw new ScopeException( |
| 56 | 60 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 57 | 61 | ); |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | |
| 32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
| 33 | 33 | { |
| 34 | - if (!$this->hasLocale($locale)) { |
|
| 34 | + if (!$this->hasLocale($locale)){ |
|
| 35 | 35 | throw new LocaleException($locale); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | |
| 32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
| 33 | 33 | { |
| 34 | - if (!$this->hasLocale($locale)) { |
|
| 34 | + if (!$this->hasLocale($locale)) |
|
| 35 | + { |
|
| 35 | 36 | throw new LocaleException($locale); |
| 36 | 37 | } |
| 37 | 38 | |
@@ -24,18 +24,18 @@ discard block |
||
| 24 | 24 | public function __construct( |
| 25 | 25 | private readonly LoaderInterface $loader, |
| 26 | 26 | CacheInterface $cache = null |
| 27 | - ) { |
|
| 27 | + ){ |
|
| 28 | 28 | $this->cache = $cache ?? new NullCache(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function getLocales(): array |
| 32 | 32 | { |
| 33 | - if ($this->locales !== []) { |
|
| 33 | + if ($this->locales !== []){ |
|
| 34 | 34 | return $this->locales; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $this->locales = (array)$this->cache->getLocales(); |
| 38 | - if ($this->locales === []) { |
|
| 38 | + if ($this->locales === []){ |
|
| 39 | 39 | $this->locales = $this->loader->getLocales(); |
| 40 | 40 | $this->cache->setLocales($this->locales); |
| 41 | 41 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function load(string $locale): CatalogueInterface |
| 47 | 47 | { |
| 48 | - if (isset($this->catalogues[$locale])) { |
|
| 48 | + if (isset($this->catalogues[$locale])){ |
|
| 49 | 49 | return $this->catalogues[$locale]; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $data = (array)$this->cache->loadLocale($locale); |
| 53 | - if (!empty($data)) { |
|
| 53 | + if (!empty($data)){ |
|
| 54 | 54 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
| 55 | - } else { |
|
| 55 | + }else{ |
|
| 56 | 56 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public function reset(): void |
| 81 | 81 | { |
| 82 | 82 | $this->cache->setLocales(null); |
| 83 | - foreach ($this->getLocales() as $locale) { |
|
| 83 | + foreach ($this->getLocales() as $locale){ |
|
| 84 | 84 | $this->cache->saveLocale($locale, null); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -30,12 +30,14 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function getLocales(): array |
| 32 | 32 | { |
| 33 | - if ($this->locales !== []) { |
|
| 33 | + if ($this->locales !== []) |
|
| 34 | + { |
|
| 34 | 35 | return $this->locales; |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | $this->locales = (array)$this->cache->getLocales(); |
| 38 | - if ($this->locales === []) { |
|
| 39 | + if ($this->locales === []) |
|
| 40 | + { |
|
| 39 | 41 | $this->locales = $this->loader->getLocales(); |
| 40 | 42 | $this->cache->setLocales($this->locales); |
| 41 | 43 | } |
@@ -45,14 +47,18 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | public function load(string $locale): CatalogueInterface |
| 47 | 49 | { |
| 48 | - if (isset($this->catalogues[$locale])) { |
|
| 50 | + if (isset($this->catalogues[$locale])) |
|
| 51 | + { |
|
| 49 | 52 | return $this->catalogues[$locale]; |
| 50 | 53 | } |
| 51 | 54 | |
| 52 | 55 | $data = (array)$this->cache->loadLocale($locale); |
| 53 | - if (!empty($data)) { |
|
| 56 | + if (!empty($data)) |
|
| 57 | + { |
|
| 54 | 58 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
| 55 | - } else { |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + { |
|
| 56 | 62 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
| 57 | 63 | } |
| 58 | 64 | |
@@ -80,7 +86,8 @@ discard block |
||
| 80 | 86 | public function reset(): void |
| 81 | 87 | { |
| 82 | 88 | $this->cache->setLocales(null); |
| 83 | - foreach ($this->getLocales() as $locale) { |
|
| 89 | + foreach ($this->getLocales() as $locale) |
|
| 90 | + { |
|
| 84 | 91 | $this->cache->saveLocale($locale, null); |
| 85 | 92 | } |
| 86 | 93 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** @internal */ |
| 27 | 27 | private readonly IdentityTranslator $identityTranslator = new IdentityTranslator(), |
| 28 | 28 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 29 | - ) { |
|
| 29 | + ){ |
|
| 30 | 30 | $this->locale = $this->config->getDefaultLocale(); |
| 31 | 31 | $this->catalogueManager->load($this->locale); |
| 32 | 32 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setLocale(string $locale): void |
| 43 | 43 | { |
| 44 | - if (!$this->catalogueManager->has($locale)) { |
|
| 44 | + if (!$this->catalogueManager->has($locale)){ |
|
| 45 | 45 | throw new LocaleException($locale); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function transChoice( |
| 87 | 87 | string $id, |
| 88 | - string|int $number, |
|
| 88 | + string | int $number, |
|
| 89 | 89 | array $parameters = [], |
| 90 | 90 | string $domain = null, |
| 91 | 91 | string $locale = null |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $domain = $domain ?? $this->config->getDefaultDomain(); |
| 94 | 94 | $locale = $locale ?? $this->locale; |
| 95 | 95 | |
| 96 | - try { |
|
| 96 | + try{ |
|
| 97 | 97 | $message = $this->get($locale, $domain, $id); |
| 98 | 98 | |
| 99 | 99 | $pluralized = $this->identityTranslator->trans( |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | null, |
| 103 | 103 | $locale |
| 104 | 104 | ); |
| 105 | - } catch (\InvalidArgumentException $e) { |
|
| 105 | + }catch (\InvalidArgumentException $e){ |
|
| 106 | 106 | //Wrapping into more explanatory exception |
| 107 | 107 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
| 110 | + if (empty($parameters['n']) && is_numeric($number)){ |
|
| 111 | 111 | $parameters['n'] = $number; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -131,18 +131,18 @@ discard block |
||
| 131 | 131 | string $postfix = '}' |
| 132 | 132 | ): string { |
| 133 | 133 | $replaces = []; |
| 134 | - foreach ($values as $key => $value) { |
|
| 134 | + foreach ($values as $key => $value){ |
|
| 135 | 135 | $value = (\is_array($value) || $value instanceof \Closure) ? '' : $value; |
| 136 | 136 | |
| 137 | - if (\is_object($value)) { |
|
| 138 | - if (\method_exists($value, '__toString')) { |
|
| 137 | + if (\is_object($value)){ |
|
| 138 | + if (\method_exists($value, '__toString')){ |
|
| 139 | 139 | $value = $value->__toString(); |
| 140 | - } else { |
|
| 140 | + }else{ |
|
| 141 | 141 | $value = ''; |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $replaces[$prefix . $key . $postfix] = $value; |
|
| 145 | + $replaces[$prefix.$key.$postfix] = $value; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | return \strtr($string, $replaces); |
@@ -162,18 +162,18 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function get(string &$locale, string $domain, string $string): string |
| 164 | 164 | { |
| 165 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 165 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
| 166 | 166 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $locale = $this->config->getFallbackLocale(); |
| 170 | 170 | |
| 171 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 171 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
| 172 | 172 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // we can automatically register message |
| 176 | - if ($this->config->isAutoRegisterMessages()) { |
|
| 176 | + if ($this->config->isAutoRegisterMessages()){ |
|
| 177 | 177 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
| 178 | 178 | $this->catalogueManager->save($locale); |
| 179 | 179 | } |
@@ -41,7 +41,8 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setLocale(string $locale): void |
| 43 | 43 | { |
| 44 | - if (!$this->catalogueManager->has($locale)) { |
|
| 44 | + if (!$this->catalogueManager->has($locale)) |
|
| 45 | + { |
|
| 45 | 46 | throw new LocaleException($locale); |
| 46 | 47 | } |
| 47 | 48 | |
@@ -93,7 +94,8 @@ discard block |
||
| 93 | 94 | $domain = $domain ?? $this->config->getDefaultDomain(); |
| 94 | 95 | $locale = $locale ?? $this->locale; |
| 95 | 96 | |
| 96 | - try { |
|
| 97 | + try |
|
| 98 | + { |
|
| 97 | 99 | $message = $this->get($locale, $domain, $id); |
| 98 | 100 | |
| 99 | 101 | $pluralized = $this->identityTranslator->trans( |
@@ -102,12 +104,15 @@ discard block |
||
| 102 | 104 | null, |
| 103 | 105 | $locale |
| 104 | 106 | ); |
| 105 | - } catch (\InvalidArgumentException $e) { |
|
| 107 | + } |
|
| 108 | + catch (\InvalidArgumentException $e) |
|
| 109 | + { |
|
| 106 | 110 | //Wrapping into more explanatory exception |
| 107 | 111 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
| 108 | 112 | } |
| 109 | 113 | |
| 110 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
| 114 | + if (empty($parameters['n']) && is_numeric($number)) |
|
| 115 | + { |
|
| 111 | 116 | $parameters['n'] = $number; |
| 112 | 117 | } |
| 113 | 118 | |
@@ -131,13 +136,18 @@ discard block |
||
| 131 | 136 | string $postfix = '}' |
| 132 | 137 | ): string { |
| 133 | 138 | $replaces = []; |
| 134 | - foreach ($values as $key => $value) { |
|
| 139 | + foreach ($values as $key => $value) |
|
| 140 | + { |
|
| 135 | 141 | $value = (\is_array($value) || $value instanceof \Closure) ? '' : $value; |
| 136 | 142 | |
| 137 | - if (\is_object($value)) { |
|
| 138 | - if (\method_exists($value, '__toString')) { |
|
| 143 | + if (\is_object($value)) |
|
| 144 | + { |
|
| 145 | + if (\method_exists($value, '__toString')) |
|
| 146 | + { |
|
| 139 | 147 | $value = $value->__toString(); |
| 140 | - } else { |
|
| 148 | + } |
|
| 149 | + else |
|
| 150 | + { |
|
| 141 | 151 | $value = ''; |
| 142 | 152 | } |
| 143 | 153 | } |
@@ -162,18 +172,21 @@ discard block |
||
| 162 | 172 | */ |
| 163 | 173 | protected function get(string &$locale, string $domain, string $string): string |
| 164 | 174 | { |
| 165 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 175 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 176 | + { |
|
| 166 | 177 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 167 | 178 | } |
| 168 | 179 | |
| 169 | 180 | $locale = $this->config->getFallbackLocale(); |
| 170 | 181 | |
| 171 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 182 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 183 | + { |
|
| 172 | 184 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 173 | 185 | } |
| 174 | 186 | |
| 175 | 187 | // we can automatically register message |
| 176 | - if ($this->config->isAutoRegisterMessages()) { |
|
| 188 | + if ($this->config->isAutoRegisterMessages()) |
|
| 189 | + { |
|
| 177 | 190 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
| 178 | 191 | $this->catalogueManager->save($locale); |
| 179 | 192 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public function __construct( |
| 20 | 20 | private readonly string $locale, |
| 21 | 21 | private array $data = [] |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function getLocale(): string |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function has(string $domain, string $id): bool |
| 36 | 36 | { |
| 37 | - if (!isset($this->data[$domain])) { |
|
| 37 | + if (!isset($this->data[$domain])){ |
|
| 38 | 38 | return false; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public function get(string $domain, string $id): string |
| 45 | 45 | { |
| 46 | - if (!$this->has($domain, $id)) { |
|
| 46 | + if (!$this->has($domain, $id)){ |
|
| 47 | 47 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
| 68 | 68 | { |
| 69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
| 70 | - if (!isset($this->data[$domain])) { |
|
| 69 | + foreach ($catalogue->all() as $domain => $messages){ |
|
| 70 | + if (!isset($this->data[$domain])){ |
|
| 71 | 71 | $this->data[$domain] = []; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($follow) { |
|
| 74 | + if ($follow){ |
|
| 75 | 75 | //MessageCatalogue string has higher priority that string stored in memory |
| 76 | 76 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
| 77 | - } else { |
|
| 77 | + }else{ |
|
| 78 | 78 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function has(string $domain, string $id): bool |
| 36 | 36 | { |
| 37 | - if (!isset($this->data[$domain])) { |
|
| 37 | + if (!isset($this->data[$domain])) |
|
| 38 | + { |
|
| 38 | 39 | return false; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -43,7 +44,8 @@ discard block |
||
| 43 | 44 | |
| 44 | 45 | public function get(string $domain, string $id): string |
| 45 | 46 | { |
| 46 | - if (!$this->has($domain, $id)) { |
|
| 47 | + if (!$this->has($domain, $id)) |
|
| 48 | + { |
|
| 47 | 49 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
| 48 | 50 | } |
| 49 | 51 | |
@@ -66,15 +68,20 @@ discard block |
||
| 66 | 68 | */ |
| 67 | 69 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
| 68 | 70 | { |
| 69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
| 70 | - if (!isset($this->data[$domain])) { |
|
| 71 | + foreach ($catalogue->all() as $domain => $messages) |
|
| 72 | + { |
|
| 73 | + if (!isset($this->data[$domain])) |
|
| 74 | + { |
|
| 71 | 75 | $this->data[$domain] = []; |
| 72 | 76 | } |
| 73 | 77 | |
| 74 | - if ($follow) { |
|
| 78 | + if ($follow) |
|
| 79 | + { |
|
| 75 | 80 | //MessageCatalogue string has higher priority that string stored in memory |
| 76 | 81 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
| 77 | - } else { |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 78 | 85 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
| 79 | 86 | } |
| 80 | 87 | } |