Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Language support
#11
I did the translation system with the replacements in the output.
I used str_replace() and not ereg_replace() because ereg_replace can't handle HTML and this has to be because otherwise the error like I said in post 5 happens. I have not coded a system to choose language in THT, that still has to happen.

This is what I already have:
includes/output.php
PHP Code:
<?
//include the language files
include ('language.php');
$language = new lang();

#Sort the errors
if($_SESSION['ecount'] == 1) {
    
$_SESSION['ecount'] = 0;
    
$_SESSION['errors'] = 0;
}
else {
    
$_SESSION['ecount'] = 1;
}
$data ob_get_contents(); # Get all the HTML created by the script
ob_end_clean(); # Erase that data

echo $language->translate($style->prepare($data)); # Prepare, translate and output it
?>

includes/language.php
PHP Code:
<?
class lang {

public function 
translate($output) {

$original = array();
$replacement = array();

//language files start 
$original[0] = 'English text';
$original[1] = '<td>Client Area</td>';
$replacement[0] = 'translated test';
$replacement[1] = '<td>Client Area translated</td>';


//replaces the english output by the foreign language
return str_replace($original$replacement$output);
?>

It's quite simple, but the translation is the most work! (I'll translate it into Dutch)
Reply
#12
Very nicely done, exactly how I meant.
I would use a different data structure though. Use:
PHP Code:
$variables[0] = array("Client Area""El Cliento Areo"); 

You catch my drift Wink
Jonny H - THT Main Developer & Founder


Reply
#13
My system is easier if you want to use different languages. Else the files will have to have each time the english forms and it's better to keep it compact. I don't know how I'll manage the language selection, but maybe you could help?
Now I have translated the Order and now I have to do Admin and Client control panel (don't know sure that i'll do the admin cp)
Reply
#14
Oh yeah, sorry didn't think that through.
Simple, I'd have a folder in includes call languages, with php files like, dutch.php that the includes/languages.php includes, depending on the scripts setting.
Jonny H - THT Main Developer & Founder


Reply
#15
Yes, with a language setting in the database that loads the good language file. (wasn't there a function included in THT for checking all files in a folder?)
Reply
#16
How about this, language files be stored in a different folder /languages, and like this:
/languages/english/lang_orderform.php
/languages/english/lang_admin_home.php (Admin area home)
etc...

Btw, if anyone wants me to translate to Portuguese, drop me a PM. Will do that.
Jimmie Lin - Community Manager & THT.Next Developer
Reply
#17
(12-18-2008, 04:48 AM)alfaleader Wrote: Yes, with a language setting in the database that loads the good language file. (wasn't there a function included in THT for checking all files in a folder?)
Yeah there is.
The function is:
PHP Code:
$main->folderFiles("folderlink"); 
Make sure you use the global LINK to get you in the includes folder. For example:
PHP Code:
$main->folderFiles(LINK ."languages/"); 
That would return the files in an array. The structure would be:
PHP Code:
$files $main->folderFiles(LINK ."languages/");
echo 
$files[0]; // Would output the first file. For example dutch.php 
Jonny H - THT Main Developer & Founder


Reply
#18
Ok, thanks!
Reply
#19
I need help:
PHP Code:
<?
class lang {

public 
$language;

public function 
__construct() { # Assign stuff to variables on creation
        
global $db;
        
$query "SELECT value FROM `tht_config` WHERE name = 'language'";
        
$this->language HELP!!!!
        
        }


public function 
translate($output) {

$original = array();


//    all visable things in the order form
$original[0] = 'Step One - Choose Hosting'//order forms start
$original[1] = 'Domain/Subdomain:';
$original[2] = 'Package:';
...

if (
$language != 'english'){ //if language is english, things don't have to be replaced
require_once(LINK.'language/'.$this->language.'/translation.php');
echo 
$language;

//replaces the english output by the foreign language
return str_replace($original$replacement$output);
}


    }

}

?>

I have made in the database unther tht-config, name = 'language' , the 'value' should be the language I want.
The problem is that I can't get this value out of the database. Could someone do this for me? (i get 'Resource id #62' if I try Sad )
Reply
#20
Easy.
$db->config('language');. No need to query.

This pulls up the value 'language' from the tht_config table. With your code, it would be:

PHP Code:
public function __construct() { # Assign stuff to variables on creation
        
global $db;
        
$this->language $db->config('language');
        
        } 
Jimmie Lin - Community Manager & THT.Next Developer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)