chore: create a utils/languages file

This commit is contained in:
Chuma McPhoy
2024-07-04 15:19:17 +02:00
parent f89d17cd7f
commit bfcef5b832
12 changed files with 31 additions and 54 deletions
+16
View File
@@ -0,0 +1,16 @@
import { Lang } from "@/constants/languages"
export function findLang(pathname: string) {
return Object.values(Lang).find(
(l) => pathname.startsWith(`/${l}/`) || pathname === `/${l}`
)
}
/**
* Helper function to convert langs in uppercase or capitalized format (e.g. the Hotel endpoint)
* to to Lang enum.
*/
export function fromUppercaseToLangEnum(lang: string): Lang | undefined {
const lowerCaseLang = lang.toLowerCase()
return Object.values(Lang).find((l) => l === lowerCaseLang)
}