[thelist] recreating a website in 4 new languages

Bojan Tesanovic btesanovic at gmail.com
Fri Feb 22 09:00:08 CST 2008


Here I will give you example of PHP code.
1. You will need folder eg lang_maps in wich you should put php files  
with array of phrases_key => Language Phrase per file
here is an example of engleash file that contains PHP array
file name: maps_en.php
======
$lang_maps = array{
'WELCOME_GUEST'=>'Hi Guest Welcome to bla.com',
'HEADING_1'=>'How to become Steven Segal :)',
.....
}
======
maps_sr.php  //Serbian language
$lang_maps = array{
'WELCOME_GUEST'=>'Cao gost dobrodosao na bla.com',
'HEADING_1'=>'Kako postati Steven Segal :)',
.....
}
etc etc  make as many language files as you need

you will need a function something like this

//defaults to english
function getTranslation($lngKey,$language='en'){
        static $MAP;
	$path_to_lang_dir= '.....';
	$fileName = 'map_'.$language.'en.php';
	$absolutePath = $path_to_lang_dir . $fileName;
	//defaults to en if file dont exist
	if(  ! file_exists($absolutePath) ) $absolutePath =  
$path_to_lang_dir . 'map_en.php';
	
	if( ! $MAP){
		include($path_to_lang_dir . fileName);
		//assign to static $MAP array from loaded file this will be done  
only once
		//as next time this function is called we alredy have static $MAP  
array loaded

		$MAP = $lang_maps;
	}

	$return = isset($MAP[$lngKey]) ? $MAP[$lngKey] : "No translation for  
$lngKey";


	return $return;
}


====
Than in your templates

<h1> <?php echo getTranslation('WELCOME_GUEST',$LANG); ?></h1>
.....
....
<h2> <?php echo getTranslation('HEADING_1',$LANG); ?></h2>



Also you may want to define in the begining of a execution of you  
script something like this
<?php

if( isset($_GET['lng'] ){
$LNG = $_GET['lng'];
}else if(sset($_COOKIE['lng']){
$LNG = $_COOKIE['lng'];
}else{
$LNG= 'en';
}

define('USER_LANGUAGE',$LNG);
....
?>

doing this it is much easier to handle current user language as it is  
set in one place so above template would be

<h1> <?php echo getTranslation('WELCOME_GUEST', USER_LANGUAGE); ?></h1>
.....
....
<h2> <?php echo getTranslation('HEADING_1', USER_LANGUAGE); ?></h2>


For images it depends on image itself but generally I would make one  
php file that handles images
eg
getImageLang.php  that can choose correct image to return to browser   
so you can have something like

<img src="/getImageLang.php?imgkey=send_email&lang=<?php echo  
USER_LANGUAGE ?> " />



getImageLang.php can either shoose correct image from disk or  
generate an image using GD library , it depends on your needs





On Feb 21, 2008, at 3:17 PM, Nan Harbison wrote:

> Hi Folks,
>
> I just finished a website that the client now wants translated into  
> 4 other
> languages. I am going to do this in a database.
> I am just starting to sort this out in my head.
>
> I need to have:
>
> a table for all the src's of graphics that have writing on them in the
> foreign language (different pages have different numbers of  
> graphics on
> them)
> a table with:
>     the translated heading for each page
>     the content text for each page
>
> Would I put the actual markup in the table, or have each paragraph  
> in a
> separate row and surround it with tags on retrieving it?
>
> Does anyone have suggestions for the best way to approach this?
>
> Thanks for your time.
> Nan
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

Bojan Tesanovic
http://www.classicio.com/
http://www.carster.us/






More information about the thelist mailing list