This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preferred browser language fallback strategy (#13)
* Add initial logic for retrieving the browser locale * Add tests for browser utilities * Cleanup * Add support for browser language * Update changelog * Update prop description Co-Authored-By: Tyler Biethman <[email protected]> * Move files into private directory * Update snapshots and private directory * Add private directory disclaimer * update dependencies * revert update to dependencies. i only want to update dev dependencies * update snapshots, update docker dev environment, update npm lock strategy * :/ * Update snapshots and tests with action header, maybe this will work? * keep the selector for slide-panel * data attribute * 25% confidence this will pass regularly * Apply suggestions from code review Co-Authored-By: Emily Rohrbough <[email protected]> * Update test selector * Update WDIO test selector Co-authored-by: Tyler Biethman <[email protected]> Co-authored-by: Matt Henkes <[email protected]> Co-authored-by: Emily Rohrbough <[email protected]>
- Loading branch information
1 parent
de2ec99
commit 2c25dd8
Showing
53 changed files
with
328 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
package-lock=false | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
FROM cerner/terra-node | ||
FROM cerner/terra-node-ci:1 |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* global TERRA_AGGREGATED_LOCALES */ | ||
|
||
// The fallback locale that will be used if a supported locale is unable to be retrieved from the browser. | ||
const DEFAULT_LOCALE = 'en'; | ||
|
||
/** | ||
* Returns a boolean indicating if the locale is supported. | ||
* @param {string} locale - The locale. | ||
* @returns {bool} - A boolean indicating the locale is supported. | ||
*/ | ||
const isSupported = (locale) => { | ||
if (typeof TERRA_AGGREGATED_LOCALES === 'object' && Array.isArray(TERRA_AGGREGATED_LOCALES) && locale) { | ||
return TERRA_AGGREGATED_LOCALES.indexOf(locale) > -1; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
/** | ||
* Filters the user's preferred languages from the browser and returns the first language found that is included in the supported locale list. | ||
* @returns {string|null} - A supported locale. Null if not found. | ||
*/ | ||
const filterLanguages = () => { | ||
if (navigator.languages && navigator.languages.length > 0) { | ||
for (let index = 0; index < navigator.languages.length; index += 1) { | ||
const locale = navigator.languages[index]; | ||
|
||
if (isSupported(locale)) { | ||
return locale; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
/** | ||
* Retrieves the preferred browser locale. | ||
* @returns {string} - A supported browser locale. Falls back to en. | ||
*/ | ||
const getBrowserLocale = () => { | ||
const preferredLocale = filterLanguages(); | ||
|
||
if (preferredLocale) { | ||
return preferredLocale; | ||
} | ||
|
||
if (isSupported(navigator.language)) { | ||
return navigator.language; | ||
} | ||
|
||
if (isSupported(navigator.userLanguage)) { | ||
return navigator.userLanguage; | ||
} | ||
|
||
if (isSupported(navigator.browserLanguage)) { | ||
return navigator.browserLanguage; | ||
} | ||
|
||
return DEFAULT_LOCALE; | ||
}; | ||
|
||
export default getBrowserLocale; | ||
export { isSupported, filterLanguages }; |
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
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
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
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
Oops, something went wrong.