pot-ext-meta.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo';
  10. require_once "$pomo/po.php";
  11. require_once dirname( __FILE__ ) . '/makepot.php';
  12. class PotExtMeta {
  13. var $headers = array(
  14. 'Plugin Name',
  15. 'Theme Name',
  16. 'Plugin URI',
  17. 'Theme URI',
  18. 'Description',
  19. 'Author',
  20. 'Author URI',
  21. 'Tags',
  22. );
  23. function usage() {
  24. fwrite(STDERR, "Usage: php pot-ext-meta.php EXT POT\n");
  25. fwrite(STDERR, "Adds metadata from a WordPress theme or plugin file EXT to POT file\n");
  26. exit(1);
  27. }
  28. function load_from_file($ext_filename) {
  29. $source = MakePOT::get_first_lines($ext_filename);
  30. $pot = '';
  31. foreach($this->headers as $header) {
  32. $string = MakePOT::get_addon_header($header, $source);
  33. if (!$string) continue;
  34. $args = array(
  35. 'singular' => $string,
  36. 'extracted_comments' => $header.' of the plugin/theme',
  37. );
  38. $entry = new Translation_Entry($args);
  39. $pot .= "\n".PO::export_entry($entry)."\n";
  40. }
  41. return $pot;
  42. }
  43. function append( $ext_filename, $pot_filename, $headers = null ) {
  44. if ( $headers )
  45. $this->headers = (array) $headers;
  46. if ( is_dir( $ext_filename ) ) {
  47. $pot = implode('', array_map(array($this, 'load_from_file'), glob("$ext_filename/*.php")));
  48. } else {
  49. $pot = $this->load_from_file($ext_filename);
  50. }
  51. $potf = '-' == $pot_filename? STDOUT : fopen($pot_filename, 'a');
  52. if (!$potf) return false;
  53. fwrite($potf, $pot);
  54. if ('-' != $pot_filename) fclose($potf);
  55. return true;
  56. }
  57. }
  58. $included_files = get_included_files();
  59. if ($included_files[0] == __FILE__) {
  60. ini_set('display_errors', 1);
  61. $potextmeta = new PotExtMeta;
  62. if (!isset($argv[1])) {
  63. $potextmeta->usage();
  64. }
  65. $potextmeta->append( $argv[1], isset( $argv[2] ) ? $argv[2] : '-', isset( $argv[3] ) ? $argv[3] : null );
  66. }
  67. ?>