Patch - Choose language upon C5 installation

Permalink
Hi!

This could interest you.

controllers/install.phphttp://pastebin.com/NUWmPK6B

single_pages/install.phphttp://pastebin.com/dtdQcN7r

Yeah I know a patch file would be nicer, but I don't have netbeans installed atm.

This basically gives you a dropdown of the installed languages upon a c5 install and set the chosen language as active language in your site.php

Fernandos
 
Fernandos replied on at Permalink Reply
Fernandos
Here's a cut of my additions:
Single Page:
<?php
   $folder = "./languages";
    if (is_dir($folder)){
        $contents = scandir($folder);
        $bad = array(".", "..", ".DS_Store", "_notes", "Thumbs.db");
        $files = array_diff($contents, $bad);
      array_push($files, 'en_US');
    }
   ?>   
   <label for="LOCALE"><?php echo t('Language')?></label><br/>
   <?php
   echo '<select name="LOCALE">';
   foreach($files as $language) {
      echo '<option value='.$language.'>'.$language.'</option>';
   }



Controller line ~987:
$configuration .= "define('LOCALE', '" . addslashes($_POST['LOCALE']) . "');\n";
andrew replied on at Permalink Reply
andrew
Nice. We'll take a look at including this. We've got some thoughts about including multilingual installation in concrete5 but this looks like it'd get the job done quickly and nicely.
okhayat replied on at Permalink Reply
okhayat
This would be great.
Thank you for bringing this up!
Fernandos replied on at Permalink Reply
Fernandos
thx :)
I'm happy to have helped you.
Fernandos replied on at Permalink Reply
Fernandos
I added a screenshot!
And a nice enhancement.

http://image-upload.de/image/Rw7Fz8/c991b150bf.png...

<?php
   $folder = "./".DIRNAME_LANGUAGES;
   if (is_dir($folder)){
      $contents = scandir($folder);
      $bad = array(".", "..", ".DS_Store", "_notes", "thumbs.db", "Thumbs.db");
      $files = array_diff($contents, $bad);
     array_push($files, 'en_US');
   }
   ?>   
   <label for="LOCALE"><?php echo t('Language')?></label><br/>
   <?php
   echo '<select name="LOCALE">';
   foreach($files as $language) {
      if($language == 'da_DK') $language = 'Dansk';
      if($language == 'de_DE') $language = 'Deutsch';
Tao replied on at Permalink Reply
Tao
Good solution.
I will propose this to the next Japanese version.

Thank you.
Fernandos replied on at Permalink Reply
Fernandos
:) Thanks!

There's a little you can enhance on it though. I've added an empty <option> on my install, so that Dansk isn't the default.

Also installing without selecting a language results in an error, because setting LOCALE to "" won't work. That's why it would be better to put in validation and exception handling.

It's up to you, but you could put in a "smart default" for the dropdown if you want too. I'm specifically talking about browser_language detection code.

Have a nice Weekend!