Skip to content

Parses the 'Accept-Language' and 'Accept-Charset' HTTP/1.1 headers

License

Notifications You must be signed in to change notification settings

jmullan/AcceptToGettext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AcceptToGettext

Parses the 'Accept-Language' and 'Accept-Charset' HTTP/1.1 headers

In PHP, you have the possibility to use gettext, which makes translating a message a lot easier.

Of course, translation is only interesting if you provide the user with the language and encoding he asks for. Since there's part of the HTTP protocol that allows you to specify that, it's nice if one can use that information to pick the 'right' translation out of the ones you have available.

I wrote something that does just that -- it parses the 'Accept-Language' and 'Accept-Charset' HTTP/1.1 headers, and tells you which one the user prefers out of a list you provide.

Note that even if the user's browser may support this, the user may not know about it; as such, it's probably good practice not to remove links to other-languaged versions, so that people can still get a version of your site in another language if they so prefer.

I wrote this entirely in PHP (4; not sure whether it works under PHP3 (as in "didn't test it")), so, no C code at all. The code is here. Feedback (e.g., bugreports, enhancements, ...) about this is highly appreciated at [email protected].

https://grep.be/articles/php-accept

About

Parses the 'Accept-Language' and 'Accept-Charset' HTTP/1.1 headers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages