forked from servergrove/TranslationEditorBundle
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGenerateCommand.php
More file actions
executable file
·79 lines (60 loc) · 1.98 KB
/
Copy pathGenerateCommand.php
File metadata and controls
executable file
·79 lines (60 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace ServerGrove\Bundle\TranslationEditorBundle\Command;
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Output\OutputInterface,
Symfony\Component\Translation\MessageCatalogue;
/**
* Command for generating new translation files
*
* @author Joris de Wit <joris.w.dewit@gmail.com>
*/
class GenerateCommand extends AbstractCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();
$this
->setName('locale:editor:generate')
->setDescription('Creates a translation file for a locale automatically')
;
}
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$dialog = $this->getHelper('dialog');
$storage = $this->getContainer()->get('server_grove_translation_editor.storage');
$localesArray = array();
$locales = $storage->findLocaleList();
foreach($locales as $locale) {
$localesArray[] = $locale->getLanguage();
}
$fromIndex = $dialog->select(
$output,
'Please select the locale to translate from',
$localesArray,
0
);
$from = $localesArray[$fromIndex];
$to = $dialog->ask(
$output,
'Please enter the locale of the language to translate to: ',
''
);
if (strlen($to) != 2) {
throw new \Exception('Locale must be 2 digits');
}
$generator = $this->getContainer()->get('server_grove_translation_editor.translation.generator');
$this->output->writeln('Please wait while your translations are translated.');
$generator->run($from, $to, true);
$this->output->writeln('Done.');
}
}