Browse Source

Update App::path() to return locales path for plugins too.

Refs #14463
ADmad 6 years ago
parent
commit
d63bf24480
3 changed files with 16 additions and 4 deletions
  1. 5 0
      src/Core/App.php
  2. 1 1
      src/I18n/MessagesFileLoader.php
  3. 10 3
      tests/TestCase/Core/AppTest.php

+ 5 - 0
src/Core/App.php

@@ -199,6 +199,11 @@ class App
             return [Plugin::templatePath($plugin)];
         }
 
+        if ($type === 'locales') {
+            /** @psalm-suppress PossiblyNullArgument */
+            return [Plugin::path($plugin) . 'resources' . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR];
+        }
+
         deprecationWarning(
             'App::path() is deprecated for class path.'
             . ' Use \Cake\Core\App::classPath() or \Cake\Core\Plugin::classPath() instead.'

+ 1 - 1
src/I18n/MessagesFileLoader.php

@@ -173,7 +173,7 @@ class MessagesFileLoader
         // If space is not added after slash, the character after it remains lowercased
         $pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name));
         if (Plugin::isLoaded($pluginName)) {
-            $basePath = Plugin::path($pluginName) . 'resources' . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR;
+            $basePath = App::path('locales', $pluginName)[0];
             foreach ($folders as $folder) {
                 $searchPaths[] = $basePath . $folder . DIRECTORY_SEPARATOR;
             }

+ 10 - 3
tests/TestCase/Core/AppTest.php

@@ -242,10 +242,17 @@ class AppTest extends TestCase
      */
     public function testPathWithPlugins()
     {
-        $this->deprecated(function () {
-            $basepath = TEST_APP . 'Plugin' . DS;
-            $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
+        $basepath = TEST_APP . 'Plugin' . DS;
+        $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
+
+        $result = App::path('locales', 'TestPlugin');
+        $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'resources' . DS . 'locales' . DS, $result[0]);
+
+        $result = App::path('locales', 'Company/TestPluginThree');
+        $expected = $basepath . 'Company' . DS . 'TestPluginThree' . DS . 'resources' . DS . 'locales' . DS;
+        $this->assertPathEquals($expected, $result[0]);
 
+        $this->deprecated(function () use ($basepath) {
             $result = App::path('Controller', 'TestPlugin');
             $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'src' . DS . 'Controller' . DS, $result[0]);