UNPKG

strapi-plugin-i18n

Version:

This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API

50 lines (41 loc) 1.11 kB
'use strict'; const { prop } = require('lodash/fp'); const { yup, formatYupErrors } = require('strapi-utils'); const { isoLocales } = require('../constants'); const allowedLocaleCodes = isoLocales.map(prop('code')); const handleReject = error => Promise.reject(formatYupErrors(error)); const createLocaleSchema = yup .object() .shape({ name: yup .string() .max(50) .nullable(), code: yup .string() .oneOf(allowedLocaleCodes) .required(), isDefault: yup.boolean().required(), }) .noUnknown(); const validateCreateLocaleInput = data => { return createLocaleSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject); }; const updateLocaleSchema = yup .object() .shape({ name: yup .string() .min(1) .max(50) .nullable(), isDefault: yup.boolean(), }) .noUnknown(); const validateUpdateLocaleInput = data => { return updateLocaleSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject); }; module.exports = { validateCreateLocaleInput, validateUpdateLocaleInput, };