浏览代码

Add ability to provide custom paths for locale files.

ADmad 11 年之前
父节点
当前提交
a39d28ce1a
共有 3 个文件被更改,包括 15 次插入6 次删除
  1. 3 0
      src/Core/App.php
  2. 10 5
      src/I18n/MessagesFileLoader.php
  3. 2 1
      tests/bootstrap.php

+ 3 - 0
src/Core/App.php

@@ -114,6 +114,9 @@ class App {
 		if ($type === 'Plugin') {
 			return (array)Configure::read('App.paths.plugins');
 		}
+		if (empty($plugin) && $type === 'Locale') {
+			return (array)Configure::read('App.paths.locales');
+		}
 		if (empty($plugin) && $type === 'Template') {
 			return (array)Configure::read('App.paths.templates');
 		}

+ 10 - 5
src/I18n/MessagesFileLoader.php

@@ -151,15 +151,20 @@ class MessagesFileLoader {
 			$locale['language']
 		];
 
-		// If space is not added after slash, the character after it remains lowercased
-		$pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name));
-		$basePath = APP . 'Locale' . DS;
 		$searchPath = [];
 
-		foreach ($folders as $folder) {
-			$searchPath[] = $basePath . $folder . DS;
+		$localePaths = App::path('Locale');
+		if (empty($localePaths)) {
+			$localePaths[] = APP . 'Locale' . DS;
+		}
+		foreach ($localePaths as $path) {
+			foreach ($folders as $folder) {
+				$searchPath[] = $path . $folder . DS;
+			}
 		}
 
+		// If space is not added after slash, the character after it remains lowercased
+		$pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name));
 		if (Plugin::loaded($pluginName)) {
 			$basePath = Plugin::classPath($pluginName) . 'Locale' . DS;
 			foreach ($folders as $folder) {

+ 2 - 1
tests/bootstrap.php

@@ -79,7 +79,8 @@ Configure::write('App', [
 	'cssBaseUrl' => 'css/',
 	'paths' => [
 		'plugins' => [TEST_APP . 'Plugin' . DS],
-		'templates' => [APP . 'Template' . DS]
+		'templates' => [APP . 'Template' . DS],
+		'locales' => [APP . 'Locale' . DS],
 	]
 ]);