0

i trying to set the user default language based on user's country

i tried to use this command

Request::server('HTTP_ACCEPT_LANGUAGE');

but it give me this result:

en-US,en;q=0.8,he;q=0.6,zh-CN;q=0.4,zh;q=0.2,ru;q=0.2

so i realized that this is not the right way to detect the user default language because it based on the browser usage and i think that my users will prefer to use their country language

so i wonder what is the best way to get the user language based on his country?

thank you!

Machavity
  • 30,841
  • 27
  • 92
  • 100
Ilan Finkel
  • 496
  • 2
  • 11
  • 28
  • Possible duplicate of [Get visitors language & country code with javascript (client-side)](http://stackoverflow.com/questions/17680413/get-visitors-language-country-code-with-javascript-client-side) – Kev Wilson Oct 29 '16 at 13:41
  • Kev thank you this is a nice solutions, i'm bit afraid to use http://freegeoip.net/json/ service cause i cant be sure that they will always be active and i also dont get the main language of the country but only the country name, country code etc... – Ilan Finkel Oct 29 '16 at 13:58
  • 1
    We tend to use ACCEPT_LANGUAGE header (with the `mcamara/laravel-localization` package). It is most often OK, IP could be better but it's a lot harder to implement. – nxu Oct 29 '16 at 18:03
  • 1
    Also, ACCEPT_LANGUAGE is set by the user's browser, so there's a lot more chances to get the right language for this user (i.e. a user who is on a trip doesn't necessarily want to display the website in the local language). – Marc-Antoine Parent Jan 12 '17 at 19:10
  • Using a language based on the location of a person is a very bad idea. People do not necessarily speak the main language of the place where they currently reside. And there are places that have no distinct main language (Switzerland, Canada, ...) – NineBerry Jan 12 '17 at 19:12

0 Answers0