| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 class GP_CLI { 4 5 var $short_options = ''; 6 var $program_name = ''; 7 var $usage = ''; 8 9 function __construct() { 10 global $argv; 11 if ( gp_array_get( $_SERVER, 'HTTP_HOST' ) ) { 12 die('CLI only!'); 13 } 14 if ( !defined( 'STDERR' ) ) { 15 define( 'STDERR', fopen( 'php://stderr', 'w' ) ); 16 } 17 18 $this->program_name = array_shift( $argv ); 19 $this->options = getopt( $this->short_options ); 20 $this->args = $argv; 21 } 22 23 function usage() { 24 $this->error( 'php '.$this->program_name.' '.$this->usage ); 25 } 26 27 function to_stderr( $text, $no_new_line = false ) { 28 $text .= ($no_new_line? '' : "\n"); 29 fwrite( STDERR, $text ); 30 } 31 32 function error( $message, $exit_code = 1 ) { 33 $this->to_stderr( $message ); 34 exit( $exit_code ); 35 } 36 } 37 38 class GP_Translation_Set_Script extends GP_CLI { 39 40 var $short_options = 'p:l:t:'; 41 42 var $usage = "-p <project-path> -l <locale> [-t <translation-set-slug>]"; 43 44 function run() { 45 if ( !isset( $this->options['l'] ) || !isset( $this->options['p'] ) ) { 46 $this->usage(); 47 } 48 $this->project = GP::$project->by_path( $this->options['p'] ); 49 if ( !$this->project ) $this->error( __('Project not found!') ); 50 51 $this->locale = GP_Locales::by_slug( $this->options['l'] ); 52 if ( !$this->locale ) $this->error( __('Locale not found!') ); 53 54 $this->options['t'] = gp_array_get( $this->options, 't', 'default' ); 55 56 $this->translation_set = GP::$translation_set->by_project_id_slug_and_locale( $this->project->id, $this->options['t'], $this->locale->slug ); 57 if ( !$this->translation_set ) $this->error( __('Translation set not found!') ); 58 59 $this->action_on_translation_set( $this->translation_set ); 60 } 61 62 function action_on_translation_set( $translation_set ) { 63 // define this function in a subclass 64 } 65 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |