refac: language detection

This commit is contained in:
Timothy J. Baek 2024-06-29 20:41:06 -07:00
parent 4b0c422ec5
commit 5ee7da54a1

View File

@ -750,6 +750,11 @@ export const extractFrontmatter = (content) => {
// Function to determine the best matching language // Function to determine the best matching language
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => { export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
const languages = supportedLanguages.map((lang) => lang.code); const languages = supportedLanguages.map((lang) => lang.code);
const match = preferredLanguages.find((lang) => languages.includes(lang));
const match = preferredLanguages
.map((prefLang) => languages.find((lang) => lang.startsWith(prefLang)))
.find(Boolean);
console.log(languages, preferredLanguages, match, defaultLocale);
return match || defaultLocale; return match || defaultLocale;
}; };