Skip to content

Commit 8754ed5

Browse files
committed
Backport PR #123
1 parent daac81c commit 8754ed5

19 files changed

+1633
-75
lines changed

Command/AutoClosingCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
4949
$translator = $this->getContainer()->get('translator');
5050
$translator->setLocale($locale);
5151

52+
$translationDomain = $this->getContainer()->getParameter('hackzilla_ticket.translation_domain');
53+
5254
$username = $input->getArgument('username');
5355

5456
$resolved_tickets = $ticketRepository->getResolvedTicketOlderThan($input->getOption('age'));
5557

5658
foreach ($resolved_tickets as $ticket) {
5759
$message = $ticket_manager->createMessage()
5860
->setMessage(
59-
$translator->trans('MESSAGE_STATUS_CHANGED', ['%status%' => $translator->trans('STATUS_CLOSED')])
61+
$translator->trans('MESSAGE_STATUS_CHANGED', ['%status%' => $translator->trans('STATUS_CLOSED', [], $translationDomain)], $translationDomain)
6062
)
6163
->setStatus(TicketMessage::STATUS_CLOSED)
6264
->setPriority($ticket->getPriority())

Controller/TicketAttachmentController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public function downloadAction($ticketMessageId)
2525
$ticketMessage = $ticketManager->getMessageById($ticketMessageId);
2626

2727
if (!$ticketMessage || !$ticketMessage instanceof TicketMessageWithAttachment) {
28-
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
28+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
29+
30+
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
2931
}
3032

3133
// check permissions

Controller/TicketController.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public function indexAction(Request $request)
3030
$userManager = $this->getUserManager();
3131
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
3232

33-
$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN'));
33+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
34+
35+
$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN', [], $translationDomain));
3436
$ticketPriority = $request->get('priority', null);
3537

3638
$query = $ticketManager->getTicketListQuery(
@@ -48,9 +50,10 @@ public function indexAction(Request $request)
4850
return $this->render(
4951
$this->container->getParameter('hackzilla_ticket.templates')['index'],
5052
[
51-
'pagination' => $pagination,
52-
'ticketState' => $ticketState,
53-
'ticketPriority' => $ticketPriority,
53+
'pagination' => $pagination,
54+
'ticketState' => $ticketState,
55+
'ticketPriority' => $ticketPriority,
56+
'translationDomain' => $translationDomain,
5457
]
5558
);
5659
}
@@ -81,11 +84,14 @@ public function createAction(Request $request)
8184
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
8285
}
8386

87+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
88+
8489
return $this->render(
8590
$this->container->getParameter('hackzilla_ticket.templates')['new'],
8691
[
87-
'entity' => $ticket,
88-
'form' => $form->createView(),
92+
'entity' => $ticket,
93+
'form' => $form->createView(),
94+
'translationDomain' => $translationDomain,
8995
]
9096
);
9197
}
@@ -100,11 +106,14 @@ public function newAction()
100106

101107
$form = $this->createForm(TicketType::class, $entity);
102108

109+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
110+
103111
return $this->render(
104112
$this->container->getParameter('hackzilla_ticket.templates')['new'],
105113
[
106-
'entity' => $entity,
107-
'form' => $form->createView(),
114+
'entity' => $entity,
115+
'form' => $form->createView(),
116+
'translationDomain' => $translationDomain,
108117
]
109118
);
110119
}
@@ -128,7 +137,9 @@ public function showAction($ticketId)
128137
$currentUser = $this->getUserManager()->getCurrentUser();
129138
$this->getUserManager()->hasPermission($currentUser, $ticket);
130139

131-
$data = ['ticket' => $ticket];
140+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
141+
142+
$data = ['ticket' => $ticket, 'translationDomain' => $translationDomain];
132143

133144
$message = $ticketManager->createMessage($ticket);
134145

@@ -156,8 +167,10 @@ public function replyAction(Request $request, $ticketId)
156167
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
157168
$ticket = $ticketManager->getTicketById($ticketId);
158169

170+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
171+
159172
if (!$ticket) {
160-
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
173+
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
161174
}
162175

163176
$user = $this->getUserManager()->getCurrentUser();
@@ -176,7 +189,7 @@ public function replyAction(Request $request, $ticketId)
176189
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
177190
}
178191

179-
$data = ['ticket' => $ticket, 'form' => $form->createView()];
192+
$data = ['ticket' => $ticket, 'form' => $form->createView(), 'translationDomain' => $translationDomain];
180193

181194
if ($user && $this->get('hackzilla_ticket.user_manager')->hasRole($user, TicketRole::ADMIN)) {
182195
$data['delete_form'] = $this->createDeleteForm($ticket->getId())->createView();
@@ -212,7 +225,9 @@ public function deleteAction(Request $request, $ticketId)
212225
$ticket = $ticketManager->getTicketById($ticketId);
213226

214227
if (!$ticket) {
215-
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
228+
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
229+
230+
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
216231
}
217232

218233
$ticketManager->deleteTicket($ticket);
@@ -264,8 +279,6 @@ private function createMessageForm(TicketMessageInterface $message)
264279
*/
265280
private function getUserManager()
266281
{
267-
$userManager = $this->get('hackzilla_ticket.user_manager');
268-
269-
return $userManager;
282+
return $this->get('hackzilla_ticket.user_manager');
270283
}
271284
}

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function getConfigTreeBuilder()
2727

2828
$rootNode
2929
->children()
30+
->enumNode('translation_domain')
31+
->values(['HackzillaTicketBundle', 'messages'])
32+
->defaultValue('messages')
33+
->end()
3034
->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
3135
->scalarNode('ticket_class')->cannotBeEmpty()->defaultValue('Hackzilla\Bundle\TicketBundle\Entity\Ticket')->end()
3236
->scalarNode('message_class')->cannotBeEmpty()->defaultValue('Hackzilla\Bundle\TicketBundle\Entity\TicketMessage')->end()

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,30 @@ public function load(array $configs, ContainerBuilder $container)
3737
if (!isset($bundles['VichUploaderBundle'])) {
3838
$container->removeDefinition('hackzilla_ticket.file_upload_subscriber');
3939
}
40+
41+
$this->setTranslationDomain($config, $container);
4042
}
4143

4244
public static function bundleDirectory()
4345
{
4446
return realpath(__DIR__.'/..');
4547
}
48+
49+
private function setTranslationDomain(array $config, ContainerBuilder $container)
50+
{
51+
$translationDomain = $config['translation_domain'];
52+
53+
if ('HackzillaTicketBundle' !== $translationDomain) {
54+
@trigger_error(
55+
'Omitting the option "hackzilla_ticket.translation_domain" or using other value than "HackzillaTicketBundle" is deprecated since hackzilla/ticket-bundle 3.3.'
56+
.' This option will be removed in version 4.0 and the only supported translation domain will be "HackzillaTicketBundle".',
57+
E_USER_DEPRECATED
58+
);
59+
}
60+
61+
$container->setParameter('hackzilla_ticket.translation_domain', $translationDomain);
62+
63+
$definition = $container->getDefinition('hackzilla_ticket.ticket_manager');
64+
$definition->addMethodCall('setTranslationDomain', [$translationDomain]);
65+
}
4666
}

Manager/TicketManager.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class TicketManager implements TicketManagerInterface
1313
{
1414
private $translator;
1515

16+
/**
17+
* NEXT_MAJOR: Remove this property and replace its usages with "HackzillaTicketBundle".
18+
*
19+
* @var string
20+
*/
21+
private $translationDomain = 'messages';
22+
1623
private $objectManager;
1724

1825
private $ticketRepository;
@@ -61,6 +68,20 @@ public function setTranslator(TranslatorInterface $translator)
6168
return $this;
6269
}
6370

71+
/**
72+
* NEXT_MAJOR: Remove this method.
73+
*
74+
* @param string $translationDomain
75+
*
76+
* @return $this
77+
*/
78+
public function setTranslationDomain($translationDomain)
79+
{
80+
$this->translationDomain = $translationDomain;
81+
82+
return $this;
83+
}
84+
6485
/**
6586
* Create a new instance of Ticket entity.
6687
*
@@ -279,7 +300,7 @@ public function getTicketStatus($statusStr)
279300
$statuses = [];
280301

281302
foreach (TicketMessageInterface::STATUSES as $id => $value) {
282-
$statuses[$id] = $this->translator->trans($value);
303+
$statuses[$id] = $this->translator->trans($value, [], $this->translationDomain);
283304
}
284305
}
285306

@@ -301,7 +322,7 @@ public function getTicketPriority($priorityStr)
301322
$priorities = [];
302323

303324
foreach (TicketMessageInterface::PRIORITIES as $id => $value) {
304-
$priorities[$id] = $this->translator->trans($value);
325+
$priorities[$id] = $this->translator->trans($value, [], $this->translationDomain);
305326
}
306327
}
307328

0 commit comments

Comments
 (0)