Page 1 of 1

how to create a template to support diffent languages?

Posted: Fri May 02, 2008 5:58 pm
by lilili
I am doing a project, in which user first selects a languages,
and then the same html form written with selected language will be displayed. i.e. a user can decide to show the same form in English, French, and so on.

What I can think is I need to create a template html form
and several text xml files writen in different language.
then maybe I need to create a php file to parse the corresponding text xml file based on the language selected by users, and then combine the result to template form.

Since I am not familar with html and php, I do not know how to implent it in details. Can anybody give me a very simple example about how to create a template html and how to compine the parsed result to the template?

Thanks.

Re: how to create a template to support diffent languages?

Posted: Fri May 02, 2008 6:13 pm
by yacahuma
no need to get that fancy(xml)

directory
language
|---EN
|---SP
|---FR

inside each have a file called language.php

language.php(for example in EN,english)
$NAME_LA = 'Name';
$PHONE_LA = 'Phone';
etc
etc

the on top of the page form

Code: Select all

 
include 'language/' . $SESSION['user_selected_lang'] . '/'language.php';
 
<p><label for="">$NAME_LA</label><input...></p>
 

check that the session is a valid value(EN,SP, or whatever)

Re: how to create a template to support diffent languages?

Posted: Sat May 03, 2008 1:00 am
by Kieran Huggins
You should consider the Gettext functions in PHP. I've never used them personally, but they seem to make a certain amount of sense at first glance.

gettext() also has a handy alias that makes your code a little easier to look at: _()

Is it a perfect solution? Not by a long shot (i18n and l10n are far from "solved") but it certainly seems to handle your template issue with a certain grace.

Re: how to create a template to support diffent languages?

Posted: Sat May 03, 2008 6:21 am
by yacahuma
kieran,

Why would gettext will be better that just including a language file?
I read the doc in php.net but do not see any extra benefits.


Thank you

Re: how to create a template to support diffent languages?

Posted: Sat May 03, 2008 6:59 am
by matthewl
If your going to use includes, you might want to consider using constants rather than vars.

however the gettext functions are designed to standardize the translations.

Re: how to create a template to support diffent languages?

Posted: Tue May 06, 2008 3:13 pm
by lilili
Thanks all for your suggestion.
Finally I implemented this function by using include.
gettext is also good. But in my case, the language will not change
once it is configured. so include may be simpler.

Re: how to create a template to support diffent languages?

Posted: Wed May 07, 2008 10:54 am
by yacahuma
If your going to use includes, you might want to consider using constants rather than vars.
Why is this??
Thank you