remix-utils-rt
Version:
This package contains simple utility functions to use with [React Router](https://reactrouter.com/home).
19 lines • 762 B
JavaScript
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;
}
//# sourceMappingURL=get-client-locales.js.map