繁体   English   中英

如何更改Google登录按钮语言

[英]How to change Google Sign-in button language

所以这是我的问题:我的页面中有一个默认的Google登录按钮,需要更改它的语言。

我渲染它:

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

我在整个网络上尝试了几种解决方案。 那些是:

  1. 在API的脚本标记中插入lang对象:

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

     window.___gcfg = { lang: 'pt' }; 
  3. html标记中设置lang属性

     <html lang="pt"> 
  4. 将参数添加到API的URL

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

我在Google的文档中找到了与此相关的唯一地方,它重定向到一个对此没有任何说明的页面。 https://developers.google.com/identity/sign-in/web/build-button

我真的想避免建立一个自定义按钮,因为品牌指导,有人可以帮助我吗?

PS:我正在使用React.js

非常感谢!

仅使用css:

 span[id^=not_signed_]:before { content: 'Connexion avec Google'; padding-right:20px; } 

有人在评论中问我是怎么做到的,所以这就是答案。

我也无法得到window.___gcfg设置工作,但我设法让hl参数工作。

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

为此,当您调用gapi.signin2.render(id, options)函数时,必须在options参数中设置longtitle: true (默认为false )。

{
  scope: 'email',
  width: 200,
  height: 50,
  longtitle: true,
  theme: 'dark',
  onsuccess: handleSuccess,
  onfailure: handleFailure
}

还要注意文档中所述的宽度

longtitle

显示长标签,例如“使用Google登录”而不是“登录”(默认值:false)。 使用长标题时,应该从默认值增加按钮的宽度。

在Google Signs In for Websites中,您可以更改按钮的语言。

只有选项符合此部分的说明: https//developers.google.com/identity/sign-in/web/build-button#building_a_button_with_a_custom_graphic

我有同样的问题,我现在结束了。 不是很干净,但“它有效”。 所以它使用platform.js脚本的回调:

<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>

由于span id是动态的,我们必须使用“id start with”选择器。 (在这种情况下使用jQuery)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM