refac: browser language detection

This commit is contained in:
Timothy J. Baek
2024-06-29 20:04:04 -07:00
parent 56137acd94
commit df8d1dacc4
2 changed files with 12 additions and 5 deletions

View File

@@ -746,3 +746,10 @@ export const extractFrontmatter = (content) => {
return frontmatter;
};
// Function to determine the best matching language
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
const languages = supportedLanguages.map((lang) => lang.code);
const match = preferredLanguages.find((lang) => languages.includes(lang));
return match || defaultLocale;
};