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.
how to create a template to support diffent languages?
Moderator: General Moderators
Re: how to create a template to support diffent languages?
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
check that the session is a valid value(EN,SP, or whatever)
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)
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: how to create a template to support diffent languages?
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.
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?
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
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?
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.
however the gettext functions are designed to standardize the translations.
Re: how to create a template to support diffent languages?
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.
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?
Why is this??If your going to use includes, you might want to consider using constants rather than vars.
Thank you