4 ms·
> Not that hard to implement, except perhaps parsing the Accept-Language preferences with their quality value can be cumbersome. Many web frameworks provide a
by Cyberdog 2y ago
> Not that hard to implement, except perhaps parsing the Accept-Language preferences with their quality value can be cumbersome.
Many web frameworks provide a tool for parsing these for you. If yours doesn't (or you're not using one) you may be able to find a package that does. Some will also do the matching for you, so you can pass it a list of languages you can support alongside the Accept-Language string and it will pick the best option that's found in both.
For example, here's the documentation for such a method in the excellent Nette PHP framework that I've been using where I can lately: https://doc.nette.org/en/http/request#toc-detectlanguage https://doc.nette.org/en/http/request#toc-detectlanguage
But I've also used this stand-alone package:
https://packagist.org/packages/willdurand/negotiation https://packagist.org/packages/willdurand/negotiation
- LordShredda 2y agoRuby on Rails has built in localization and actually respects whatever headers the user agent sends