views:

607

answers:

2

I'm trying to create a web-page intended to be viewed by an iPhone OS device. Is there a way to retrieve the current language or some locale-specific data when a user visits on an iPhone OS device? I want to set the web-page language according to the local or language of the device. So, how can I get the language-setting of an iPhone OS device visiting my web page?

+2  A: 

Try using the "Accept-Language" header sent by the browser to the server. It should be something like "en-us" or "fr-fr", etc. depending on the language setting for the device.

Marc Novakowski
A: 

iPhone indeed sends reasonably correct Accept-Language as seen from this email.

(However, it's strange for me that it sends only fr-fr. It appears more reasonable to send fr-fr, en-us;q=0.9 and they might change into that in the future)

But the more important information for you is that you don't really need to do anything complicated in your situation. This is called content negotiation and is standard feature of Apache and other servers -- they will automatically return page in the language user prefers with minimum configuration.

You do need to create different pages at different URIs for different languages. If you don't, you're breaking the idea that any content has an URI that can be easily passed to another person and that second person will see exactly the same content even if his/her language is different.

How Apache does it. You create

example.fr.html
example.en.html
example.de.html

(and edit .htaccess file). Then /example returns page in user's language while /example.fr always returns French. As an added bonus, you don't need .html.

ilya n.