UNPKG

@kentcdodds/tmp-remix-utils

Version:

This package contains simple utility functions to use with [Remix.run](https://remix.run).

17 lines (16 loc) 672 B
import { parseAcceptLanguage } from "intl-parse-accept-language"; import { getHeaders } from "./get-headers.js"; export function getClientLocales(requestOrHeaders) { let headers = getHeaders(requestOrHeaders); let acceptLanguage = headers.get("Accept-Language"); // if the header is not defined, return undefined if (!acceptLanguage) return undefined; let locales = parseAcceptLanguage(acceptLanguage, { validate: Intl.DateTimeFormat.supportedLocalesOf, ignoreWildcard: true, }); // if there are no locales found, return undefined if (locales.length === 0) return undefined; // if there are multiple locales, return the array return locales; }