cleanup duplicate translation ids (#3001)

This commit is contained in:
Kevin Papst
2021-12-08 01:49:44 +01:00
committed by GitHub
parent 9ec0280334
commit ec9dd08970
112 changed files with 646 additions and 1372 deletions

View File

@@ -43,6 +43,7 @@ class TranslationCommand extends Command
->setDescription('Translation adjustments')
->addOption('resname', null, InputOption::VALUE_NONE, 'Fix the resname vs. id attribute')
->addOption('duplicates', null, InputOption::VALUE_NONE, 'Find duplicate translation keys')
->addOption('delete-resname', null, InputOption::VALUE_REQUIRED, 'Deletes the translation by resname')
->addOption('extension', null, InputOption::VALUE_NONE, 'Find translation files with wrong extensions')
;
}
@@ -61,6 +62,13 @@ class TranslationCommand extends Command
'plugins' => $this->projectDirectory . Kernel::PLUGIN_DIRECTORY . '/*/Resources/translations',
];
if ($input->getOption('delete-resname')) {
$files = glob($bases['core'] . '/*.xlf');
foreach ($files as $file) {
$this->removeKey($file, $input->getOption('delete-resname'));
}
}
if ($input->getOption('resname')) {
foreach ($bases as $id => $directory) {
$files = glob($directory . '/*.xlf');
@@ -132,4 +140,29 @@ class TranslationCommand extends Command
file_put_contents($file, $xmlDocument->saveXML());
}
private function removeKey(string $file, string $key): void
{
$xml = simplexml_load_file($file);
/** @var \SimpleXMLElement $unit */
foreach ($xml->file->body->{'trans-unit'} as $unit) {
if (!isset($unit['resname'])) {
continue;
}
if ((string) $unit['resname'] === $key) {
$dom = dom_import_simplexml($unit);
$dom->parentNode->removeChild($dom);
break;
}
}
$xmlDocument = new \DOMDocument('1.0');
$xmlDocument->preserveWhiteSpace = false;
$xmlDocument->formatOutput = true;
$xmlDocument->loadXML($xml->asXML());
file_put_contents($file, $xmlDocument->saveXML());
}
}

View File

@@ -54,7 +54,7 @@ class ActivitySubscriber extends AbstractActionsSubscriber
$parameters['customers[]'] = $activity->getProject()->getCustomer()->getId();
$parameters['projects[]'] = $activity->getProject()->getId();
}
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', $parameters)]);
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', $parameters)]);
}
if ($event->hasSubmenu('filter')) {

View File

@@ -49,15 +49,15 @@ class CustomerSubscriber extends AbstractActionsSubscriber
}
if ($this->isGranted('view_project') || $this->isGranted('view_teamlead_project') || $this->isGranted('view_team_project')) {
$event->addActionToSubmenu('filter', 'project', ['title' => 'project', 'translation_domain' => 'actions', 'url' => $this->path('admin_project', ['customers[]' => $customer->getId()])]);
$event->addActionToSubmenu('filter', 'project', ['title' => 'project.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_project', ['customers[]' => $customer->getId()])]);
}
if ($this->isGranted('view_activity')) {
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $customer->getId()])]);
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $customer->getId()])]);
}
if ($this->isGranted('view_other_timesheet')) {
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $customer->getId()])]);
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $customer->getId()])]);
}
if ($event->hasSubmenu('filter')) {

View File

@@ -49,11 +49,11 @@ class ProjectSubscriber extends AbstractActionsSubscriber
}
if ($this->isGranted('view_activity')) {
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
}
if ($this->isGranted('view_other_timesheet')) {
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
}
if ($event->hasSubmenu('filter')) {

View File

@@ -47,7 +47,7 @@ class TagSubscriber extends AbstractActionsSubscriber
}
if ($this->isGranted('view_other_timesheet')) {
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['tags' => $name])]);
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['tags' => $name])]);
}
if ($event->isIndexView() && $this->isGranted('delete_tag')) {

View File

@@ -67,7 +67,7 @@ class UserSubscriber extends AbstractActionsSubscriber
}
if ($viewOther && $user->isEnabled()) {
$event->addAction('timesheet', ['url' => $this->path('admin_timesheet', ['users[]' => $user->getId()])]);
$event->addAction('timesheet', ['title' => 'timesheet.filter', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['users[]' => $user->getId()])]);
}
if ($event->isIndexView() && $this->isGranted('delete', $user)) {

View File

@@ -97,26 +97,26 @@ final class MenuSubscriber implements EventSubscriberInterface
}
if ($auth->isGranted('view_customer') || $auth->isGranted('view_teamlead_customer') || $auth->isGranted('view_team_customer')) {
$customers = new MenuItemModel('customer_admin', 'menu.admin_customer', 'admin_customer', [], $icons->icon('customer'));
$customers = new MenuItemModel('customer_admin', 'customers', 'admin_customer', [], $icons->icon('customer'));
$customers->setChildRoutes(['admin_customer_create', 'admin_customer_permissions', 'customer_details', 'admin_customer_edit', 'admin_customer_delete']);
$menu->addChild($customers);
}
if ($auth->isGranted('view_project') || $auth->isGranted('view_teamlead_project') || $auth->isGranted('view_team_project')) {
$projects = new MenuItemModel('project_admin', 'menu.admin_project', 'admin_project', [], $icons->icon('project'));
$projects = new MenuItemModel('project_admin', 'projects', 'admin_project', [], $icons->icon('project'));
$projects->setChildRoutes(['admin_project_permissions', 'admin_project_create', 'project_details', 'admin_project_edit', 'admin_project_delete']);
$menu->addChild($projects);
}
if ($auth->isGranted('view_activity') || $auth->isGranted('view_teamlead_activity') || $auth->isGranted('view_team_activity')) {
$activities = new MenuItemModel('activity_admin', 'menu.admin_activity', 'admin_activity', [], $icons->icon('activity'));
$activities = new MenuItemModel('activity_admin', 'activities', 'admin_activity', [], $icons->icon('activity'));
$activities->setChildRoutes(['admin_activity_create', 'activity_details', 'admin_activity_edit', 'admin_activity_delete']);
$menu->addChild($activities);
}
if ($auth->isGranted('view_tag')) {
$menu->addChild(
new MenuItemModel('tags', 'menu.tags', 'tags', [], 'fas fa-tags')
new MenuItemModel('tags', 'tags', 'tags', [], 'fas fa-tags')
);
}
@@ -124,7 +124,7 @@ final class MenuSubscriber implements EventSubscriberInterface
$menu = $event->getSystemMenu();
if ($auth->isGranted('view_user')) {
$users = new MenuItemModel('user_admin', 'menu.admin_user', 'admin_user', [], $icons->icon('users'));
$users = new MenuItemModel('user_admin', 'users', 'admin_user', [], $icons->icon('users'));
$users->setChildRoutes(['admin_user_create', 'admin_user_delete', 'user_profile', 'user_profile_edit', 'user_profile_password', 'user_profile_api_token', 'user_profile_roles', 'user_profile_teams', 'user_profile_preferences']);
$menu->addChild($users);
}

View File

@@ -33,10 +33,10 @@ class InitialViewType extends AbstractType
'my_profile' => 'profile.title',
'admin_timesheet' => 'menu.admin_timesheet',
'invoice' => 'menu.invoice',
'admin_user' => 'menu.admin_user',
'admin_customer' => 'menu.admin_customer',
'admin_project' => 'menu.admin_project',
'admin_activity' => 'menu.admin_activity',
'admin_user' => 'users',
'admin_customer' => 'customers',
'admin_project' => 'projects',
'admin_activity' => 'activities',
];
private const ROUTE_PERMISSION = [