From 4b0c422ec55ca52fb69e5497b038658f981e5348 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 29 Jun 2024 20:33:10 -0700 Subject: [PATCH 1/2] chore: format --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e38e5b26..be9b8ec7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - ## [0.3.7] - 2024-06-29 ### Added From 5ee7da54a1c640f385fb086ece20cb402102dd98 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 29 Jun 2024 20:41:06 -0700 Subject: [PATCH 2/2] 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; };