0

I try to design a web in different languages.

How can make the link that gives a clean url? Some pages are dynamic so, I do not know the url, I am searching for a way to make that links work in any page.

I know I can do this because it works in any page:

<a href='?lang=en'>en</a>
<a href='?lang=fr'>fr</a>

But, how to do that and be able to get a clean url like this?:

myDomain/someFolder/file.php // the default in English
myDomain/fr/someFolder/file.php // fr for French

(Beware that it is not just change fr to en. In English there is no /en/)

I have found that I have tu use a rewrite rule in the htaccess to change from myDomain/someFolder/file.php to myDomain/Folder/file.php?lang=en But this is not the point, my question is different, I ask: how to make clean links in the html if I do not know the url?

Nrc
  • 9,577
  • 17
  • 67
  • 114

1 Answers1

0

What I would do, which is not anywhere as fancy as an .htaccess rewrite tool...

First, I would do something to get the current page name. This can be as simple as:

$pagename = "contactme.html";

Now, I have an array of available languages:

$languages = array('en'=>'English','fr'=>'French','es'=>'Spanish');

With that, I can slap this on the top of every page:

Select your language: <?php
foreach($languages as $ln=>$language)
    print " <a href='mysite.com/$ln/$pagename'>$ln</a> ";

That will spit out a list of abbreviations. Can they be little flags (a lot of people like those). Sure. Change $ln in the anchor to <img src='$ln.png' border='0'> and make sure you have all the images. Can they be in a form with a select list? Sure. Make a select list. Add an 'onchange' trigger to the form to reload to the correct URL. Can they be is a super-fancy rotating flash animation? Yes - if you really want to do something that silly.

kainaw
  • 4,256
  • 1
  • 18
  • 38
  • this is interesting but it does not answer my question. I do not ask how to choose language. I ask how to make links if I do not know the url. – Nrc Apr 01 '15 at 07:55