handles post and update of specific language on page model
This commit is contained in:
@@ -8,15 +8,21 @@ import languageParser from 'accept-language-parser';
|
||||
*/
|
||||
export default function locale(localization) {
|
||||
return function (req, res, next) {
|
||||
let query;
|
||||
let setLocale;
|
||||
if (req.query.locale) {
|
||||
query = localization.languages.find(locale => locale === req.query.locale);
|
||||
if (query) {
|
||||
req.locale = query;
|
||||
setLocale = localization.languages.find(search => search === req.query.locale);
|
||||
if (setLocale) {
|
||||
req.locale = setLocale;
|
||||
}
|
||||
if (req.query.locale === '*' || req.query.locale === 'all')
|
||||
return next();
|
||||
}
|
||||
if (req.body.locale){
|
||||
setLocale = localization.languages.find(search => search === req.body.locale);
|
||||
if (setLocale) {
|
||||
req.locale = setLocale;
|
||||
}
|
||||
}
|
||||
if (!req.locale && req.headers['accept-language'])
|
||||
req.locale = languageParser.pick(localization.languages, req.headers['accept-language']);
|
||||
if (!req.locale)
|
||||
|
||||
Reference in New Issue
Block a user