修复翻译BUG
This commit is contained in:
@@ -251,10 +251,11 @@ class Rule extends Backend
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$toEnglish = !$this->shouldForceMenuTitleZh($request) && $this->shouldTranslateMenuToEnglish();
|
||||
foreach ($rules as $idx => $rule) {
|
||||
$title = $rule['title'] ?? '';
|
||||
if (is_string($title) && $title !== '') {
|
||||
$rules[$idx]['title'] = $this->menuTitleToZh($title);
|
||||
$rules[$idx]['title'] = $toEnglish ? $this->menuTitleToEn($title) : $this->menuTitleToZh($title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +273,30 @@ class Rule extends Backend
|
||||
return isset($zhMap[$title]) && is_string($zhMap[$title]) ? $zhMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function menuTitleToEn(string $title): string
|
||||
{
|
||||
static $enMap = null;
|
||||
if (!is_array($enMap)) {
|
||||
$mapFile = app_path() . '/common/lang/en/admin_rule_title.php';
|
||||
$loaded = is_file($mapFile) ? include $mapFile : [];
|
||||
$enMap = is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
return isset($enMap[$title]) && is_string($enMap[$title]) ? $enMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function shouldTranslateMenuToEnglish(): bool
|
||||
{
|
||||
$lang = function_exists('locale') ? locale() : '';
|
||||
$normalized = is_string($lang) ? strtolower(str_replace('_', '-', trim($lang))) : '';
|
||||
return str_starts_with($normalized, 'en');
|
||||
}
|
||||
|
||||
private function shouldForceMenuTitleZh(Request $request): bool
|
||||
{
|
||||
$flag = $request->get('force_menu_zh') ?? $request->post('force_menu_zh');
|
||||
return in_array($flag, [1, '1', true, 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
private function autoAssignPermission(int $id, int $pid): void
|
||||
{
|
||||
$groups = AdminGroup::where('rules', '<>', '*')->select();
|
||||
|
||||
Reference in New Issue
Block a user