Author: mahono
Date: 2010-01-21 12:33:16 +0100 (Thu, 21 Jan 2010)
New Revision: 26978

Modified:
   plugins/sfSympalPlugin/trunk/data/bin/installer.php
Log:
[1.4][sfSympalPlugin][1.0] Adds support for enabling i18n during installation 
to sympal CLI project installer

Modified: plugins/sfSympalPlugin/trunk/data/bin/installer.php
===================================================================
--- plugins/sfSympalPlugin/trunk/data/bin/installer.php 2010-01-21 11:22:08 UTC 
(rev 26977)
+++ plugins/sfSympalPlugin/trunk/data/bin/installer.php 2010-01-21 11:33:16 UTC 
(rev 26978)
@@ -144,6 +144,83 @@
 $this->logSection('install', 'create an application');
 $this->runTask('generate:app', $application);
 
+// i18n
+class sfValidatorSympalCultures extends sfValidatorString
+{
+  protected function configure($options = array(), $messages = array())
+  {
+    parent::configure($options, $messages);
+
+    $this->setOption('empty_value', array());
+    $this->setOption('required', false);
+    $this->setOption('trim', true);
+
+    $this->addMessage('invalid', 'Please enter a comma separated list of 
cultures.');
+  }
+
+  public function doClean($value)
+  {
+    $parts = explode(',', $value);
+
+    $cultures = array();
+
+    foreach ($parts as $culture)
+    {
+      $culture = trim($culture);
+
+      if (!empty($culture))
+      {
+        $cultures[] = $culture;
+      }  
+    }
+
+    if (empty($cultures))
+    {
+      throw new sfValidatorError($this, 'invalid');
+    }
+
+    return $cultures;
+  }
+}
+
+$this->logBlock("
+The next input allows you to turn on internationalisation for your Sympal 
project.
+If you don't need internationalisation simply leave it blank.
+But if you want internationalisation enter a comma separated list of cultures,
+example: en,de,fr
+The first one will be configured as default culture.
+", 'COMMENT');
+
+$cultures = $this->askAndValidate("Enter a comma separated list of cultures or 
leave blank if you don't need i18n:", new sfValidatorSympalCultures(), 
array('style' => 'QUESTION_LARGE'));
+
+if (count($cultures) > 0)
+{
+  $this->logSection('i18n', 'enabling i18n in Sympal with cultures: 
'.implode(', ', $cultures));
+
+  $out = $err = null;
+  $command = sprintf(
+    '%s "%s" %s',
+    sfToolkit::getPhpCli(),
+    sfConfig::get('sf_root_dir').'/symfony',
+    'sympal:configure '.sprintf('i18n=true language_codes="[%s]"', 
implode(',', $cultures))
+  );
+  $this->logBlock($command, 'INFO');
+  $this->getFilesystem()->execute($command, $out, $err);
+
+  $this->logSection('i18n', sprintf('enabling i18n in application "%s"', 
$application));
+
+  $settingsFilename = 
sfConfig::get('sf_apps_dir').'/'.$application.'/config/settings.yml';
+  $settings = file_get_contents($settingsFilename);
+  $settings .= <<<EOF
+
+    i18n: true
+    default_culture: {$cultures[0]}
+EOF;
+
+  file_put_contents($settingsFilename, $settings);
+}
+
+// execute sympal installation
 $out = $err = null;
 $command = sprintf(
   '%s "%s" %s',

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to