|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* generate missing translation entities based on english strings |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\I18nBundle\Command; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Graviton\I18nBundle\Document\Translatable; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* generate missing translation entities based on english strings |
|
15
|
|
|
* |
|
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
18
|
|
|
* @link http://swisscom.ch |
|
19
|
|
|
*/ |
|
20
|
|
|
class LoadMissingCommand extends ContainerAwareCommand |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* base strings to translate (en) |
|
24
|
|
|
* |
|
25
|
|
|
* @var Translatable[] |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $baseStrings; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* set up command |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
6 |
|
protected function configure() |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
6 |
|
->setName('graviton:i18n:load:missing') |
|
38
|
6 |
|
->setDescription('Generate translatables for strings in en.'); |
|
39
|
6 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* run command |
|
43
|
|
|
* |
|
44
|
|
|
* @param InputInterface $input input interface |
|
45
|
|
|
* @param OutputInterface $output output interface |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
2 |
|
$this->generateTranslatables(); |
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* loop over languages |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
2 |
|
private function generateTranslatables() |
|
60
|
|
|
{ |
|
61
|
2 |
|
$container = $this->getContainer(); |
|
62
|
2 |
|
$languages = $container->get('graviton.i18n.repository.language')->findAll(); |
|
63
|
2 |
|
$this->baseStrings = $container->get('graviton.i18n.repository.translatable')->findBy(array('locale' => 'en')); |
|
64
|
|
|
|
|
65
|
2 |
|
array_walk( |
|
66
|
|
|
$languages, |
|
67
|
|
|
function ($language) { |
|
68
|
2 |
|
$this->generateForLanguage($language->getId()); |
|
69
|
2 |
|
} |
|
70
|
|
|
); |
|
71
|
2 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* generate strings for languages |
|
75
|
|
|
* |
|
76
|
|
|
* @param Language $language language |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
2 |
|
private function generateForLanguage($language) |
|
81
|
|
|
{ |
|
82
|
2 |
|
if ($language == 'en') { |
|
83
|
2 |
|
return; |
|
84
|
|
|
} |
|
85
|
2 |
|
array_walk( |
|
86
|
2 |
|
$this->baseStrings, |
|
87
|
2 |
|
function ($base) use ($language) { |
|
88
|
2 |
|
$domain = $base->getDomain(); |
|
89
|
2 |
|
$original = $base->getOriginal(); |
|
90
|
2 |
|
$id = implode('-', array($domain, $language, $original)); |
|
91
|
|
|
|
|
92
|
2 |
|
$record = new Translatable; |
|
93
|
2 |
|
$record->setId($id); |
|
94
|
2 |
|
$record->setDomain($domain); |
|
95
|
2 |
|
$record->setLocale($language); |
|
96
|
2 |
|
$record->setOriginal($original); |
|
97
|
|
|
|
|
98
|
2 |
|
$this->getContainer()->get('graviton.i18n.model.translatable')->insertRecord($record); |
|
99
|
2 |
|
} |
|
100
|
|
|
); |
|
101
|
2 |
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|