Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple language: language edit
#1
Hello

I want some help for my multiple language plugin, it's the part where the users should make there own language:

I have an array with in it:
-number (for the $original[x] )
-english text

Now I want to show a form that displays all the english text and a textbox to make the translation (in a table).
But how should I do this?

Alfaleader
Reply
#2
babelfish makes a button that translates a page.


babelfish.yahoo.com
Nick - TheHostingTool Staff Coordinator

[Image: standard.png]

Reply
#3
Babelfish gives bad site translations (it's for word to word translations), this plugin takes care of good translations.
Reply
#4
Ok, I decided not to use the .tpl files. But now I need help for another thing:
PHP Code:
<?php
//Check if called by script
if(THT != 1){die();}

class 
page {
    
    public 
$navtitle;
    public 
$navlist = array();
                            
    public function 
__construct() {
        
$this->navtitle "Language Sub Menu";
        
$this->navlist[] = array("Change Language""world.png""changel");
        
$this->navlist[] = array("Edit Language""lock.png""editl");
        
$this->navlist[] = array("New Language""user_red.png""newl");
    }
    
    public function 
description() {
        return 
"<strong>Language Settings</strong><br />
        Here you can change your THT language. You can edit a language or create a new one...<br />
        To get started, choose a link from the sidebar's SubMenu."
;    
    }
    
    public function 
content() {
        global 
$main;
        global 
$style;
        global 
$db;
        if(
$_POST) {
            foreach(
$main->postvar as $key => $value) {
                if(
$value == "" && !$n) { //if something is empty, do this
                    
$main->errors("Please fill in all the fields!");
                    
$n++;
                }
            } 
//stop foreach
            
            
if(!$n) { //if everything is ok, do this
                
foreach($main->postvar as $key => $value) {
                    
$db->updateConfig($key$value);
                }
                
$main->errors("Language Updated!");
                
$main->done();
            }
        }
        switch(
$main->getvar['sub']) { //look if something is clicked in the SubMenu
            
default:
                
$array['NAME'] = $db->config("name");
                
$array['URL'] = $db->config("url");
                
$values[] = array("Admin Area""admin");
                
$values[] = array("Order Form""order");
                
$values[] = array("Client Area""client");
                
$array['DROPDOWN'] = $main->dropDown("default"$values$db->config("default"));
                echo 
$style->replaceVar("tpl/pathsettings.tpl"$array);
                break;
                
            case 
"changel"#change your language
                
$folder '../includes/language';
                if (
$handle opendir($folder)) { # Open the folder
                    
while (false !== ($file readdir($handle))) { # Read the files
                            
if($file != "." && $file != ".." ) { # Check aren't these names
                            
$values[] = array($file$file);
                        }
                    }
                }
                
closedir($handle); #Close the folder
                
$array['LANGUAGE'] = $main->dropDown("language"$values$db->config("theme")); #set to LANGUAGE a dropbox with all the languages found in the /language folder
                
echo $style->replaceVar("tpl/languagesettings.tpl"$array); #replace %LANGUAGE% to a dropbox + output
                
break; 

(Just took it from settings.php)

The part i don't understand that good:
PHP Code:
if(!$n) {
                foreach(
$main->postvar as $key => $value) {
                    
$db->updateConfig($key$value);
                }
                
$main->errors("Settings Updated!");
                
$main->done();
            }
        } 
Is the if(!$n) to update the database with the new settings? But how do you can use multiple types (like language edit, language create)
PHP Code:
        switch($main->getvar['sub']) {
        
            default:
                
$array['NAME'] = $db->config("name");
                
$array['URL'] = $db->config("url");
                
$values[] = array("Admin Area""admin");
                
$values[] = array("Order Form""order");
                
$values[] = array("Client Area""client");
                
$array['DROPDOWN'] = $main->dropDown("default"$values$db->config("default"));
                echo 
$style->replaceVar("tpl/pathsettings.tpl"$array);
                break; 

And why is the default: thing for? (the default display is the description, why this default?)

PHP Code:
case "edit":
                if(isset(
$main->getvar['do'])) { 
and why is the $main->getvar['do'] for?
Thanks!
Reply
#5
Just thing $main->getvar as $_GET and $main->postvar as $_POST. Just they're SQL Cleaned.

I wouldn't use settings.php as an example, look at something like servers.
Jonny H - THT Main Developer & Founder


Reply
#6
Let me explain that !$n part
PHP Code:
if(!$n) { # Searches for $n, I don't know what it is but anyway
                
foreach($main->postvar as $key => $value) { # Foreach loop, checks $key value.
                    
$db->updateConfig($key$value); # So it updates config name $key to $value
                
}
                
$main->errors("Settings Updated!"); # Returns updated msg
                
$main->done(); # Finished. Yay!
            
}
        } 
Jimmie Lin - Community Manager & THT.Next Developer
Reply
#7
I understand now mostly everything,
(except the $n variable :p , and jimmie also doesn't know why it's for, but I'll use it without knowing why it's for :p )

Now I have this:
/admin/language.php
PHP Code:
<?php
//Check if called by script
if(THT != 1){die();}

class 
page {
    
    public 
$navtitle;
    public 
$navlist = array();
                            
    public function 
__construct() {
        
$this->navtitle "Language Sub Menu";
        
$this->navlist[] = array("Change Language""world.png""changel");
        
$this->navlist[] = array("Edit Language""lock.png""editl");
        
$this->navlist[] = array("New Language""user_red.png""newl");
    }
    
    public function 
description() {
        return 
"<strong>Language Control Center</strong><br />
        This is where you control the THT Language. You can change your THT language, edit a language or evan make your own new language<br />
        To get started, choose a link from the sidebar's SubMenu."
;    
    }
    
    public function 
content() { # Displays the page 
        
global $main;
        global 
$style;
        global 
$db;
        if(
$_POST) {
            foreach(
$main->postvar as $key => $value) {
                if(
$value == "" && !$n) {
                    
$main->errors("Please fill in all the fields!");
                    
$n++;
                }
            }
            if(!
$n) {
                foreach(
$main->postvar as $key => $value) {
                    
$db->updateConfig($key$value);
                }
                
$main->errors("Settings Updated!");
                
$main->done();
            }
        }
        
        switch(
$main->getvar['sub']) { #what has the admin clicked in the submenu?

                
default: #is it Change Language?
            
if($_POST) {
                    foreach (
$main->postvar as $key => $value ) { #get the POST variables from the form
                        
if($value == "" && !$n) { #checks if everything is filled in
                            
$main->errors("Please fill in all the fields!");
                            
$n++;
                        }
                    }
                if(!
$n) { #if everything is filled in, do this:
                
$db->updateConfig('language'$main->postvar['changel']); # So it updates config name $key to $value
                
$main->errors("Language Changed!"); # Returns updated msg
                
$main->done(); # Finished. Yay!
                
}
            }

                
#gets all the languages from the /language folder (for the output form)
                
$folder '../includes/language';
                    if (
$handle opendir($folder)) { # Open the folder
                        
while (false !== ($file readdir($handle))) { # Read the files
                                
if($file != "." && $file != ".." ) { # Check aren't these names
                                
$values[] = array($file$file);
                            }
                        }
                    }
                    
closedir($handle); #Close the folder
                    
                #output the form for changing language, this has to be outputtet always, even as the language is just changed
                
$array['LANGUAGE'] = $main->dropDown("language"$values$db->config("theme"));
                
$array['CURRENTLANGUAGE'] = $db->config('language');
                echo 
$style->replaceVar("tpl/changelanguage.tpl"$array);
                
                break;
                
            
        }
    }
}
?>
/includes/tpl/changelanguage.tpl
PHP Code:
<ERRORS>
<
form id="settings" name="settings" method="post" action="">
<
table width="100%" border="0" cellspacing="2" cellpadding="0">
  <
tr>
    <
td width="20%"><p>Current language: %CURRENTLANGUAGE%</p>
      <
p>Change Language:</p></td>
    <
td>
      %
LANGUAGE%    <a title="Choose your language." class="tooltip"><img src="<URL>themes/icons/information.png" /></a>
    </
td>
  </
tr>
  <
tr>
    <
td colspan="2" align="center"><input type="submit" name="add" id="add" value="Change Language" /></td>
  </
tr>
</
table>
</
form

The problem is that it won't update the language to the database if I choose another language. What's my mistake?
Reply
#8
The $n is defined in the previous foreach look that cycles through all the posts and check if all the fields are filled. If not n will be defined and the amount of boxes not filled will be $n.
Jonny H - THT Main Developer & Founder


Reply
#9
Thanks, now I almost finished the edit language and I have to do the new language.
Reply
#10
Do you have any updates on this? Smile
Jimmie Lin - Community Manager & THT.Next Developer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)