Vulcan/packages/vulcan-lib/lib/modules/intl.js

47 lines
917 B
JavaScript
Raw Normal View History

import SimpleSchema from 'simpl-schema';
2018-05-08 12:29:51 +09:00
import { Strings } from './strings';
2018-05-09 09:46:47 +09:00
export const Locales = [];
export const addLocale = locale => {
Locales.push(locale);
}
/*
Look for type name in a few different places
Note: look into simplifying this
*/
export const isIntlField = fieldSchema => {
const typeProperty = fieldSchema.type;
let type;
if (Array.isArray(typeProperty)) {
type = typeProperty[0].type;
} else {
type = typeProperty.singleType ? typeProperty.singleType : typeProperty.definitions[0].type;
}
return type.name === 'IntlString';
}
/*
Generate custom IntlString SimpleSchema type
*/
2018-05-08 12:29:51 +09:00
export const getIntlString = () => {
const schema = {};
Object.keys(Strings).forEach(locale => {
schema[locale] = {
type: String,
optional: true,
};
});
const IntlString = new SimpleSchema(schema);
IntlString.name = 'IntlString';
return IntlString;
}