diff --git a/src/I18n/ChainMessagesLoader.php b/src/I18n/ChainMessagesLoader.php index f9cb7a3fb21..9b613013d02 100644 --- a/src/I18n/ChainMessagesLoader.php +++ b/src/I18n/ChainMessagesLoader.php @@ -71,9 +71,7 @@ public function __invoke() )); } - if (count($package->getMessages())) { - return $package; - } + return $package; } return new Package(); diff --git a/src/I18n/MessagesFileLoader.php b/src/I18n/MessagesFileLoader.php index f8d89506232..3fb0d60bfaa 100644 --- a/src/I18n/MessagesFileLoader.php +++ b/src/I18n/MessagesFileLoader.php @@ -101,13 +101,12 @@ public function __construct($name, $locale, $extension = 'po') * Loads the translation file and parses it. Returns an instance of a translations * package containing the messages loaded from the file. * - * @return \Aura\Intl\Package + * @return \Aura\Intl\Package|false * @throws \RuntimeException if no file parser class could be found for the specified * file extension. */ public function __invoke() { - $package = new Package('default'); $folders = $this->translationsFolders(); $ext = $this->_extension; $file = false; @@ -126,7 +125,7 @@ public function __invoke() } if (!$file) { - return $package; + return false; } $name = ucfirst($ext); @@ -137,6 +136,7 @@ public function __invoke() } $messages = (new $class)->parse($file); + $package = new Package('default'); $package->setMessages($messages); return $package; diff --git a/tests/TestCase/I18n/MessagesFileLoaderTest.php b/tests/TestCase/I18n/MessagesFileLoaderTest.php index 3dddaaf7668..167faf0a5ff 100644 --- a/tests/TestCase/I18n/MessagesFileLoaderTest.php +++ b/tests/TestCase/I18n/MessagesFileLoaderTest.php @@ -64,4 +64,19 @@ public function testCustomLocalePath() $messages = $package->getMessages(); $this->assertEquals('Po (translated) from custom folder', $messages['Plural Rule 1']['_context']['']); } + + /** + * Test reading MO files + * @return void + */ + public function testLoadingMoFiles() + { + $loader = new MessagesFileLoader('empty', 'es', 'mo'); + $package = $loader(); + $this->assertNotFalse($package); + + $loader = new MessagesFileLoader('missing', 'es', 'mo'); + $package = $loader(); + $this->assertFalse($package); + } } diff --git a/tests/test_app/TestApp/Locale/es/empty.mo b/tests/test_app/TestApp/Locale/es/empty.mo new file mode 100644 index 00000000000..3e3b426809b Binary files /dev/null and b/tests/test_app/TestApp/Locale/es/empty.mo differ