HI all,
I want to develp a multi lingual website in PHP.(english and french)
I am a novice developer in this aspect.
Pls suggest us what are the methods used in general.
Do we need any extra s/w.
Hey.
This can be as simple as: - Define an array of values in different languages, preferably each language having it's own array defined in a separate file.
- Create a script that figures out which language to use (by, for example, reading session, cookie or get/post values) and includes the proper file.
- Include said script into your pages, using the array defined in the language files to echo the text in those pages.
Consider, if you had these files: - locale/
-
english.php
-
french.php
-
set_locale.php
-
index.php
You could define each of the "locale" files as such: - <?php
-
/*
-
* File: locale/english.php
-
*/
-
$locale = array(
-
'title' => 'Title in English',
-
'h1' => 'The following in in English:',
-
'p1' => 'This is a sample text, in English'
-
);
-
?>
-
<?php
-
/*
-
* File: locale/french.php
-
*/
-
$locale = array(
-
'title' => 'Titre en français',
-
'h1' => 'Le texte suivant en en français:',
-
'p1' => 'Il s\'agit d\'un échantillon de texte, en français.'
-
);
-
?>
Then, in your "set_locale.php" file, you could select a language based on some input variable, like say; a variable named "lang" from the GET array, and include one of those files based on that value: - <?php
-
/*
-
* File: set_locale.php
-
*/
-
-
// Get the language from the query string, or set a default.
-
($language = @$_GET['lang']) or $language = 'english';
-
-
// Set up a list of possible values, and make sure the
-
// selected language is valid.
-
$allowed_locales = array('english', 'french');
-
if(!in_array($language, $allowed_locales)) {
-
$language = 'english'; // Set default if it is invalid.
-
}
-
-
// Inlclude the selected language
-
include "locale/{$language}.php";
-
-
// Make it global, so it is accessible everywhere in the code.
-
$GLOBALS['L'] = $locale;
-
?>
Then, in your pages (the index.php page, in this example), include the "set_locale.php" script and use the $GLOBALS['L'] array to set language specific phrases in the HTML: - <?php
-
/*
-
* File: index.php
-
*/
-
-
// Include the "set_locale" script to fetch the locale
-
// that should be used.
-
include_once "set_locale.php"
-
-
// Print the HTML, using the selected locale.
-
?>
-
<html>
-
<head>
-
<title><?php echo $GLOBALS['L']['title']; ?></title>
-
</head>
-
<body>
-
<h1><?php echo $GLOBALS['L']['h1']; ?></h1>
-
<p><?php echo $GLOBALS['L']['p1']; ?></p>
-
</body>
-
</html>
See what I mean?
6 4469
basicly you do it like a monolingual website, where you can decide, whether to put the english or french content in (e.g. by using templates)
Atli 5,058
Expert 4TB
Hey.
This can be as simple as: - Define an array of values in different languages, preferably each language having it's own array defined in a separate file.
- Create a script that figures out which language to use (by, for example, reading session, cookie or get/post values) and includes the proper file.
- Include said script into your pages, using the array defined in the language files to echo the text in those pages.
Consider, if you had these files: - locale/
-
english.php
-
french.php
-
set_locale.php
-
index.php
You could define each of the "locale" files as such: - <?php
-
/*
-
* File: locale/english.php
-
*/
-
$locale = array(
-
'title' => 'Title in English',
-
'h1' => 'The following in in English:',
-
'p1' => 'This is a sample text, in English'
-
);
-
?>
-
<?php
-
/*
-
* File: locale/french.php
-
*/
-
$locale = array(
-
'title' => 'Titre en français',
-
'h1' => 'Le texte suivant en en français:',
-
'p1' => 'Il s\'agit d\'un échantillon de texte, en français.'
-
);
-
?>
Then, in your "set_locale.php" file, you could select a language based on some input variable, like say; a variable named "lang" from the GET array, and include one of those files based on that value: - <?php
-
/*
-
* File: set_locale.php
-
*/
-
-
// Get the language from the query string, or set a default.
-
($language = @$_GET['lang']) or $language = 'english';
-
-
// Set up a list of possible values, and make sure the
-
// selected language is valid.
-
$allowed_locales = array('english', 'french');
-
if(!in_array($language, $allowed_locales)) {
-
$language = 'english'; // Set default if it is invalid.
-
}
-
-
// Inlclude the selected language
-
include "locale/{$language}.php";
-
-
// Make it global, so it is accessible everywhere in the code.
-
$GLOBALS['L'] = $locale;
-
?>
Then, in your pages (the index.php page, in this example), include the "set_locale.php" script and use the $GLOBALS['L'] array to set language specific phrases in the HTML: - <?php
-
/*
-
* File: index.php
-
*/
-
-
// Include the "set_locale" script to fetch the locale
-
// that should be used.
-
include_once "set_locale.php"
-
-
// Print the HTML, using the selected locale.
-
?>
-
<html>
-
<head>
-
<title><?php echo $GLOBALS['L']['title']; ?></title>
-
</head>
-
<body>
-
<h1><?php echo $GLOBALS['L']['h1']; ?></h1>
-
<p><?php echo $GLOBALS['L']['p1']; ?></p>
-
</body>
-
</html>
See what I mean?
Or you could just tell your users to learn how to use Google Translate. ;)
thanks for your valuable code
Given the code, how would you go about coding an <a></a> tag with alternating classes?
For example when the home page is selected, the home link looks:
<a href="index.php?lang=english" class="selected">Home</a>
but if I'm on the contact us page for example, I want the home link to be (without the class="selected"):
<a href="index.php?lang=english">Home</a>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dc |
last post by:
Product Announcement:
Multi-Lingual web site using Nested Templates and Menus
http://www.decloak.com/Products/Dreamweaver/NestedTemplates/
You can see the TONGUES of FIRE demo web site at...
|
by: J |
last post by:
I've run CSSCheck on my style sheets and I always get a warning
similar to this:
"font: bold 9pt/100% sans-serif
Warning: Absolute length units should not generally be used on the Web ..."
...
|
by: Z D |
last post by:
Hello,
I need to support multiple languages in a product package being developed in
both ASP.NET (vb.net) and WinForm .net (c#).
I was wondering if there are any best practice guides,...
|
by: Ahmad Jalil Qarshi |
last post by:
hi!
i want to develop an application in VC7 which will have multilingual
support. I m new to VC7. plz help me to find some useful link or something
else tht may be helpful.
thanx in advance....
|
by: THY |
last post by:
anyone know a good way to create a multi-lingual website in ASP.Net ?
thanks
|
by: Bart Schelkens |
last post by:
Hi,
what is the best way (or the most interesting) way to make my application
multi-lingual?
I have french, dutch and english users and they all want the menu's and the
labels,... in their...
|
by: Cédric |
last post by:
Hello,
wanting to have a multi-lingual windows form application. Does anyone know,
how to do, or where articles on that topic could be found.
Thanks
|
by: Dylan Parry |
last post by:
Hi folks,
I was wondering if anyone here has experience of making Web applications
that are multi-lingual? The solution that I have in my head is to have
several "language" files as resources so...
|
by: Aussie Rules |
last post by:
Hi,
I have a site that Iwant to either display my text in english or french,
based on the users prefernces ?
I am new to webforms, but I know in winforms, this is pretty easy with a
resource...
|
by: Jonathan |
last post by:
Before I start creating a new asp.net website, is there a standard way of
making it multi-lingual?
For example, rather than type in body text to a page, should I rather refer
by number code to a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |