From 5ee7da54a1c640f385fb086ece20cb402102dd98 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 29 Jun 2024 20:41:06 -0700 Subject: [PATCH] refac: language detection --- src/lib/utils/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index cf7a826ab..d80fcc799 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -750,6 +750,11 @@ export const extractFrontmatter = (content) => { // 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)); + + const match = preferredLanguages + .map((prefLang) => languages.find((lang) => lang.startsWith(prefLang))) + .find(Boolean); + + console.log(languages, preferredLanguages, match, defaultLocale); return match || defaultLocale; };