Package Exports
- keystone-translated-fields
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (keystone-translated-fields) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
keystone-translated-fields
A small helper library for multilanguage Keystone sites.
Installation
$ yarn add keystone-translated-fields
Example usage
Models
var keystone = require('keystone');
const { createField, combineFields } = require('keystone-translated-fields');
const locales = require('../constants').locales;
const Types = keystone.Field.Types;
const Speaker = new keystone.List('Speaker', {
map: {
name: 'title',
},
singular: 'Speaker',
plural: 'Speakers',
autokey: {
path: 'slug',
from: 'title',
unique: true,
},
});
Speaker.add(combineFields([
{ title: { type: String, required: true } },
{ name: { type: String } },
{ desc: { type: Types.Html, wysiwyg: true, height: 300 } },
{ image: { type: Types.CloudinaryImage } },
createField('about', { type: String }, locales),
]));
Speaker.register();
Middleware
const { getField } = require('keystone-translated-fields');
exports.initLocals = function (req, res, next) {
// ...
res.locals.getField = getField;
// ...
next();
}
Templates
h3 #{getField(speaker, 'title', locale)}
if speaker.desc
!= speaker.desc
p #{getField(speaker, 'about', locale)}