Permalink
Browse files

A new packages directory within `lang` can now override package langu…

…age files.
  • Loading branch information...
taylorotwell committed Oct 28, 2013
1 parent 9be92f0 commit 5483042e8762d4f8ffc356579ddaae4f7dc3cbc9
@@ -29,7 +29,8 @@
{"message": "When unit testing, the application instance is now refreshed once per test class - not every test.", "backport": null},
{"message": "Added 'whereNotBetween' support to the query builder.", "backport": null},
{"message": "Added App::middleware method to inject middlewares onto Stack.", "backport": null},
{"message": "Deprecate 'close' application hooks, Stack middlewares should be used instead.", "backport": null}
{"message": "Deprecate 'close' application hooks, Stack middlewares should be used instead.", "backport": null},
{"message": "A new packages directory within `lang` can now override package language files.", "backport": null}
],
"4.0.x": [
{"message": "Added implode method to query builder and Collection class.", "backport": null},
@@ -70,12 +70,35 @@ protected function loadNamespaced($locale, $group, $namespace)
{
if (isset($this->hints[$namespace]))
{
return $this->loadPath($this->hints[$namespace], $locale, $group);
$lines = $this->loadPath($this->hints[$namespace], $locale, $group);
return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace);
}
return array();
}
/**
* Load a local namespaced translation group for overrides.
*
* @param array $lines
* @param string $locale
* @param string $group
* @param string $namespace
* @return array
*/
protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)
{
$file = "{$this->path}/packages/{$locale}/{$namespace}/{$group}.php";
if ($this->files->exists($file))
{
return array_replace_recursive($lines, $this->files->getRequire($file));
}
return $lines;
}
/**
* Load a locale from a given path.
*
@@ -26,10 +26,24 @@ public function testLoadMethodWithNamespacesProperlyCallsLoader()
{
$loader = new FileLoader($files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__);
$files->shouldReceive('exists')->once()->with('bar/en/foo.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with('bar/en/foo.php')->andReturn(array('messages'));
$files->shouldReceive('exists')->once()->with(__DIR__.'/packages/en/namespace/foo.php')->andReturn(false);
$files->shouldReceive('getRequire')->once()->with('bar/en/foo.php')->andReturn(array('foo' => 'bar'));
$loader->addNamespace('namespace', 'bar');
$this->assertEquals(array('messages'), $loader->load('en', 'foo', 'namespace'));
$this->assertEquals(array('foo' => 'bar'), $loader->load('en', 'foo', 'namespace'));
}
public function testLoadMethodWithNamespacesProperlyCallsLoaderAndLoadsLocalOverrides()
{
$loader = new FileLoader($files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__);
$files->shouldReceive('exists')->once()->with('bar/en/foo.php')->andReturn(true);
$files->shouldReceive('exists')->once()->with(__DIR__.'/packages/en/namespace/foo.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with('bar/en/foo.php')->andReturn(array('foo' => 'bar'));
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/packages/en/namespace/foo.php')->andReturn(array('foo' => 'override', 'baz' => 'boom'));
$loader->addNamespace('namespace', 'bar');
$this->assertEquals(array('foo' => 'override', 'baz' => 'boom'), $loader->load('en', 'foo', 'namespace'));
}

0 comments on commit 5483042

Please sign in to comment.