about Adding different language support on a webpage

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
mr00047
Forum Newbie
Posts: 14
Joined: Fri May 12, 2006 1:01 pm

about Adding different language support on a webpage

Post by mr00047 »

i want to know what is the best approach (in terms of reducing development time, energy, code reusablity) to add different language support on a web page. so far i have followed two approaches.

1. creating different php script for different language declaring hundreads of variables that contain the texts(that need to be translated) and include that script to every pages of the site.
2. the second approach is to write an XML file that contain all the text and then translate them with name/value pair technique.


in these two approaches i have used google translator to translate to my desired language which is incredibly painful. So for these, none of the approaches seemed very much convincing.

can anyone show me a better approach on how to implement different language support on a web page?

Any kind of suggestion is warmly welcomed.

Thanks.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Basic templating will simplify bulk text translation quite simply. The templates can be stored in language subdirectories or named differently. When getting the template see if the page exists as the translated value or default to the default language. This doesn't solve other PHP created details/variables. The site I am currently encoding uses a database to store translations rather than a file. A function translate('text to be translated','class') is used to get the text and store it in a session variable applicable to the language (subsequent calls simply get the session variable). The class parameter is used to bulk load a "set" of information in one select rather than several (example Titles are Mr, Mrs, Miss .. load all three using class 'title') for storing in the session. This means the first time something is called it may take longer as access to the database is required but subsequent loads of the same information get the information from the session. The translate function also inserts additional links if the user is an admin so they can edit the text in the database directly from the page.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Well, there's gettext
Post Reply