bugfixes
All checks were successful
Build & Push Docker Image / docker (push) Successful in 1m48s

This commit is contained in:
Ahmed Darrazi 2025-12-17 14:23:58 +01:00
parent b381624f12
commit efc7e1c2a7

View File

@ -15,6 +15,7 @@ use Exception;
class LanguageService extends MediaService class LanguageService extends MediaService
{ {
public string $cacheKey; public string $cacheKey;
protected array $groupNames = ['auth', 'button', 'common', 'dashboard', 'frontend', 'input', 'settings', 'table'];
public function __construct(Request $request) public function __construct(Request $request)
{ {
@ -28,31 +29,9 @@ class LanguageService extends MediaService
$appLangPath = storage_path('app/lang/default'); $appLangPath = storage_path('app/lang/default');
$groupNames = ['auth','button','common','dashboard','frontend','input','settings'];
$groups = []; $groups = [];
foreach ($groupNames as $groupName) { foreach ($this->groupNames as $groupName) {
$repoGroupPath1 = base_path("lang/{$data['code']}/groups/{$groupName}.php"); $groups[$groupName] = $this->loadLanguageGroup($data['code'], $groupName);
$repoGroupPath2 = base_path("lang/{$data['code']}/{$groupName}.php");
if (file_exists($repoGroupPath1)) {
$groups[$groupName] = require $repoGroupPath1;
continue;
}
if (file_exists($repoGroupPath2)) {
$file = require $repoGroupPath2;
$groups[$groupName] = [
[
'name' => ucfirst(str_replace('_', ' ', $groupName)),
'slug' => $groupName,
'properties' => $file,
],
];
continue;
}
$groups[$groupName] = require storage_path("app/lang/groups/{$groupName}.php");
} }
$languages = Language::create($data); $languages = Language::create($data);
@ -80,6 +59,65 @@ class LanguageService extends MediaService
Language::find($id)->update($data); Language::find($id)->update($data);
} }
protected function loadLanguageGroup(string $locale, string $groupName): array
{
$defaultGroupPath = storage_path("app/lang/groups/{$groupName}.php");
$defaultGroups = file_exists($defaultGroupPath) ? require $defaultGroupPath : [];
$repoGroupPath = base_path("lang/{$locale}/groups/{$groupName}.php");
if (file_exists($repoGroupPath)) {
return require $repoGroupPath;
}
$flatFilePath = base_path("lang/{$locale}/{$groupName}.php");
if (file_exists($flatFilePath)) {
$flatTranslations = require $flatFilePath;
return $this->mergeFlatTranslations($defaultGroups, $flatTranslations, $groupName);
}
return $defaultGroups;
}
protected function mergeFlatTranslations(array $defaultGroups, array $flatTranslations, string $groupName): array
{
if (empty($defaultGroups)) {
return [[
'name' => ucfirst(str_replace('_', ' ', $groupName)),
'slug' => $groupName,
'properties' => $flatTranslations,
]];
}
$groups = [];
foreach ($defaultGroups as $group) {
$properties = [];
foreach ($group['properties'] as $key => $value) {
if (array_key_exists($key, $flatTranslations)) {
$properties[$key] = $flatTranslations[$key];
unset($flatTranslations[$key]);
} else {
$properties[$key] = $value;
}
}
$groups[] = [
...$group,
'properties' => $properties,
];
}
if (! empty($flatTranslations)) {
$groups[] = [
'name' => ucfirst(str_replace('_', ' ', $groupName)) . ' Extra',
'slug' => "{$groupName}_extra",
'properties' => $flatTranslations,
];
}
return $groups;
}
function defaultLanguage($id) function defaultLanguage($id)
{ {
Language::where('is_default', true)->update(['is_default' => false]); Language::where('is_default', true)->update(['is_default' => false]);