1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Console application, which adds metadata strings from |
4
|
|
|
* a WordPress extension to a POT file |
5
|
|
|
* |
6
|
|
|
* @package wordpress-i18n |
7
|
|
|
* @subpackage tools |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
11
|
|
|
require_once "$pomo/po.php"; |
12
|
|
|
require_once dirname( __FILE__ ) . '/makepot.php'; |
13
|
|
|
|
14
|
|
|
class PotExtMeta { |
15
|
|
|
|
16
|
|
|
var $headers = array( |
17
|
|
|
'Plugin Name', |
18
|
|
|
'Theme Name', |
19
|
|
|
'Plugin URI', |
20
|
|
|
'Theme URI', |
21
|
|
|
'Description', |
22
|
|
|
'Author', |
23
|
|
|
'Author URI', |
24
|
|
|
'Tags', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
function usage() { |
29
|
|
|
fwrite(STDERR, "Usage: php pot-ext-meta.php EXT POT\n"); |
30
|
|
|
fwrite(STDERR, "Adds metadata from a WordPress theme or plugin file EXT to POT file\n"); |
31
|
|
|
exit(1); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function load_from_file($ext_filename) { |
35
|
|
|
$makepot = new MakePOT; |
36
|
|
|
$source = $makepot->get_first_lines($ext_filename); |
37
|
|
|
$pot = ''; |
38
|
|
|
$po = new PO; |
39
|
|
|
foreach($this->headers as $header) { |
40
|
|
|
$string = $makepot->get_addon_header($header, $source); |
41
|
|
|
if (!$string) continue; |
|
|
|
|
42
|
|
|
$args = array( |
43
|
|
|
'singular' => $string, |
44
|
|
|
'extracted_comments' => $header.' of the plugin/theme', |
45
|
|
|
); |
46
|
|
|
$entry = new Translation_Entry($args); |
47
|
|
|
$pot .= "\n".$po->export_entry($entry)."\n"; |
48
|
|
|
} |
49
|
|
|
return $pot; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function append( $ext_filename, $pot_filename, $headers = null ) { |
53
|
|
|
if ( $headers ) |
54
|
|
|
$this->headers = (array) $headers; |
55
|
|
|
if ( is_dir( $ext_filename ) ) { |
56
|
|
|
$pot = implode('', array_map(array($this, 'load_from_file'), glob("$ext_filename/*.php"))); |
57
|
|
|
} else { |
58
|
|
|
$pot = $this->load_from_file($ext_filename); |
59
|
|
|
} |
60
|
|
|
$potf = '-' == $pot_filename? STDOUT : fopen($pot_filename, 'a'); |
61
|
|
|
if (!$potf) return false; |
62
|
|
|
fwrite($potf, $pot); |
63
|
|
|
if ('-' != $pot_filename) fclose($potf); |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$included_files = get_included_files(); |
69
|
|
|
if ($included_files[0] == __FILE__) { |
70
|
|
|
ini_set('display_errors', 1); |
71
|
|
|
$potextmeta = new PotExtMeta; |
72
|
|
|
if (!isset($argv[1])) { |
73
|
|
|
$potextmeta->usage(); |
74
|
|
|
} |
75
|
|
|
$potextmeta->append( $argv[1], isset( $argv[2] ) ? $argv[2] : '-', isset( $argv[3] ) ? $argv[3] : null ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
?> |
|
|
|
|
79
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.