Translate website automatically according to the country of the internet user

Asked

Viewed 1,159 times

1

I wonder if there is a php or JS function that through the visitor’s IP makes it possible to translate the site automatically according to the country of the internet user without needing him to choose the language manually in a select.

Suppose my website were visited by someone from England, then automatically the script would choose the English language from the Lang folder. If visited by someone from Italy automatically the script would run the Italian language, for visitors from Portugal and Brazil would run the Portuguese language and so on.

I looked for something of the kind but found nothing on the subject.

I noticed that in Adsense ads, google uses this function, because even if we Brazilians visit a foreign site, the ads that Adsense displays are from Brazilian campaigns. It’s as if it detected the visitor’s location. And that’s what I want, to detect the user’s parents and create a condition like:

Se localidade do visitante é igual à Brasil ou Portugal
Utilizar idioma português
 Se não se localidade  do visitante é igual à EUA ou Inglaterra ou Canadá etc
Utilizar idioma inglês
 Se não se localidade do visitante é igual à Espanha ou Argentina ou México etc
Utilizar idioma espanhol
e assim por diante ...

2 answers

2

You can pick up the language using JS and from there translate your content.

<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage;
</script>

1

You can use the $idioma = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2); to recognize the language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.