Skip to content

Commit

Permalink
Don't ignore empty MO translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
berarma committed Aug 1, 2017
1 parent 47d1d27 commit 02e8c3d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/I18n/ChainMessagesLoader.php
Expand Up @@ -71,9 +71,7 @@ public function __invoke()
));
}

if (count($package->getMessages())) {
return $package;
}
return $package;
}

return new Package();
Expand Down
6 changes: 3 additions & 3 deletions src/I18n/MessagesFileLoader.php
Expand Up @@ -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;
Expand All @@ -126,7 +125,7 @@ public function __invoke()
}

if (!$file) {
return $package;
return false;
}

$name = ucfirst($ext);
Expand All @@ -137,6 +136,7 @@ public function __invoke()
}

$messages = (new $class)->parse($file);
$package = new Package('default');
$package->setMessages($messages);

return $package;
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/I18n/MessagesFileLoaderTest.php
Expand Up @@ -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);
}
}
Binary file added tests/test_app/TestApp/Locale/es/empty.mo
Binary file not shown.

0 comments on commit 02e8c3d

Please sign in to comment.