@@ -20,7 +20,7 @@ class MakeMoCommand extends WP_CLI_Command {
20
20
* : Path to an existing PO file or a directory containing multiple PO files.
21
21
*
22
22
* [<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.
24
24
*
25
25
* ## EXAMPLES
26
26
*
@@ -30,6 +30,9 @@ class MakeMoCommand extends WP_CLI_Command {
30
30
* # Create a MO file from a single PO file in a specific directory.
31
31
* $ wp i18n make-mo example-plugin-de_DE.po languages
32
32
*
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
+ *
33
36
* @when before_wp_load
34
37
*
35
38
* @throws WP_CLI\ExitException
@@ -40,9 +43,19 @@ public function __invoke( $args, $assoc_args ) {
40
43
WP_CLI ::error ( 'Source file or directory does not exist! ' );
41
44
}
42
45
43
- $ destination = is_file ( $ source ) ? dirname ( $ source ) : $ source ;
46
+ $ destination = is_file ( $ source ) ? dirname ( $ source ) : $ source ;
47
+ $ custom_file_name = null ;
44
48
if ( isset ( $ args [1 ] ) ) {
45
- $ destination = $ args [1 ];
49
+ $ destination = $ args [1 ];
50
+ $ destination_pathinfo = pathinfo ( $ destination );
51
+ // Destination is a file, make sure source is also a file
52
+ if ( ! empty ( $ destination_pathinfo ['filename ' ] ) && ! empty ( $ destination_pathinfo ['extension ' ] ) ) {
53
+ if ( ! is_file ( $ source ) ) {
54
+ WP_CLI ::error ( 'Destination file not supported when source is a directory! ' );
55
+ }
56
+ $ destination = $ destination_pathinfo ['dirname ' ];
57
+ $ custom_file_name = $ destination_pathinfo ['filename ' ] . '. ' . $ destination_pathinfo ['extension ' ];
58
+ }
46
59
}
47
60
48
61
// Two is_dir() checks in case of a race condition.
@@ -71,8 +84,12 @@ public function __invoke( $args, $assoc_args ) {
71
84
continue ;
72
85
}
73
86
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 }" ;
76
93
77
94
$ translations = Translations::fromPoFile ( $ file ->getPathname () );
78
95
if ( ! $ translations ->toMoFile ( $ destination_file ) ) {
0 commit comments