Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Google Sign-in button language

So here's my problem: I have a default Google Sign-in button in my page and need to change it's language.

I render it with:

gapi.signin2.render('google-button', {
    'scope': 'profile email',
    'width': 122,
    'height': 39, 
    ...
});

I've tried several solutions throughout the web. Those being:

  1. Inserting lang object in the API's script tag:

    <script src="https://apis.google.com/js/platform.js" async defer > 
        {lang:'pt'}
    </script>
    
  2. Setting ___gcfg:

    window.___gcfg = {
        lang: 'pt'
    };
    
  3. Setting the lang attribute in the html tag

    <html lang="pt">
    
  4. Adding a parameter to the API's URL

    <script src="https://apis.google.com/js/platform.js?hl=pt" . . .
    

And the only place I found something about this in Google's documentation, it redirects to a page that says nothing about this. (https://developers.google.com/identity/sign-in/web/build-button)

I really would like to avoid building a custom button because of the branding guidelines, could someone help me?

PS: I'm using React.js

Many thanks!

like image 976
Guilherme Telles Avatar asked Oct 27 '15 17:10

Guilherme Telles


Video Answer


1 Answers

I had the same problem, I ended with that for now. Not really clean but "it works". So it uses a callback for the platform.js script:

<script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>

<script>
    function onLoadCallback() {
        $('span[id^="not_signed_"]').html('Se connecter avec Google');
    }
</script>

As the span id is dynamic we have to use a "id start with" selector. (using jQuery in this case).

like image 66
COil Avatar answered Oct 17 '22 02:10

COil