Current time: 02-08-2012, 10:24 AM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Language support
12-17-2008, 05:16 AM
Post: #11
RE: Language support
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)
Find all posts by this user
Quote this message in a reply
12-17-2008, 12:50 PM
Post: #12
RE: Language support
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
Find all posts by this user
Quote this message in a reply
12-17-2008, 04:27 PM
Post: #13
RE: Language support
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)
Find all posts by this user
Quote this message in a reply
12-17-2008, 05:17 PM
Post: #14
RE: Language support
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
Find all posts by this user
Quote this message in a reply
12-18-2008, 04:48 AM
Post: #15
RE: Language support
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?)
Find all posts by this user
Quote this message in a reply
12-18-2008, 08:23 AM (This post was last modified: 12-18-2008 08:24 AM by Jimmie.)
Post: #16
RE: Language support
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
Visit this user's website Find all posts by this user
Quote this message in a reply
12-18-2008, 09:15 AM
Post: #17
RE: Language support
(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
Find all posts by this user
Quote this message in a reply
12-18-2008, 01:12 PM
Post: #18
RE: Language support
Ok, thanks!
Find all posts by this user
Quote this message in a reply
12-22-2008, 12:34 PM
Post: #19
RE: Language support
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 )
Find all posts by this user
Quote this message in a reply
12-22-2008, 01:27 PM (This post was last modified: 12-22-2008 01:28 PM by Jimmie.)
Post: #20
RE: Language support
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
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)