Created
August 2, 2020 11:21
-
-
Save HoldYourWaffle/b48739e16b6a5dd2aabff04b7c9ceeed to your computer and use it in GitHub Desktop.
Translate gapi-rendered Google Sign-In button text programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Utility function to change the text of a gapi-rendered Google Sign-In button */ | |
function translateSignin(id, signinText, signedinText) { | |
const spans = document.getElementById(id).querySelectorAll('.abcRioButtonContents span'); | |
if (spans.length !== 2) { | |
throw new Error(`Incorrect amount of sign-in span children (${spans.length} != 2)`); | |
} | |
spans.forEach(span => { | |
span.innerHTML = span.innerHTML.replace(/^Sign in with Google$/, signinText); | |
span.innerHTML = span.innerHTML.replace(/^Signed in with Google$/, signedinText); | |
}) | |
} | |
// Usage: | |
gapi.signin2.render('google-signin', { | |
// see https://developers.google.com/identity/sign-in/web/build-button | |
}); | |
// Wait for render | |
setTimeout(() => translateSignin('google-signin', 'Inloggen met Google', 'Ingelogd met Google')); // translated to Dutch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment