Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple vanilla js internationalization solution #18

Open
gkpty opened this issue Apr 28, 2020 · 0 comments
Open

simple vanilla js internationalization solution #18

gkpty opened this issue Apr 28, 2020 · 0 comments

Comments

@gkpty
Copy link
Collaborator

gkpty commented Apr 28, 2020

make a script that executes DOM content load. the user needs to include it using the async defer attributes. DOMContentLoaded() .

generate a script version of the JSON translation objects that reads each languages translation as a variable with that language code.

finding the visitor langugae preference

<script>
function myFunction() {
  var x = "Language of the browser: " + navigator.language;
  document.getElementById("demo").innerHTML = x;
}
</script>

then get the translation object according to browser locale and replace each elements textContent with the object value.

document.getElementById('consultaspanama-btn').textContent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant