OSDN Git Service

91e3b2e17df11509a20def2b6bb5b6bccbb70dea
[ethna/ethna.git] / class / Plugin / Handle / I18n.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  I18n.php
5  *
6  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com> 
7  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
8  *  @package    Ethna
9  *  @version    $Id$
10  */
11
12 // {{{ Ethna_Plugin_Handle_I18n
13 /**
14  *  i18n handler
15  *
16  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_Plugin_Handle_I18n extends Ethna_Plugin_Handle
21 {
22     /**
23      *  generate message catalog.
24      *
25      *  @access public
26      */
27     function perform()
28     {
29         $r = $this->_getopt(
30                   array('basedir=',
31                         'locale=',
32                         'gettext',
33                   )
34              );
35         if (Ethna::isError($r)) {
36             return $r;
37         }
38         list($opt_list, $arg_list) = $r;
39
40         // basedir
41         if (isset($opt_list['basedir'])) {
42             $basedir = realpath(end($opt_list['basedir']));
43         } else {
44             $basedir = getcwd();
45         }
46
47         // locale
48         if (isset($opt_list['locale'])) {
49             $locale = end($opt_list['locale']);
50             if (!preg_match('/^[A-Za-z_]+$/', $locale)) {
51                 return Ethna::raiseError("You specified locale, but invalid : $locale", 'usage');
52             }
53         } else {
54             $locale = 'ja_JP';  //  default locale. 
55         }
56
57         //  use gettext ?
58         $use_gettext = (isset($opt_list['gettext'])) ? true : false;
59
60         //  generate message catalog.
61         $ret =& Ethna_Generator::generate('I18n', $basedir, $locale, $use_gettext, $arg_list);
62         if (Ethna::isError($ret)) {
63             printf("error occurred while generating skelton. please see also following error message(s)\n\n");
64             return $ret;
65         }
66
67         return $ret;
68     }
69
70     /**
71      *  get handler's description
72      *
73      *  @access public
74      */
75     function getDescription()
76     {
77         return <<<EOS
78 generate message catalog of project:
79     {$this->id} [-b|--basedir=dir] [-l|--locale=locale] [-g|--gettext] [extdir1] [extdir2] ...
80
81 EOS;
82     }
83
84     /**
85      *  @access public
86      */
87     function getUsage()
88     {
89         return <<<EOS
90 ethna {$this->id} [-b|--basedir=dir] [-l|--locale=locale] [-g|--gettext] [extdir1] [extdir2] ...
91
92 EOS;
93     }
94 }
95 // }}}
96
97 ?>