@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected function say(string $string, array $options = [], $bundle = null): string |
43 | 43 | { |
44 | - if (Translator::isMessage($string)) { |
|
44 | + if (Translator::isMessage($string)){ |
|
45 | 45 | //Cut [[ and ]] |
46 | 46 | $string = substr($string, 2, -2); |
47 | 47 | } |
48 | 48 | |
49 | 49 | $container = ContainerScope::getContainer(); |
50 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
50 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
51 | 51 | return Translator::interpolate($string, $options); |
52 | 52 | } |
53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | $translator = $container->get(TranslatorInterface::class); |
58 | 58 | |
59 | - if (is_null($bundle)) { |
|
59 | + if (is_null($bundle)){ |
|
60 | 60 | $bundle = $translator->getDomain(static::class); |
61 | 61 | } |
62 | 62 |
@@ -41,13 +41,15 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected function say(string $string, array $options = [], $bundle = null): string |
43 | 43 | { |
44 | - if (Translator::isMessage($string)) { |
|
44 | + if (Translator::isMessage($string)) |
|
45 | + { |
|
45 | 46 | //Cut [[ and ]] |
46 | 47 | $string = substr($string, 2, -2); |
47 | 48 | } |
48 | 49 | |
49 | 50 | $container = ContainerScope::getContainer(); |
50 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
51 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
52 | + { |
|
51 | 53 | return Translator::interpolate($string, $options); |
52 | 54 | } |
53 | 55 | |
@@ -56,7 +58,8 @@ discard block |
||
56 | 58 | */ |
57 | 59 | $translator = $container->get(TranslatorInterface::class); |
58 | 60 | |
59 | - if (is_null($bundle)) { |
|
61 | + if (is_null($bundle)) |
|
62 | + { |
|
60 | 63 | $bundle = $translator->getDomain(static::class); |
61 | 64 | } |
62 | 65 |
@@ -107,9 +107,12 @@ |
||
107 | 107 | { |
108 | 108 | $bundle = strtolower(str_replace(['/', '\\'], '-', $bundle)); |
109 | 109 | |
110 | - foreach ($this->config['domains'] as $domain => $patterns) { |
|
111 | - foreach ($patterns as $pattern) { |
|
112 | - if ($this->matcher->matches($bundle, $pattern)) { |
|
110 | + foreach ($this->config['domains'] as $domain => $patterns) |
|
111 | + { |
|
112 | + foreach ($patterns as $pattern) |
|
113 | + { |
|
114 | + if ($this->matcher->matches($bundle, $pattern)) |
|
115 | + { |
|
113 | 116 | return $domain; |
114 | 117 | } |
115 | 118 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | public function getLocaleDirectory(string $locale): string |
78 | 78 | { |
79 | - return $this->getLocalesDirectory() . $locale . '/'; |
|
79 | + return $this->getLocalesDirectory().$locale.'/'; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | { |
87 | 87 | $bundle = strtolower(str_replace(['/', '\\'], '-', $bundle)); |
88 | 88 | |
89 | - foreach ($this->config['domains'] as $domain => $patterns) { |
|
90 | - foreach ($patterns as $pattern) { |
|
91 | - if ($this->matcher->matches($bundle, $pattern)) { |
|
89 | + foreach ($this->config['domains'] as $domain => $patterns){ |
|
90 | + foreach ($patterns as $pattern){ |
|
91 | + if ($this->matcher->matches($bundle, $pattern)){ |
|
92 | 92 | return $domain; |
93 | 93 | } |
94 | 94 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | */ |
51 | 51 | public function loadCatalogue(string $locale): CatalogueInterface |
52 | 52 | { |
53 | - if (!$this->hasLocale($locale)) { |
|
53 | + if (!$this->hasLocale($locale)){ |
|
54 | 54 | throw new LocaleException($locale); |
55 | 55 | } |
56 | 56 |
@@ -50,7 +50,8 @@ |
||
50 | 50 | */ |
51 | 51 | public function loadCatalogue(string $locale): CatalogueInterface |
52 | 52 | { |
53 | - if (!$this->hasLocale($locale)) { |
|
53 | + if (!$this->hasLocale($locale)) |
|
54 | + { |
|
54 | 55 | throw new LocaleException($locale); |
55 | 56 | } |
56 | 57 |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getLocales(): array |
52 | 52 | { |
53 | - if ($this->locales !== []) { |
|
53 | + if ($this->locales !== []){ |
|
54 | 54 | return $this->locales; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $this->locales = (array)$this->cache->getLocales(); |
58 | - if ($this->locales === []) { |
|
58 | + if ($this->locales === []){ |
|
59 | 59 | $this->locales = $this->loader->getLocales(); |
60 | 60 | $this->cache->setLocales($this->locales); |
61 | 61 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function load(string $locale): CatalogueInterface |
70 | 70 | { |
71 | - if (isset($this->catalogues[$locale])) { |
|
71 | + if (isset($this->catalogues[$locale])){ |
|
72 | 72 | return $this->catalogues[$locale]; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $data = (array)$this->cache->loadLocale($locale); |
76 | - if (!empty($data)) { |
|
76 | + if (!empty($data)){ |
|
77 | 77 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
78 | - } else { |
|
78 | + }else{ |
|
79 | 79 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
80 | 80 | } |
81 | 81 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function reset(): void |
113 | 113 | { |
114 | 114 | $this->cache->setLocales(null); |
115 | - foreach ($this->getLocales() as $locale) { |
|
115 | + foreach ($this->getLocales() as $locale){ |
|
116 | 116 | $this->cache->saveLocale($locale, null); |
117 | 117 | } |
118 | 118 |
@@ -50,12 +50,14 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getLocales(): array |
52 | 52 | { |
53 | - if ($this->locales !== []) { |
|
53 | + if ($this->locales !== []) |
|
54 | + { |
|
54 | 55 | return $this->locales; |
55 | 56 | } |
56 | 57 | |
57 | 58 | $this->locales = (array)$this->cache->getLocales(); |
58 | - if ($this->locales === []) { |
|
59 | + if ($this->locales === []) |
|
60 | + { |
|
59 | 61 | $this->locales = $this->loader->getLocales(); |
60 | 62 | $this->cache->setLocales($this->locales); |
61 | 63 | } |
@@ -68,14 +70,18 @@ discard block |
||
68 | 70 | */ |
69 | 71 | public function load(string $locale): CatalogueInterface |
70 | 72 | { |
71 | - if (isset($this->catalogues[$locale])) { |
|
73 | + if (isset($this->catalogues[$locale])) |
|
74 | + { |
|
72 | 75 | return $this->catalogues[$locale]; |
73 | 76 | } |
74 | 77 | |
75 | 78 | $data = (array)$this->cache->loadLocale($locale); |
76 | - if (!empty($data)) { |
|
79 | + if (!empty($data)) |
|
80 | + { |
|
77 | 81 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
78 | - } else { |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
79 | 85 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
80 | 86 | } |
81 | 87 | |
@@ -112,7 +118,8 @@ discard block |
||
112 | 118 | public function reset(): void |
113 | 119 | { |
114 | 120 | $this->cache->setLocales(null); |
115 | - foreach ($this->getLocales() as $locale) { |
|
121 | + foreach ($this->getLocales() as $locale) |
|
122 | + { |
|
116 | 123 | $this->cache->saveLocale($locale, null); |
117 | 124 | } |
118 | 125 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Spiral\Translator\Exception\TranslatorException; |
15 | 15 | use Spiral\Translator\TranslatorInterface; |
16 | 16 | |
17 | -if (!function_exists('l')) { |
|
17 | +if (!function_exists('l')){ |
|
18 | 18 | /** |
19 | 19 | * Translate message using default or specific bundle name. |
20 | 20 | * |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | function l(string $string, array $options = [], string $domain = null): string |
35 | 35 | { |
36 | 36 | $container = ContainerScope::getContainer(); |
37 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
37 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
38 | 38 | throw new ScopeException( |
39 | 39 | '`TranslatorInterface` binding is missing or container scope is not set' |
40 | 40 | ); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | -if (!function_exists('p')) { |
|
50 | +if (!function_exists('p')){ |
|
51 | 51 | /** |
52 | 52 | * Pluralize string using language pluralization options and specified numeric value. |
53 | 53 | * |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | function p(string $string, int $number, array $options = [], string $domain = null): string |
68 | 68 | { |
69 | 69 | $container = ContainerScope::getContainer(); |
70 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
70 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
71 | 71 | throw new ScopeException( |
72 | 72 | '`TranslatorInterface` binding is missing or container scope is not set' |
73 | 73 | ); |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | use Spiral\Translator\Exception\TranslatorException; |
15 | 15 | use Spiral\Translator\TranslatorInterface; |
16 | 16 | |
17 | -if (!function_exists('l')) { |
|
17 | +if (!function_exists('l')) |
|
18 | +{ |
|
18 | 19 | /** |
19 | 20 | * Translate message using default or specific bundle name. |
20 | 21 | * |
@@ -34,7 +35,8 @@ discard block |
||
34 | 35 | function l(string $string, array $options = [], string $domain = null): string |
35 | 36 | { |
36 | 37 | $container = ContainerScope::getContainer(); |
37 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
38 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
39 | + { |
|
38 | 40 | throw new ScopeException( |
39 | 41 | '`TranslatorInterface` binding is missing or container scope is not set' |
40 | 42 | ); |
@@ -47,7 +49,8 @@ discard block |
||
47 | 49 | } |
48 | 50 | } |
49 | 51 | |
50 | -if (!function_exists('p')) { |
|
52 | +if (!function_exists('p')) |
|
53 | +{ |
|
51 | 54 | /** |
52 | 55 | * Pluralize string using language pluralization options and specified numeric value. |
53 | 56 | * |
@@ -67,7 +70,8 @@ discard block |
||
67 | 70 | function p(string $string, int $number, array $options = [], string $domain = null): string |
68 | 71 | { |
69 | 72 | $container = ContainerScope::getContainer(); |
70 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
73 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
74 | + { |
|
71 | 75 | throw new ScopeException( |
72 | 76 | '`TranslatorInterface` binding is missing or container scope is not set' |
73 | 77 | ); |
@@ -77,7 +77,7 @@ |
||
77 | 77 | $container = new Container(); |
78 | 78 | $container->bind(TranslatorConfig::class, new TranslatorConfig([ |
79 | 79 | 'locale' => 'en', |
80 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
80 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
81 | 81 | 'loaders' => [ |
82 | 82 | 'php' => PhpFileLoader::class, |
83 | 83 | 'po' => PoFileLoader::class, |
@@ -44,7 +44,7 @@ |
||
44 | 44 | |
45 | 45 | $this->container->bind(TranslatorConfig::class, new TranslatorConfig([ |
46 | 46 | 'locale' => 'en', |
47 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
47 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
48 | 48 | 'loaders' => [ |
49 | 49 | 'php' => PhpFileLoader::class, |
50 | 50 | 'po' => PoFileLoader::class, |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function testHasLocale(): void |
26 | 26 | { |
27 | 27 | $loader = new CatalogueLoader(new TranslatorConfig([ |
28 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
28 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
29 | 29 | ])); |
30 | 30 | |
31 | 31 | $this->assertTrue($loader->hasLocale('ru')); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function testGetLocales(): void |
36 | 36 | { |
37 | 37 | $loader = new CatalogueLoader(new TranslatorConfig([ |
38 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
38 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
39 | 39 | ])); |
40 | 40 | |
41 | 41 | $compared = $loader->getLocales(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function testLoadCatalogue(): void |
50 | 50 | { |
51 | 51 | $loader = new CatalogueLoader(new TranslatorConfig([ |
52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
53 | 53 | 'loaders' => [ |
54 | 54 | 'php' => PhpFileLoader::class, |
55 | 55 | 'po' => PoFileLoader::class, |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function testLoadCatalogueNoLoader(): void |
90 | 90 | { |
91 | 91 | $loader = new CatalogueLoader(new TranslatorConfig([ |
92 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
92 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
93 | 93 | 'loaders' => [ |
94 | 94 | 'php' => PhpFileLoader::class, |
95 | 95 | ], |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $cache->shouldReceive('setLocales')->andReturn(null); |
32 | 32 | |
33 | 33 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
34 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
34 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
35 | 35 | 'loaders' => [ |
36 | 36 | 'php' => PhpFileLoader::class, |
37 | 37 | 'po' => PoFileLoader::class, |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $cache->shouldNotReceive('setLocales')->andReturn(null); |
50 | 50 | |
51 | 51 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
53 | 53 | 'loaders' => [ |
54 | 54 | 'php' => PhpFileLoader::class, |
55 | 55 | 'po' => PoFileLoader::class, |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $cache->shouldReceive('getLocales')->andReturn(['en', 'ru']); |
67 | 67 | |
68 | 68 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
69 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
69 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
70 | 70 | 'loaders' => [ |
71 | 71 | 'php' => PhpFileLoader::class, |
72 | 72 | 'po' => PoFileLoader::class, |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | ]); |
130 | 130 | |
131 | 131 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
132 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
132 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
133 | 133 | 'loaders' => [ |
134 | 134 | 'php' => PhpFileLoader::class, |
135 | 135 | 'po' => PoFileLoader::class, |