mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-02 19:14:35 -04:00
Inject custom translations when needed
This commit is contained in:
parent
d05c6ec975
commit
ab5dc13662
@ -30,52 +30,19 @@ class NinjaTranslator extends Translator
|
|||||||
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set multiple translations.
|
|
||||||
*
|
|
||||||
* @param array $items Format: [group => [key => value]]
|
|
||||||
* @param string $locale
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function add(array $items, $locale = null)
|
|
||||||
{
|
|
||||||
if(null === $locale)
|
|
||||||
{
|
|
||||||
$locale = $this->locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($items as $group => $translations)
|
|
||||||
{
|
|
||||||
// Build key to parse
|
|
||||||
$key = $group.'.'.key($translations);
|
|
||||||
|
|
||||||
list($namespace, $group) = $this->parseKey($key);
|
|
||||||
|
|
||||||
// Load given group defaults if exists
|
|
||||||
$this->load($namespace, $group, $locale);
|
|
||||||
|
|
||||||
foreach($translations as $item => $value)
|
|
||||||
{
|
|
||||||
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function replace($items, $locale = null)
|
public function replace($items, $locale = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(null === $locale)
|
if(null === $locale)
|
||||||
{
|
|
||||||
$locale = $this->locale;
|
$locale = $this->locale;
|
||||||
}
|
|
||||||
|
|
||||||
// Load given group defaults if exists
|
|
||||||
$this->load($namespace, $group, $locale);
|
|
||||||
|
|
||||||
foreach($items as $key => $value)
|
foreach($items as $key => $value)
|
||||||
{
|
{
|
||||||
|
|
||||||
list($namespace, $group, $item) = $this->parseKey($key);
|
list($namespace, $group, $item) = $this->parseKey($key);
|
||||||
|
|
||||||
|
$this->load($namespace, $group, $locale);
|
||||||
|
|
||||||
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,5 +27,28 @@ class TranslationTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testReplaceTranslation()
|
||||||
|
{
|
||||||
|
|
||||||
|
Lang::set('texts.invoice_number', 'test');
|
||||||
|
|
||||||
|
$this->assertEquals('test', trans('texts.invoice_number'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testReplaceArray()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'texts.invoice_number' => 'test',
|
||||||
|
'texts.custom_translation' => 'test2'
|
||||||
|
];
|
||||||
|
|
||||||
|
Lang::replace($data);
|
||||||
|
|
||||||
|
$this->assertEquals('test', trans('texts.invoice_number'));
|
||||||
|
$this->assertEquals('test2', trans('texts.custom_translation'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user