@@ -35,7 +35,7 @@ protected function configure()
35
35
->setName ('translation:update ' )
36
36
->setDefinition (array (
37
37
new InputArgument ('locale ' , InputArgument::REQUIRED , 'The locale ' ),
38
- new InputArgument ('bundle ' , InputArgument::REQUIRED , 'The bundle where to load the messages ' ),
38
+ new InputArgument ('bundle ' , InputArgument::OPTIONAL , 'The bundle where to load the messages, defaults to app/Resources folder ' , null ),
39
39
new InputOption (
40
40
'prefix ' , null , InputOption::VALUE_OPTIONAL ,
41
41
'Override the default prefix ' , '__ '
@@ -64,13 +64,18 @@ protected function configure()
64
64
->setDescription ('Updates the translation file ' )
65
65
->setHelp (<<<EOF
66
66
The <info>%command.name%</info> command extract translation strings from templates
67
- of a given bundle. It can display them or merge the new ones into the translation files.
67
+ of a given bundle or the app folder . It can display them or merge the new ones into the translation files.
68
68
When new translation strings are found it can automatically add a prefix to the translation
69
69
message.
70
70
71
+ Example running against a Bundle (AcmeBundle)
71
72
<info>php %command.full_name% --dump-messages en AcmeBundle</info>
72
73
<info>php %command.full_name% --force --prefix="new_" fr AcmeBundle</info>
73
74
75
+ Example running against app messages (app/Resources folder)
76
+ <info>php %command.full_name% --dump-messages en</info>
77
+ <info>php %command.full_name% --force --prefix="new_" fr</info>
78
+
74
79
EOF
75
80
)
76
81
;
@@ -98,23 +103,33 @@ protected function execute(InputInterface $input, OutputInterface $output)
98
103
return 1 ;
99
104
}
100
105
106
+ // Define Root Path to App folder
107
+ $ rootPath = $ this ->getApplication ()->getKernel ()->getRootDir ();
108
+ $ currentName = "app folder " ;
109
+
110
+ // Override with provided Bundle info
111
+ if (null !== $ input ->getArgument ('bundle ' )) {
112
+ $ foundBundle = $ this ->getApplication ()->getKernel ()->getBundle ($ input ->getArgument ('bundle ' ));
113
+ $ rootPath = $ foundBundle ->getPath ();
114
+ $ currentName = $ foundBundle ->getName ();
115
+ }
116
+
101
117
// get bundle directory
102
- $ foundBundle = $ this ->getApplication ()->getKernel ()->getBundle ($ input ->getArgument ('bundle ' ));
103
- $ bundleTransPath = $ foundBundle ->getPath ().'/Resources/translations ' ;
104
- $ output ->writeln (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ foundBundle ->getName ()));
118
+ $ translationsPath = $ rootPath .'/Resources/translations ' ;
119
+ $ output ->writeln (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
105
120
106
121
// load any messages from templates
107
122
$ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
108
123
$ output ->writeln ('Parsing templates ' );
109
124
$ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
110
125
$ extractor ->setPrefix ($ input ->getOption ('prefix ' ));
111
- $ extractor ->extract ($ foundBundle -> getPath () .'/Resources/views/ ' , $ extractedCatalogue );
126
+ $ extractor ->extract ($ rootPath .'/Resources/views/ ' , $ extractedCatalogue );
112
127
113
128
// load any existing messages from the translation files
114
129
$ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
115
130
$ output ->writeln ('Loading translation files ' );
116
131
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
117
- $ loader ->loadMessages ($ bundleTransPath , $ currentCatalogue );
132
+ $ loader ->loadMessages ($ translationsPath , $ currentCatalogue );
118
133
119
134
// process catalogues
120
135
$ operation = $ input ->getOption ('clean ' )
@@ -150,7 +165,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
150
165
// save the files
151
166
if ($ input ->getOption ('force ' ) === true ) {
152
167
$ output ->writeln ('Writing files ' );
153
- $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ bundleTransPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
168
+ $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ translationsPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
154
169
}
155
170
}
156
171
}
0 commit comments