-
Notifications
You must be signed in to change notification settings - Fork 397
feat(clerk-js, types): Add optional locale
from browser to signup flow
#6915
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
Merged
guilherme6191
merged 7 commits into
main
from
guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7abb603
feat: Add optional locale frowm browser to signup flow
guilherme6191 9bac8f8
feat(i18n): add locale to SignUp fixtures, class, and improve testing
guilherme6191 55028fa
chore: Update missing locale in state that implements it
guilherme6191 4541abc
refactor(i18n): only add locale key if any value is present
guilherme6191 e4478a0
feat: Add try catch to be extra safe
guilherme6191 1096c51
chore: generate changeset
guilherme6191 e07029d
refactor: Move locale util down to _create for consistency
guilherme6191 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/clerk-react': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Add support for sign up `locale` |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { getBrowserLocale } from '../locale'; | ||
|
||
describe('getBrowserLocale()', () => { | ||
afterEach(() => { | ||
vi.unstubAllGlobals(); | ||
}); | ||
|
||
it('returns the browser locale when available', () => { | ||
vi.stubGlobal('navigator', { language: 'es-ES' }); | ||
|
||
expect(getBrowserLocale()).toBe('es-ES'); | ||
}); | ||
|
||
it('returns null as default when navigator.language is not available', () => { | ||
vi.stubGlobal('navigator', { language: undefined }); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
|
||
it('returns null as default when navigator.language is empty string', () => { | ||
vi.stubGlobal('navigator', { language: '' }); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
|
||
it('returns null as default when navigator object is not defined', () => { | ||
vi.stubGlobal('navigator', undefined); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { inBrowser } from '@clerk/shared/browser'; | ||
|
||
const DEFAULT_LOCALE = null; | ||
|
||
/** | ||
* Detects the user's preferred locale from the browser. | ||
* Falls back to null if locale cannot be determined. | ||
* | ||
* @returns The browser's reported locale string (typically BCP 47 format like 'en-US', 'es-ES') or null if locale cannot be determined. | ||
*/ | ||
export function getBrowserLocale(): string | null { | ||
if (!inBrowser()) { | ||
return DEFAULT_LOCALE; | ||
} | ||
|
||
try { | ||
// Get locale from the browser | ||
const locale = navigator?.language; | ||
|
||
// Validate that we got a non-empty string | ||
if (!locale || typeof locale !== 'string' || locale.trim() === '') { | ||
return DEFAULT_LOCALE; | ||
} | ||
return locale; | ||
} catch { | ||
return DEFAULT_LOCALE; | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.