TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-24-2008, 09:49 PM   #1 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Help Creating multilingual site

Hello !
I am wondering how to make a multilingual site?
I figured I'd use gettext & Zend_Translate, but I still haven't got the application part figured yet.
The site is going to have an article manager and a gallery and it is planned it is going to be in 3 languages.

Can you give me some tips on doing this, I really don't like the solution on adding the language 1 and language 2 parts in admin. I want it added in one language to MySQL and if selected the secondary language the MySQL data is translated from the primary to secondary language.

Thank you!
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-24-2008, 09:51 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Theres an article for this on this site
TalkPHP - The Framework Basics of Creating Multilingual PHP Applications
__________________

Village Idiot is offline  
Reply With Quote
Old 02-24-2008, 09:54 PM   #3 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

I know that. :)
Well here is the deal:
I have a CMS let's say a classic one - article manager.
I add an article in English and my website is in French, Italian and Hungarian (for example).
English is the main language and is added to the MySQL database. Is there a way to translate the English text to other languages (dynamicly) - or the same text has to be pre-translated in mysql or in a language file (CSV, getext, XML) and then parsed and displayed.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-24-2008, 10:52 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Translating a language to another language verbatim yields a laughable reading sentence in the other language, although the basics are there. If you can find a system that recognises language phrases then you might be in with a shout. However, if it's a website such as a business website or any other website where it's impeccable the language is perfectly, definitely the best way is to pre-translate it. For a blog or that kind of website, dynamic translation will suffice because as aforementioned, people can get the basics.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-24-2008, 11:02 PM   #5 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Right now I'm nowhere about this translation thing.
I know that dynamic translation is - laughable.
Do I save the translated text to a special table in mysql to where save the translated text.
I'm really lost :) After reading 1000 tutoriuals, articles & how-to's I'm lost. :)
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-24-2008, 11:51 PM   #6 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 12
Thanks: 0
DarkPrince11 is on a distinguished road
Default

Maybe I'm being a bit simple minded here but couldn't you just have a Google Translate link for the article? Just post all your articles in X Language and set up a button to convert it to Y language.

Occam's Razor :: the simplest solution is always the best

There are actually lots of way to go about doing this. You could of course save the translated copies in an XML File, SQL Table, or where-ever you want for that matter. But for the sake of performance, here's my two cents.

First, publish all your articles in English. Then, in your publishing code, set up a curl method to send a POST request to an online translation service such as Google Translate or BabelFish. Then just parse the outputted HTML & retrieve your translated text.

lol maybe I'm crazy. It's late over here and I'm drunk on coffee. But it's just an idea. *

*crashes*
Send a message via AIM to DarkPrince11 Send a message via MSN to DarkPrince11
DarkPrince11 is offline  
Reply With Quote
Old 02-25-2008, 12:06 AM   #7 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Yeah that is one solution, but not as well good since most of my sites are going to be in croatian :)
I've got a plan for now:
in the config file I set the main lang - the lang that is the data in the DB in.
For other languages there is a file with translated text with keyword for the phrase - articleid-pageid - so if the alternate language is selected the data is pulled out of that file.
I'm thinking gettext for the file. or CSV variant. What do you suggest?
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-25-2008, 01:14 AM   #8 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Hi abiko

Quote:
Originally Posted by abiko View Post
Hello !
I am wondering how to make a multilingual site?
I figured I'd use gettext & Zend_Translate
I can't help with the MySQL stuff I'm afraid but I can help with Zend_Translate

Below is an example copy/pasted from one of my sites that uses Zend_Translate (and the rest of the Zend Framework).

I use TMX rather than gettext because you can use any XML or text editor to edit it rather than the hellish tool that is PoEdit, and it is looking likely to become the open standard in translation

-------------
First we load and setup the Zend_Translate class - in my application, this is in the bootstrap but if you're not using the Zend Framework MVC components then put it whether you wish:

PHP Code:
Zend_Loader::loadClass('Zend_Translate');

$translate = new Zend_Translate('tmx''./application/languages/language.tmx''en');
Zend_Registry::set('language'$translate); 
In this code, I load my TMX file (language.tmx) and tell Zend_Translate that I want to use the English ('en') language.

Here is a snippet from my language.tmx so you can see what the format is:

Code:
<?xml version="1.0" ?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
	<header creationtool="CTmx" creationtoolversion="1.0" datatype="winres" segtype="sentence" adminlang="en-us" srclang="en-us" o-tmf="txt">
	</header>

	<body>

		<tu tuid='pleaseEnterYourEmailAddress'>
			<tuv xml:lang="en">
				<seg>Please enter your email address</seg>
			</tuv>
			<tuv xml:lang="de">
				<seg>...German Translation Here...</seg>
			</tuv>
		</tu>

		<tu tuid='emailAddress'>
			<tuv xml:lang="en">
				<seg>Email Address</seg>
			</tuv>
			<tuv xml:lang="de">
				<seg>...German Translation Here...</seg>
			<tuv>
		</tu>
And it goes on like that. Each <tu> block contains the translations for each string. In mine, it has the English strings first, then the German strings (well, will have )

The next step is to fetch the 'language' object from Zend_Registry in your controllers (again, if you aren't using the Zend Framework MVC components, adjust as needed )

In my controllers init() method I have:

PHP Code:
$this->language Zend_Registry::get('language'); 
If you are also using Zend_View, you could use something like:

PHP Code:
$this->view->language Zend_Registry::get('language'); 
This will make the language available in your views.

So, at this point, you have all of your translated strings from language.tmx, in your selected language (English in this example) available in $this->language.

To go about displaying translated text to your user, you need to use the _() method (yes, the method is just an underscore - it aliases to translate() but _() is shorter to type )

For example, using our language.tmx snippet above, if I wanted to echo out "Email Address" and "Please enter your email address", I would use:

PHP Code:
echo $this->language->_('emailAddress');
echo 
$this->language->_('pleaseEnterYourEmailAddress'); 
If you have another look at the TMX snippet above you'll see that we are using the tuid property to get the language string.

If you wanted to echo the German translations for "emailAddress" and "pleaseEnterYourEmailAddress", you would just change the language specified when you created the Zend_Translate object.

For example, to load our German translation instead of English:

PHP Code:
$translate = new Zend_Translate('tmx''./application/languages/language.tmx''de'); 
Hopefully that wall of text made sense and will get you started in the right direction

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following 3 Users Say Thank You to Alan @ CIT For This Useful Post:
abiko (02-25-2008), flyingbuddha (02-25-2008), Wildhoney (02-25-2008)
Old 02-25-2008, 01:25 AM   #9 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Whoo, thank you!
Yeah, gettext is real drag - I mean that PoEdit is.. bad. I never thought that TBX is so - simple :)
I use only some parts of Zend Framework i have my own MVC.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-25-2008, 01:51 AM   #10 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Also there is an idea I was working on.
Country recognition via IP.
There are online services (APIs) where you send guests IP and it returns the country.
Via that you can build :
a) your own service for that - all you need is 1 mysql db :) and a subdomain (you ping your own server about the IP)
b) group of countries that can use the same language (for instance - Serbian, Bosnian & Croatian can use Croatian language :) )

I'm just trying to expand Alans idea/version.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 02-25-2008, 02:04 AM   #11 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

on a totally random note

if( !is_sane('abiko) ) punish::slap();

Is wrong :D
TlcAndres is offline  
Reply With Quote
Old 02-25-2008, 02:05 AM   #12 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

corrected it. 3 seconds ago :D
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 03-24-2009, 05:52 PM   #13 (permalink)
The Wanderer
 
Join Date: Mar 2009
Posts: 11
Thanks: 0
sphoid is on a distinguished road
Default Zend_Translate, Gettext, and PHPTAL

I just wrote an extensive article on this yesterday. Maybe it will help you if you are still exploring solutions: http://blog.realmofzod.com/2009/03/2...te-and-phptal/
sphoid is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:25 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design