@@ -20,7 +20,7 @@ class MakeMoCommand extends WP_CLI_Command {
2020 * : Path to an existing PO file or a directory containing multiple PO files.
2121 *
2222 * [<destination>]
23- * : Path to the destination directory for the resulting MO files. Defaults to the source directory.
23+ * : Path to the destination file or directory for the resulting MO files. Defaults to the source directory.
2424 *
2525 * ## EXAMPLES
2626 *
@@ -30,6 +30,9 @@ class MakeMoCommand extends WP_CLI_Command {
3030 * # Create a MO file from a single PO file in a specific directory.
3131 * $ wp i18n make-mo example-plugin-de_DE.po languages
3232 *
33+ * # Create a MO file from a single PO file to a specific file destination
34+ * $ wp i18n make-mo example-plugin-de_DE.po languages/bar.mo
35+ *
3336 * @when before_wp_load
3437 *
3538 * @throws WP_CLI\ExitException
@@ -40,9 +43,19 @@ public function __invoke( $args, $assoc_args ) {
4043 WP_CLI ::error ( 'Source file or directory does not exist! ' );
4144 }
4245
43- $ destination = is_file ( $ source ) ? dirname ( $ source ) : $ source ;
46+ $ destination = is_file ( $ source ) ? dirname ( $ source ) : $ source ;
47+ $ custom_file_name = null ;
4448 if ( isset ( $ args [1 ] ) ) {
45- $ destination = $ args [1 ];
49+ $ destination = $ args [1 ];
50+ $ destionation_pathinfo = pathinfo ( $ destination );
51+ // Destination is a file, make sure source is also a file
52+ if ( ! empty ( $ destionation_pathinfo ['filename ' ] ) ) {
53+ if ( ! is_file ( $ source ) ) {
54+ WP_CLI ::error ( 'Destination file not supported when source is a directory! ' );
55+ }
56+ $ destination = $ destionation_pathinfo ['dirname ' ];
57+ $ custom_file_name = $ destionation_pathinfo ['filename ' ] . '. ' . $ destionation_pathinfo ['extension ' ];
58+ }
4659 }
4760
4861 // Two is_dir() checks in case of a race condition.
@@ -71,8 +84,12 @@ public function __invoke( $args, $assoc_args ) {
7184 continue ;
7285 }
7386
74- $ file_basename = basename ( $ file ->getFilename (), '.po ' );
75- $ destination_file = "{$ destination }/ {$ file_basename }.mo " ;
87+ $ file_basename = basename ( $ file ->getFilename (), '.po ' );
88+ $ file_name = $ file_basename . '.mo ' ;
89+ if ( $ custom_file_name ) {
90+ $ file_name = $ custom_file_name ;
91+ }
92+ $ destination_file = "{$ destination }/ {$ file_name }" ;
7693
7794 $ translations = Translations::fromPoFile ( $ file ->getPathname () );
7895 if ( ! $ translations ->toMoFile ( $ destination_file ) ) {
0 commit comments