@@ -44,16 +44,16 @@ protected function configure()
44
44
))
45
45
->setDefinition (array (
46
46
new InputArgument ('locale ' , InputArgument::REQUIRED , 'The locale ' ),
47
- new InputArgument ('bundle ' , InputArgument::REQUIRED , 'The bundle name ' ),
47
+ new InputArgument ('bundle ' , InputArgument::OPTIONAL , 'The bundle name or directory where to load the messages, defaults to app/Resources folder ' ),
48
48
new InputOption ('domain ' , null , InputOption::VALUE_OPTIONAL , 'The messages domain ' ),
49
49
new InputOption ('only-missing ' , null , InputOption::VALUE_NONE , 'Displays only missing messages ' ),
50
50
new InputOption ('only-unused ' , null , InputOption::VALUE_NONE , 'Displays only unused messages ' ),
51
51
))
52
- ->setDescription ('Displays translation messages informations ' )
52
+ ->setDescription ('Displays translation messages information ' )
53
53
->setHelp (<<<EOF
54
54
The <info>%command.name%</info> command helps finding unused or missing translation
55
55
messages and comparing them with the fallback ones by inspecting the
56
- templates and translation files of a given bundle.
56
+ templates and translation files of a given bundle or the app folder .
57
57
58
58
You can display information about bundle translations in a specific locale:
59
59
@@ -71,6 +71,10 @@ protected function configure()
71
71
72
72
<info>php %command.full_name% --only-unused en AcmeDemoBundle</info>
73
73
74
+ You can display information about app translations in a specific locale:
75
+
76
+ <info>php %command.full_name% en</info>
77
+
74
78
EOF
75
79
)
76
80
;
@@ -87,17 +91,37 @@ protected function execute(InputInterface $input, OutputInterface $output)
87
91
88
92
$ locale = $ input ->getArgument ('locale ' );
89
93
$ domain = $ input ->getOption ('domain ' );
90
- $ bundle = $ this ->getContainer ()->get ('kernel ' )->getBundle ($ input ->getArgument ('bundle ' ));
91
94
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
95
+ $ kernel = $ this ->getContainer ()->get ('kernel ' );
96
+
97
+ // Define Root Path to App folder
98
+ $ rootPath = $ kernel ->getRootDir ();
99
+
100
+ // Override with provided Bundle info
101
+ if (null !== $ input ->getArgument ('bundle ' )) {
102
+ try {
103
+ $ rootPath = $ kernel ->getBundle ($ input ->getArgument ('bundle ' ))->getPath ();
104
+ } catch (\InvalidArgumentException $ e ) {
105
+ // such a bundle does not exist, so treat the argument as path
106
+ $ rootPath = $ input ->getArgument ('bundle ' );
107
+
108
+ if (!is_dir ($ rootPath )) {
109
+ throw new \InvalidArgumentException (sprintf ('<error>"%s" is neither an enabled bundle nor a directory.</error> ' , $ rootPath ));
110
+ }
111
+ }
112
+ }
113
+
114
+ // get bundle directory
115
+ $ translationsPath = $ rootPath .'/Resources/translations ' ;
92
116
93
117
// Extract used messages
94
118
$ extractedCatalogue = new MessageCatalogue ($ locale );
95
- $ this ->getContainer ()->get ('translation.extractor ' )->extract ($ bundle -> getPath () .'/Resources/views ' , $ extractedCatalogue );
119
+ $ this ->getContainer ()->get ('translation.extractor ' )->extract ($ rootPath .'/Resources/views ' , $ extractedCatalogue );
96
120
97
121
// Load defined messages
98
122
$ currentCatalogue = new MessageCatalogue ($ locale );
99
- if (is_dir ($ bundle -> getPath (). ' /Resources/translations ' )) {
100
- $ loader ->loadMessages ($ bundle -> getPath (). ' /Resources/translations ' , $ currentCatalogue );
123
+ if (is_dir ($ translationsPath )) {
124
+ $ loader ->loadMessages ($ translationsPath , $ currentCatalogue );
101
125
}
102
126
103
127
// Merge defined and extracted messages to get all message ids
@@ -130,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
130
154
}
131
155
132
156
$ fallbackCatalogue = new MessageCatalogue ($ fallbackLocale );
133
- $ loader ->loadMessages ($ bundle -> getPath (). ' /Resources/translations ' , $ fallbackCatalogue );
157
+ $ loader ->loadMessages ($ translationsPath , $ fallbackCatalogue );
134
158
$ fallbackCatalogues [] = $ fallbackCatalogue ;
135
159
}
136
160
}
0 commit comments