-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into web-console/news-ui
- Loading branch information
Showing
13 changed files
with
139 additions
and
52 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
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,9 @@ | ||
/** | ||
* Function to determine the user's preferred language or locale using the `navigator` object. | ||
* @returns {string} The user's preferred language or locale. | ||
*/ | ||
export const fetchUserLocale = () => { | ||
return navigator.languages && navigator.languages.length | ||
? navigator.languages[0] | ||
: navigator.language | ||
} |
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,28 @@ | ||
import { Locale } from "date-fns" | ||
import { enUS, fr, es, de, ja, ko, zhCN } from "date-fns/locale" | ||
|
||
/** | ||
* Function to retrieve a date-fns Locale object based on a specified language code. | ||
* | ||
* This function takes a language code as input and returns the corresponding date-fns Locale object. | ||
* It uses a predefined mapping of language codes to Locale objects. If the input language code is not found | ||
* in the mapping, it defaults to the English (United States) Locale. | ||
* | ||
* @param {string} language - The language code (e.g., "en-US", "fr-FR", "es-ES") for which to retrieve the Locale. | ||
* @returns {Locale} The date-fns Locale object corresponding to the input language code, or the English (United States) Locale as the default. | ||
*/ | ||
export const getLocaleFromLanguage = (language: string) => { | ||
const localeMap: { [key: string]: Locale } = { | ||
"en-US": enUS, // English (United States) | ||
"fr-FR": fr, // French (France) | ||
"es-ES": es, // Spanish (Spain) | ||
"de-DE": de, // German (Germany) | ||
"ja-JP": ja, // Japanese (Japan) | ||
"ko-KR": ko, // Korean (South Korea), | ||
"zh-CN": zhCN, // Chinese (Simplified, China) | ||
// add more language support here | ||
} | ||
|
||
// If the language is not found in the map, default to English (United States) | ||
return localeMap[language] || enUS | ||
} |
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,5 @@ | ||
// isServerError takes api response and checks if the error is of type server error or timeout | ||
// returns true if server error type | ||
export const isServerError = (response: Response): boolean => { | ||
return response.status === 408 || response.status >= 500; | ||
}; |
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