OSDN Git Service

- added locale option to "ethna add-project command".
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Wed, 21 May 2008 23:37:02 +0000 (23:37 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Wed, 21 May 2008 23:37:02 +0000 (23:37 +0000)
class/Plugin/Generator/Ethna_Plugin_Generator_Project.php
class/Plugin/Handle/Ethna_Plugin_Handle_AddProject.php

index 6e94c88..816399c 100644 (file)
@@ -28,9 +28,11 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
      *  @param  string  $skeldir    スケルトンディレクトリ。これが指定されると、そこにある
      *                              ファイルが優先される。また、ETHNA_HOME/skel にないもの
      *                              も追加してコピーする 
-     *  @return bool     true:成功  Ethna_Error:失敗
+     *  @param  string  $locale     ロケール名
+     *                              (ロケール名は、ll_cc の形式。ll = 言語コード cc = 国コード)
+     *  @return bool    true:成功   Ethna_Error:失敗
      */
-    function generate($id, $basedir, $skeldir)
+    function generate($id, $basedir, $skeldir, $locale)
     {
         $dir_list = array(
             array("app", 0755),
@@ -47,13 +49,13 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
             array("etc", 0755),
             array("lib", 0755),
             array("locale", 0755),
-            array("locale/ja", 0755),
-            array("locale/ja/LC_MESSAGES", 0755),
+            array("locale/$locale", 0755),
+            array("locale/$locale/LC_MESSAGES", 0755),
             array("log", 0777),
             array("schema", 0755),
             array("skel", 0755),
             array("template", 0755),
-            array("template/ja", 0755),
+            array("template/$locale", 0755),
             array("tmp", 0777),
             array("www", 0755),
             array("www/css", 0755),
@@ -122,7 +124,13 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
         $default_macro = $macro;
         $macro = array_merge($macro, $user_macro);
 
+        //  select locale file.
+        $locale_file = (file_exists(ETHNA_BASE . "/skel/locale/$locale/ethna_sysmsg.ini"))
+                     ? "locale/$locale/ethna_sysmsg.ini"
+                     : 'locale/ethna_sysmsg.default.ini';
+
         $realfile_maps = array(
+            $locale_file    => "$basedir/locale/$locale/LC_MESSAGES/ethna_sysmsg.ini",
             "www.index.php" => "$basedir/www/index.php",
             "www.info.php"  => "$basedir/www/info.php",
             "www.unittest.php" => "$basedir/www/unittest.php",
@@ -152,7 +160,7 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
             "skel.view.php" => sprintf("$basedir/skel/skel.view.php"),
             "skel.template.tpl" => sprintf("$basedir/skel/skel.template.tpl"),
             "skel.view_test.php" => sprintf("$basedir/skel/skel.view_test.php"),
-            "template.index.tpl" => sprintf("$basedir/template/ja/index.tpl"),
+            "template.index.tpl" => sprintf("$basedir/template/$locale/index.tpl"),
         );
 
         //    also copy user defined skel file.
index 28e4a66..9a2fbc1 100644 (file)
@@ -26,7 +26,7 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
      */
     function perform()
     {
-        $r = $this->_getopt(array('basedir=', 'skeldir='));
+        $r = $this->_getopt(array('basedir=', 'skeldir=', 'locale='));
         if (Ethna::isError($r)) {
             return $r;
         }
@@ -60,7 +60,17 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
             $skeldir = null;
         }
 
-        $r = Ethna_Generator::generate('Project', null, $app_id, $basedir, $skeldir);
+        // locale
+        if (isset($opt_list['locale'])) {
+            $locale = end($opt_list['locale']);
+            if (!preg_match('/^[A-Za-z_]+$/', $locale)) {
+                return Ethna::raiseError("You specified locale, but invalid : $locale", 'usage');
+            }
+        } else {
+            $locale = 'ja_JP';  //  default locale. 
+        }
+
+        $r = Ethna_Generator::generate('Project', null, $app_id, $basedir, $skeldir, $locale);
         if (Ethna::isError($r)) {
             printf("error occurred while generating skelton. please see also error messages given above\n\n");
             return $r;
@@ -79,7 +89,7 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
     {
         return <<<EOS
 add new project:
-    {$this->id} [-b|--basedir=dir] [-s|--skeldir] [project-id]
+    {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [project-id]
 
 EOS;
     }
@@ -92,7 +102,7 @@ EOS;
     function getUsage()
     {
         return <<<EOS
-ethna {$this->id} [-b|--basedir=dir] [-s|--skeldir] [project-id]
+ethna {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [project-id]
 EOS;
     }
 }