Adding new method to get all translations for a locale, group and namespace

parent aed2dcb0
......@@ -101,4 +101,15 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
{
return str_replace(" ", "--", $key);
}
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace)
{
return $this->cache
->tags([$this->entityName, 'global'])
->rememberForever("{$this->entityName}.findByKeyAndLocale.{$locale}.{$group}.[$namespace]",
function () use ($locale, $group, $namespace) {
return $this->repository->getTranslationsForGroupAndNamespace($locale, $group, $namespace);
}
);
}
}
......@@ -2,6 +2,7 @@
namespace Modules\Translation\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Translation\Entities\TranslationTranslation;
use Modules\Translation\Repositories\TranslationRepository;
......@@ -24,6 +25,23 @@ class EloquentTranslationRepository extends EloquentBaseRepository implements Tr
return '';
}
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace)
{
$start = $namespace . '::' . $group;
$test = $this->model->where('key', 'LIKE', "{$start}%")->whereHas('translations', function (Builder $query) use ($locale) {
$query->where('locale', $locale);
})->get();
$translations = [];
foreach ($test as $item) {
$key = str_replace($start . '.', '', $item->key);
$translations[$key] = $item->translate($locale)->value;
}
return $translations;
}
public function allFormatted()
{
$allRows = $this->all();
......
......@@ -48,4 +48,6 @@ interface TranslationRepository extends BaseRepository
* @return void
*/
public function updateTranslationToValue(TranslationTranslation $translationTranslation, $value);
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment