Page 1 of 1

about Adding different language support on a webpage

Posted: Mon Oct 16, 2006 2:53 am
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.

Posted: Mon Oct 16, 2006 3:37 am
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.

Posted: Mon Oct 16, 2006 7:14 am
by Weirdan
Well, there's gettext