next-i18next
Version:
The easiest way to translate your NextJs apps.
24 lines (19 loc) • 479 B
JavaScript
export const lngFromReq = req => {
if (!req.i18n) {
return null;
}
const {
allLanguages,
defaultLanguage,
fallbackLng
} = req.i18n.options;
const fallback = fallbackLng || defaultLanguage;
if (!req.i18n.languages) {
return typeof fallback === 'string' ? fallback : null;
}
const language = req.i18n.languages.find(l => allLanguages.includes(l)) || fallback;
if (typeof language === 'string') {
return language;
}
return null;
};