Translate website automatically according to the netizen's country

1

I wonder if there is a function php or JS that through the visitor's IP could translate the site automatically according to the netizen's country without having to choose the language manually in a select.

Suppose my site was visited by someone from England, so the script would automatically choose the English language of the Lang folder. If it were visited by someone from Italy, the script automatically rotated the Italian language, so visitors from Portugal and Brazil would have the Portuguese language and so on.

I looked for something like this but found nothing about it.

I noticed that in ads ads ads google uses this function, because even if we Brazilians visit a foreign site, the ads adsense displays are from Brazilian campaigns. It is as if it detects the locality of the visitor. And this is what I want, to detect the user's country 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 ...
    
asked by anonymous 06.07.2016 / 05:13

2 answers

2

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

<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage;
</script>
    
06.07.2016 / 05:25
1

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

    
06.07.2016 / 11:27