- This topic is empty.
-
AuthorPosts
-
February 6, 2010 at 3:21 am #27892
e11world
MemberHi all,
I’ve been looking on the net for something like this and found a few things but because I’m a beginner still, I can’t put it together.
I need to change the site’s language based on the folder /en/ or /fr/ and the file names are always the same. The site is not big and this would work perfectly.I have this code in asp that does it but not sure how to convert it into php:
A sample site using it is http://www.contacservices.com/fr/contactus.html but on home page, it’s using index.html and index_fr.html because they’re not in the /en/ and /fr/ foldersCode:<% Dim PATH_INFO PATH_INFO = Request.ServerVariables("PATH_INFO") If (Instr(PATH_INFO,"/fr/")>0) Then
‘Response.Write(“FRENCH”)
PATH_INFO =Replace( PATH_INFO , “/fr/”, “/en/”)
ElseIf (Instr(PATH_INFO,”/en/”)>0) Then
‘Response.Write(“ENGLSIH”)
PATH_INFO =Replace( PATH_INFO , “/en/”, “/fr/”)
End If
%>
<%'Response.Write(Request.ServerVariables("PATH_INFO"))%>I also found this http://www.phpbuilder.com/tips/item.php?id=343 but I can’t figure out why it’s not working. Maybe I’m just not using it right.
Can you guys please help me?February 7, 2010 at 3:53 pm #70594Chris Coyier
KeymasterI really have no idea. The closest I’ve ever come to playing with multiple language support is this nice jQuery plugin:
February 9, 2010 at 1:37 pm #70690e11world
MemberUnfortunately, this is not what I had in mind. I’ve seen that before but I’ve posted my request on another forum and will post back a link once I get the right answer. Thanks Chris!
February 11, 2010 at 12:01 am #70747e11world
MemberThe url looks messy when you click on the flags and navigation back and forth. I think this confuses the user.
I found another sample but also not sure how to use this one either http://www.phpbuilder.com/tips/item.php … int_mode=1 :?
Please, I hope someone answer my question the way I wrote it. I think I’m getting closer but I would love to see code samples because I’m such a newbie with PHP.
I need it to do the same thing shown here http://www.contacservices.com/en/aboutus.html (when you click on the Français in the top right corner). It just changes the folder from en to fr and reloads/redirects the page. This works from any page except the home page which is because it’s not within the en or fr folders.
Thanks to anyone who can help!February 11, 2010 at 4:10 pm #70772davesgonebananas
MemberOk I think I understand what you mean. You have this setup:
[img]http://grab.by/2mmk[/img]
and you want the php code to create a link that will switch between the en and fr directories.February 11, 2010 at 11:51 pm #70795e11world
MemberEXACTLY! Thanks for clearing this up Dave. Only thing is, the include folder would be in the top root level as well as the en and fr folders. Do you have a solution for this?
February 12, 2010 at 9:49 am #70818davesgonebananas
MemberYou can use a regular expression to get the language out of the url. Such as:
Code:if (preg_match(‘/^/(en|fr)/(.*)/’, $_SERVER[‘REQUEST_URI’], $matches)) {
$cur_lang = $matches[1];
if ($cur_lang == ‘en’)
$alt_lang = ‘fr’;
else
$alt_lang = ‘en’;$alt_lang_url = “/{$alt_lang}/{$matches[2]}”;
echo “$alt_lang“;
}February 12, 2010 at 6:45 pm #70851e11world
MemberThanks for the reply again dave.
But I found a solution after playing around with my original code!!! :lol: :lol: Basically converting the code I already had from the start from ASP to PHP did the trick:I put the following code in the include folder and I named it hdr-ar.php
Code:0){
echo “YOU ARE IN THE ARABIC SITE”;
$path_info = str_replace(“/ar/”, “/en/”, $path_info);
}else if (strpos($path_info, “/en/”) > 0){
echo “YOU ARE IN THE ENGLISH SITE”;
$path_info = str_replace(“/en/”, “/ar/”, $path_info);
}
echo ‘
‘;
echo $path_info;
?>
You can comment the echo statements. It’s just there for testing.
I put the following code in the include folder and I named it hdr-en.php
Code:0){
echo “YOU ARE IN THE ARABIC SITE”;
$path_info = str_replace(“/ar/”, “/en/”, $path_info);
}else if (strpos($path_info, “/en/”) > 0){
echo “YOU ARE IN THE ENGLISH SITE”;
$path_info = str_replace(“/en/”, “/ar/”, $path_info);
}
echo ‘
‘;
echo $path_info;
?>*The arabic writing might show weird on this post but you get the point.
I had a problem running this using PATH_INFO which didn’t really do anything. Then I used REQUEST_URI and that fixed it right away.
Just include the file(s) usingCode:and you’re good to go.
It’s too bad not many people answered my question properly (maybe didn’t fully understand it) and I’m more amazed/sad :shock: at how little responses there were but anyways, I hope this helps someone in the future. :D
By the way, this works in php5 and should be fine in php4 too. -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.