Commit 5ee7da54 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac: language detection

parent 4b0c422e
...@@ -750,6 +750,11 @@ export const extractFrontmatter = (content) => { ...@@ -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;
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment