-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6430 from hotosm/fix/6429-mapbox-language-not-sup…
…ported-error
- Loading branch information
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; | ||
} |