Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi Language
#1
Hello,
I'm Daniele.
I'm building a simple semi-static website that should be multilingual.
I have seen a couple of posts about multilanguage support in GetSimple, but nobody has sorted out. I've seen many great ideas and I found this one http://get-simple.info/forum/viewtopic.php?id=510 perfect to accomplish my goal. So I used the customField plugin and I modified some of the admin pages of GS in order to get the multilanguage support.

ATTENTION! I'm a web designer not a PHP developer: my code could look crappy.

Instruction:
Download and Install CustomField plugin. Create a file /data/other/customfields.xml which should be in the following format:
Code:
<channel>
  <item>
    <desc>language</desc>
    <label>Language </label>
    <type>dropdown</type>
    <option>it</option>
    <option>de</option>
    <option>fr</option>
    <option>es</option>
  </item>
</channel>

Modify plugin/customfields.php. You need to add this line:
Code:
function createTagInputs(){    
     global $tags;
     global $data_edit;
     $uri           = @$_GET['id'];
     $language      = @$_GET['language']; //Add this line
     $path = GSDATAPAGESPATH;

and replace with these others:
Code:
case "dropdown":    
     echo "<td>";
     echo "<b>".$tags[$key]['label'].":</b><br />";
     echo "<select id=\"post-".strtolower($key)."\" name=\"post-".strtolower($key)."\" class='".$class."'>";
     echo "<option value='".$data_edit->$key."'>".$data_edit->$key."</option>";
     foreach ($tags[$key]['options'] as $option) {
       echo "<option value='".$option."'>".$option."</option>";
     }
     echo "</select>";
     echo "</td>";
     break;
with:
Code:
case "dropdown":     echo "<td>";
     echo "<b>".$tags[$key]['label'].":</b><br />";
     echo "<select id=\"post-".strtolower($key)."\" name=\"post-".strtolower($key)."\" class='".$class."'>";
     if ($data_edit->$key != '' ) {
         $thelanguage = $data_edit->$key;
     } else {
         $thelanguage = $language;
     }
     foreach ($tags[$key]['options'] as $option) {
         echo "<option ";
         if (strtolower($thelanguage) == strtolower($option)) { echo " SELECTED "; }
              echo "value='".$option."'>".$option."</option>";
     }
     echo "</select>";
     echo "</td>";
     break;
Change admin/pages.php adding this line:
Code:
$id           = @$_GET['id'];
$ptype           = @$_GET['type'];
$language      = @$_GET['language']; //Add this line

Now you have to change:
Code:
$table .= '<td>'. @$dash .'<a title="'.$i18n['EDITPAGE_TITLE'].': '. cl($page['title']) .'" href="edit.php?id='. $page['url'] .'" >'. cl($page['title']) .'</a><span class="showstatus toggle" >'. $homepage . $page['menuStatus'] . $page['private'] .'</span></td>'
with

Code:
$table .= '<td>'. @$dash .'<a title="'.$i18n['EDITPAGE_TITLE'].': '. cl($page['title']) .'" href="edit.php?id='. $page['url'] .'&language=' . $language . '" >'. cl($page['title']) .'</a><span class="showstatus toggle" >'. $homepage . $page['menuStatus'] . $page['private'] .'</span></td>';

and
Code:
if (count($filenames) != 0) {      foreach ($filenames as $file) {
          if (isFile($file, $path, 'xml')) {
               $data = getXML($path .$file);
               $status = $data->menuStatus;
               //$pagesArray[$count]['title'] = $data->title;
               $pagesArray[$count]['title'] = html_entity_decode($data->title, ENT_QUOTES, 'UTF-8');
               $pagesArray[$count]['parent'] = $data->parent;
               $pagesArray[$count]['menuStatus'] = $data->menuStatus;
               $pagesArray[$count]['private'] = $data->private;
               if ($data->parent != '') {
                    $parentdata = getXML($path . $data->parent .'.xml');
                    $parentTitle = $parentdata->title;
                    $pagesArray[$count]['sort'] = $parentTitle .' '. $data->title;
               } else {
                    $pagesArray[$count]['sort'] = $data->title;
               }
               $pagesArray[$count]['url'] = $data->url;
               $pagesArray[$count]['date'] = $data->pubDate;
               $parentTitle = '';
               $count++;
          }
     }
}

to

Code:
if (count($filenames) != 0) {
     foreach ($filenames as $file) {
          if (isFile($file, $path, 'xml')) {
               $data = getXML($path .$file);
               //$status = $data->menuStatus;
               //$pagesArray[$count]['title'] = $data->title;
               if (strtolower($data->language) == strtolower($language) OR $language == '') {
                    $pagesArray[$count]['title'] = html_entity_decode($data->title, ENT_QUOTES, 'UTF-8');
                    $pagesArray[$count]['parent'] = $data->parent;
                    $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                    $pagesArray[$count]['private'] = $data->private;
                    if ($data->parent != '') {
                         $parentdata = getXML($path . $data->parent .'.xml');
                         $parentTitle = $parentdata->title;
                         $pagesArray[$count]['sort'] = $parentTitle .' '. $data->title;
                    } else {
                         $pagesArray[$count]['sort'] = $data->title;
                    }
                    $pagesArray[$count]['url'] = $data->url;
                    $pagesArray[$count]['date'] = $data->pubDate;
                    $parentTitle = '';
                    $count++;
               }
          }
     }
}
admin/edit.php. Simply add this line
Code:
// Get passed variables
$uri           = @$_GET['uri'];
$id           = @$_GET['id'];
$ptype           = @$_GET['type'];
$language      = @$_GET['language']; //Add this line
$path           = GSDATAPAGESPATH;
and replace
Code:
if ($tmpData->parent == '')
               {
                    $parents_list .= '<option '.@$sel.' value="'.$goodname.'" >'.$goodname.'</option>';
               }
with
Code:
if ($tmpData->parent == '' AND strtolower($tmpData->language) == strtolower($language))
               {
                    $parents_list .= '<option '.@$sel.' value="'.$goodname.'" >'.$goodname.'</option>';
               }
admin/template/sidebar-pages.php: Add the following lines on top of the page:
Code:
<?php
     $language      = @$_GET['language'];
     if (!isset($language))
          $thelanguage = '';
     else
          $thelanguage = '?language='.$language;
?>
then replace
Code:
<li><a href="pages.php" accesskey="p" <?php check_menu('pages');  ?>><?php echo $i18n['SIDE_VIEW_PAGES']; ?></a></li>
<li><a href="edit.php" accesskey="c" <?php if((@$_GET['id'] == "") && (get_filename_id()==='edit'))  { echo 'class="current"'; } ?>><?php echo $i18n['SIDE_CREATE_NEW']; ?></a></li>
with
Code:
<li><a href="pages.php<?php echo $thelanguage; ?>" accesskey="p" <?php check_menu('pages');  ?>><?php echo $i18n['SIDE_VIEW_PAGES'] . ' ' . strtoupper($language); ?></a></li>
     <li><a href="edit.php<?php echo $thelanguage; ?>" accesskey="c" <?php if((@$_GET['id'] == "") && (get_filename_id()==='edit'))  { echo 'class="current"'; } ?>><?php echo $i18n['SIDE_CREATE_NEW'] . ' ' . strtoupper($language); ?></a></li>
Last but not least admin/template/include-nav.php. Replace and add
Code:
<li><a class="pages" href="pages.php" accesskey="p" ><?php echo $i18n['TAB_PAGES'];?></a></li>
with
Code:
<li><a class="pages" href="pages.php?language=it" accesskey="p" ><?php echo $i18n['TAB_PAGES'].' IT';?></a></li>
     <li><a class="pages" href="pages.php?language=de" accesskey="p" ><?php echo $i18n['TAB_PAGES'].' DE';?></a></li>
     <li><a class="pages" href="pages.php?language=fr" accesskey="p" ><?php echo $i18n['TAB_PAGES'].' FR';?></a></li>
     <li><a class="pages" href="pages.php?language=es" accesskey="p" ><?php echo $i18n['TAB_PAGES'].' ES';?></a></li>

Ok and that's the admin. Now add this new function to your template in order to get the menu with the right language:

Code:
function menu_data_reloaded($id = null,$xml=false) {
        $menu_extract = '';
        global $PRETTYURLS;
        global $SITEURL;
    global $tags;
    global $lang;
    
    if ($lang == '') $lang = 'it';
        
        $path = GSDATAPAGESPATH;
        $dir_handle = @opendir($path) or die("Unable to open $path");
        $filenames = array();
        while ($filename = readdir($dir_handle)) {
            $filenames[] = $filename;
        }
        
        $count="0";
        $pagesArray = array();
        if (count($filenames) != 0) {
            foreach ($filenames as $file) {
                if ($file == "." || $file == ".." || is_dir(GSDATAPAGESPATH . $file) || $file == ".htaccess"  ) {
                    // not a page data file
                } else {
            $data = getXML(GSDATAPAGESPATH . $file);
            if (strtolower($data->language) == strtolower($lang)) {
            if ($data->private != 'Y') {
                $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                $pagesArray[$count]['menu'] = $data->menu;
                $pagesArray[$count]['parent'] = $data->parent;
                $pagesArray[$count]['title'] = $data->title;
                $pagesArray[$count]['url'] = $data->url;
                $pagesArray[$count]['private'] = $data->private;
                $pagesArray[$count]['pubDate'] = $data->pubDate;
                $pagesArray[$count]['language'] = $data->language;
                $count++;
            }
            }
                }
            }
        }
        
        $pagesSorted = subval_sort($pagesArray,'menuOrder');
        if (count($pagesSorted) != 0) {
            $count = 0;
            if (!$xml){
            foreach ($pagesSorted as $page) {
                    $text = (string)$page['menu'];
                    $pri = (string)$page['menuOrder'];
                    $parent = (string)$page['parent'];
                    $title = (string)$page['title'];
                    $slug = (string)$page['url'];
                    $menuStatus = (string)$page['menuStatus'];
                    $private = (string)$page['private'];
            $pubDate = (string)$page['pubDate'];
            $language = (string)$page['language'];
                    
                    $url = find_url($slug,$parent);
                    
                    $specific = array("slug"=>$slug,"url"=>$url,"parent_slug"=>$parent,"title"=>$title,"menu_priority"=>$pri,"menu_text"=>$text,"menu_status"=>$menuStatus,"private"=>$private,"pub_date"=>$pubDate,"language"=>$language);
                    
                    if ($id == $slug) {
                        return $specific;
                        exit;
                    } else {
                        $menu_extract[] = $specific;
                    }
                
            }
            return $menu_extract;
            } else {
            $xml = '<?xml version="1.0" encoding="UTF-8"?><channel>';    
            foreach ($pagesSorted as $page) {
                    $text = $page['menu'];
                    $pri = $page['menuOrder'];
                    $parent = $page['parent'];
                    $title = $page['title'];
                    $slug = $page['url'];
                    $pubDate = $page['pubDate'];
                    $menuStatus = $page['menuStatus'];
                    $private = $page['private'];
            $language = $page['language'];
                      
                    $url = find_url($slug,$parent);
                    
                    $xml.="<item>";
                    $xml.="<slug><![CDATA[".$slug."]]></slug>";
                    $xml.="<pubDate><![CDATA[".$pubDate."]]></pubDate>";
                    $xml.="<url><![CDATA[".$url."]]></url>";
                    $xml.="<parent><![CDATA[".$parent."]]></parent>";
                    $xml.="<title><![CDATA[".$title."]]></title>";
                    $xml.="<menuOrder><![CDATA[".$pri."]]></menuOrder>";
                    $xml.="<menu><![CDATA[".$text."]]></menu>";
                    $xml.="<menuStatus><![CDATA[".$menuStatus."]]></menuStatus>";
                    $xml.="<private><![CDATA[".$private."]]></private>";
            $xml.="<language><![CDATA[".$language."]]></language>";
                    $xml.="</item>";
                    
            }
            $xml.="</channel>";
            return $xml;
            }
        }
        
        closedir($dir_handle);
    }

To test all your work simply insert these lines in your template:

Code:
<?php global $lang; $lang = 'de'; print_r(menu_data_reloaded()); ?>

Of course, you need to create the pages!



If you don't want to modify all these files, I attached them to the post.

Thank You, I love GS
Reply


Messages In This Thread
Multi Language - by daniele.polencic - 2010-04-03, 08:03:33
Multi Language - by Zegnåt - 2010-04-03, 16:56:44
Multi Language - by prince15 - 2010-04-23, 18:15:51
Multi Language - by weblogic - 2010-06-01, 08:10:01
Multi Language - by zerophot1 - 2010-07-21, 05:05:25
Multi Language - by karol - 2010-07-22, 18:18:14
Multi Language - by agro - 2010-12-13, 05:49:21
Multi Language - by mogilka - 2010-12-16, 04:08:27
Multi Language - by mvlcek - 2011-01-19, 02:52:06



Users browsing this thread: 1 Guest(s)