@@ -38,6 +38,9 @@ class MakeJsonCommand extends WP_CLI_Command {
3838 * [<destination>]
3939 * : Path to the destination directory for the resulting JSON files. Defaults to the source directory.
4040 *
41+ * [--domain=<domain>]
42+ * : Text domain to use for the JSON file name. Overrides the default one extracted from the PO file.
43+ *
4144 * [--purge]
4245 * : Whether to purge the strings that were extracted from the original source file. Defaults to true, use `--no-purge` to skip the removal.
4346 *
@@ -78,6 +81,7 @@ public function __invoke( $args, $assoc_args ) {
7881 $ purge = Utils \get_flag_value ( $ assoc_args , 'purge ' , true );
7982 $ update_mo_files = Utils \get_flag_value ( $ assoc_args , 'update-mo-files ' , true );
8083 $ map_paths = Utils \get_flag_value ( $ assoc_args , 'use-map ' , false );
84+ $ domain = Utils \get_flag_value ( $ assoc_args , 'domain ' , '' );
8185
8286 if ( Utils \get_flag_value ( $ assoc_args , 'pretty-print ' , false ) ) {
8387 $ this ->json_options |= JSON_PRETTY_PRINT ;
@@ -115,7 +119,7 @@ public function __invoke( $args, $assoc_args ) {
115119 /** @var DirectoryIterator $file */
116120 foreach ( $ files as $ file ) {
117121 if ( $ file ->isFile () && $ file ->isReadable () && 'po ' === $ file ->getExtension () ) {
118- $ result = $ this ->make_json ( $ file ->getRealPath (), $ destination , $ map );
122+ $ result = $ this ->make_json ( $ file ->getRealPath (), $ destination , $ map, $ domain );
119123 $ result_count += count ( $ result );
120124
121125 if ( $ purge ) {
@@ -222,10 +226,11 @@ static function ( $value ) {
222226 *
223227 * @param string $source_file Path to the source file.
224228 * @param string $destination Path to the destination directory.
225- * @param array|null $map Source to build file mapping.
229+ * @param array|null $map Source to build file mapping.
230+ * @param string $domain Override text domain to use.
226231 * @return array List of created JSON files.
227232 */
228- protected function make_json ( $ source_file , $ destination , $ map ) {
233+ protected function make_json ( $ source_file , $ destination , $ map, $ domain ) {
229234 /** @var Translations[] $mapping */
230235 $ mapping = [];
231236 $ translations = new Translations ();
@@ -235,7 +240,7 @@ protected function make_json( $source_file, $destination, $map ) {
235240
236241 $ base_file_name = basename ( $ source_file , '.po ' );
237242
238- $ domain = $ translations ->getDomain ();
243+ $ domain = ( ! empty ( $ domain ) ) ? $ domain : $ translations ->getDomain ();
239244
240245 if ( $ domain && 0 !== strpos ( $ base_file_name , $ domain ) ) {
241246 $ base_file_name = "{$ domain }- {$ base_file_name }" ;
0 commit comments