On Mon, 2014-11-03 at 18:12 +0100, Rafnews wrote: > Hi, > > i'm thinking to make a multi languages application using PHP. > > basically people should go to indx.php and can select 1 of the 4 > languages available. > once chosen, application redirect to: > - www.myapp.com/en for english > - www.myapp.com/fr for french > - www.myapp.com/es for spanish > - www.myapp.com/de for german > > i know that there are several way how to do it, but i also want to make > it easy for SEO. > 1. basically the first thought would be to create folders /en, /fr, /es, > /de for each language but it would force me to have 4 times the same > code and from maintenance point of view that's not good. > 2. another approach would be to have a variable $lang in a session and > to add it to each URL. However how to retrieve it easily when user will > be on page www.myapp.com/fr/controlpanel/profile.php for example ? > 3. we could also use the .htaccess file and rewrite URL, but how to > retrieve the language parameter from URL ? or should it be in session > variable ? > > i don't know what is the best way and especially the more secured. > I would appreciate any feedback. > > thx > This is both a simple and a very complex problem at once, so I'll try and cover with what I know and do. Typically, when you have a website in multiple languages it's for one of two reasons: * You want the content available for people who cannot read the primary language the sites contents is written in * You want to internationalise your website You might be forgiven for thinking they are the same thing, but in the second, consider a website selling cars in Europe, but not all of those cars are available in every country. Thus you might require slightly different content for Switzerland than for UK or France. However, Switzerland speaks two languages: French and German. Splitting your site by language isn't enough, neither is by country. This is where something called language cultures (http://msdn.microsoft.com/en-gb/library/ee825488%28v=cs.20%29.aspx ) can help out. Basically, this is the name given to the pairing of language and region as a means of identifying some content. Currently, I'm building a CMS that can serve multi-culture content, and I'm using the table from the above link as a guide for the URL format, e.g. website.com/en/gb or website.com/fr/fr An .htaccess rule is used to direct all traffic through a central index.php file which then deals with the requests in a typical MVC manner: i.e. process the requested URL, identify the culture and correct controller and pass control to that. You don't necessarily need to do exactly this, but an .htaccess rule would allow you to turn requested URL parameters into query string variables that are passed to your scripts. No duplication of code, and multi-culture content. -- Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php