-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix map page crash due to unsupported language error
- Handle Mapbox unsupported locale by fallback to `en` language for unsupported ones - Related to #6429
- Loading branch information
1 parent
9b3fe34
commit 15f4ad9
Showing
6 changed files
with
40 additions
and
14 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
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,23 @@ | ||
import { useSelector } from 'react-redux'; | ||
import MapboxLanguage from '@mapbox/mapbox-gl-language'; | ||
|
||
const { supportedLanguages } = new MapboxLanguage(); | ||
|
||
const defaultLocale = 'en'; | ||
|
||
/** | ||
* A React custom hook to check if the locale language is supported by Mapbox GL or not | ||
* | ||
* Returns `en` if the locale is not supported, else returns preferred locale | ||
* | ||
*/ | ||
export default function useMapboxSupportedLanguage() { | ||
const locale = useSelector((state) => state.preferences.locale); | ||
|
||
if (!locale) return defaultLocale; | ||
|
||
const language = locale.substr(0, 2); | ||
if (supportedLanguages.includes(language)) return language; | ||
|
||
return defaultLocale; | ||
} |