Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function i18nMiddleware() {
// initialLocale will be set by the middleware
init(INIT_OPTIONS);
return (req, res, next) => {
const isDocument = DOCUMENT_REGEX.test(req.originalUrl);
// get the initial locale only for a document request
if (!isDocument) {
next();
return;
}
let locale = getCookie('locale', req.headers.cookie);
// no cookie, let's get the first accepted language
if (locale == null) {
if (req.headers['accept-language']) {
const headerLngs = req.headers['accept-language'].split(',');
const headerLngCodes = headerLngs.map(lng => lng.split(';')[0].trim());
export function startClient() {
console.log('nav', getLocaleFromNavigator());
init({
...INIT_OPTIONS,
initialLocale: getCookie('locale') || INIT_OPTIONS.localeOptions.find(option => option == cropCountryCode(getLocaleFromNavigator())) || INIT_OPTIONS.initialLocale,
});
}