2020-08-11 02:48:05 +02:00
|
|
|
<?php
|
2020-11-10 04:27:25 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-11-10 04:27:25 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-08-11 02:48:05 +02:00
|
|
|
|
|
|
|
namespace App\Helpers\Language;
|
|
|
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Translation\Translator;
|
|
|
|
|
|
|
|
class NinjaTranslator extends Translator
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Set translation.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param string $key
|
|
|
|
* @param mixed $value
|
|
|
|
* @param null $locale
|
2020-08-11 02:48:05 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function set($key, $value, $locale = null)
|
|
|
|
{
|
|
|
|
list($namespace, $group, $item) = $this->parseKey($key);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (null === $locale) {
|
2020-08-11 02:48:05 +02:00
|
|
|
$locale = $this->locale;
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-08-11 02:48:05 +02:00
|
|
|
|
|
|
|
// Load given group defaults if exists
|
|
|
|
$this->load($namespace, $group, $locale);
|
|
|
|
|
|
|
|
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function replace($items, $locale = null)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (null === $locale) {
|
2020-08-11 02:48:05 +02:00
|
|
|
$locale = $this->locale;
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-08-11 02:48:05 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
foreach ($items as $key => $value) {
|
2020-08-11 03:03:49 +02:00
|
|
|
list($namespace, $group, $item) = $this->parseKey($key);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-11 03:03:49 +02:00
|
|
|
$this->load($namespace, $group, $locale);
|
2020-08-11 02:48:05 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
Arr::set($this->loaded[$namespace][$group][$locale], $item, $value);
|
2020-08-11 02:48:05 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|