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

Locale property is not working? #56

Closed
Bodrie opened this issue Jul 14, 2022 · 9 comments
Closed

Locale property is not working? #56

Bodrie opened this issue Jul 14, 2022 · 9 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@Bodrie
Copy link

Bodrie commented Jul 14, 2022

To be honest I'm not sure if I am doing something wrong but it seems that the locale property of the the GoogleLogin component isn't working, in your and in the google documentation is stated that: locale: string, e.g. "zh_CN", but even the example isn't working.

Is this the case or I miss understhood something?

@MomenSherif
Copy link
Owner

Capture

<GoogleLoginOauth
  locale="zh_CN"
  onSuccess={() => console.log('onSuccesss.')}
  onError={() => {
    console.log('onError')
  }}
/>

It's working!

@MomenSherif MomenSherif self-assigned this Jul 15, 2022
@MomenSherif MomenSherif added the invalid This doesn't seem right label Jul 15, 2022
@Bodrie
Copy link
Author

Bodrie commented Jul 15, 2022

Sorry but that is pretty inappropriate, to close and mark the issue as invalid w/o any explanation or further discution...

@Bodrie
Copy link
Author

Bodrie commented Jul 15, 2022

Screenshot 15-07-2022

The locale is set...

Screenshot 15-07-2022_1

The button stays in the browser def lang...

@MomenSherif
Copy link
Owner

https://developers.google.com/identity/gsi/web/reference/js-reference#locale

The pre-set locale of the button text. If it's not set, the browser's default locale or the Google session user’s preference is used. Therefore, different users might see different versions of localized buttons, and possibly with different sizes.

Maybe the user account has a strong preference that google respects.

@Crsk
Copy link

Crsk commented Apr 7, 2024

https://developers.google.com/identity/gsi/web/reference/js-reference#locale

The pre-set locale of the button text. If it's not set, the browser's default locale or the Google session user’s preference is used. Therefore, different users might see different versions of localized buttons, and possibly with different sizes.

Maybe the user account has a strong preference that google respects.

image

From the Google side, the user account has not a strong preference, so the locale property should also have priority over Google account and browser.

BTW, the locale is not working for me either, same as @Bodrie I did set the property and the button stays in another lang which in my case is Spanish. Seems like this is not working if your default Google account or browser is set to other than English


Edit, I did some testing (making sure to hard reload):

OS and Browser Google account Locale prop Text result
English Spanish undefined Spanish
English Spanish zh_CN Spanish
English English zh_CN English
English English es-CL English
English Portuguese es-CL Portuguese
English Portuguese undefined Portuguese
English Portuguese en_AU Portuguese
English Chinese en_US Chinese
image

So, my theory about

Locale not working if your default Google account or browser is set to other than English

seems pretty much incorrect. I have no idea why it works on some people but it doesn't for some others.

@buraketmen
Copy link

any update?

@Whitelistedd
Copy link

doesnt work for me too

@andriiwp3
Copy link

Hey guys! I have ran into this issue as well
The reason why this doesn't work according to Google's documentation is that the library doesn't pass the hl directive

Add the hl parameter and language code to the src directive when loading the library, for example: gsi/client?hl=<iso-639-code>

If it's not set, the browser's default locale or the Google session user's preference is used

I have found a workaround to get around it for now

This works perfectly for me, so feel free to use it. In the meantime, I'll try to open a PR to this repo to fix the issue globally

  const onScriptLoaded = () => {
    document.body.removeChild(document.querySelector('[src="https://accounts.google.com/gsi/client"]'));
    const scriptTag = document.createElement('script');
    scriptTag.src = `https://accounts.google.com/gsi/client?hl=${locale}`;
    scriptTag.onload = () => {
      setIsReady(true);
    };
    document.body.appendChild(scriptTag);
  };

  return (
    <div ref={ref}>
      <GoogleOAuthProvider
        clientId={googleSignInToken}
        onScriptLoadSuccess={onScriptLoaded}
      >
        {isReady && <GoogleLogin {...props} />}
      </GoogleOAuthProvider>
    </div>
  );

@andriiwp3
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

6 participants