chenos 479f64f197
feat: support i18n (#99)
* feat: i18next

* multi language data

* feat(client): locale support

* en-US for collections

* us-EN for routes

* en-US for routes

* en-US for attachments

* feat: partial translations

* translation

* add AntdConfigProvider

* translation

* translation

* feat: translation

* feat: add translation

* fix: improve translation

* feat: improve translation

* fix: SyntaxError: Unexpected token ) in JSON at position

* typo

* feat: improve translation

* feat: improve translation

* feat: language settings can be saved on the server

* feat: lang option of init cli

* demo translation

* typo

* change address field to textarea

* address data

* feat: chart translation

* feat: chart translation

* improve translation

* signin,signup,signout...

Co-authored-by: Zhou <zhou.working@gmail.com>
2021-11-08 19:32:59 +08:00

76 lines
2.0 KiB
TypeScript

import { cloneDeep, set } from 'lodash';
import * as types from './types';
import { uid } from '@formily/shared';
import { ISchema } from '../..';
interface IDefaultSchema {
dataType: string;
uiSchema?: ISchema;
[key: string]: any;
}
export interface FieldOptions extends ISchema {
[key: string]: any;
default?: IDefaultSchema;
}
export const interfaces = new Map<string, ISchema>();
const fields = {};
const groupLabels = {};
export function getDefaultFields() {
const defaults = ['createdAt', 'updatedAt', 'createdBy', 'updatedBy'];
return defaults.map((key) => {
return {
interface: key,
key: uid(),
name: uid(),
privilege: 'undelete',
...cloneDeep(interfaces.get(key)?.default),
};
});
}
export function registerField(group: string, type: string, schema) {
fields[group] = fields[group] || {};
set(fields, [group, type], schema);
interfaces.set(type, schema);
}
export function registerGroupLabel(key: string, label: string) {
groupLabels[key] = label;
}
Object.keys(types).forEach((type) => {
const schema = types[type];
registerField(schema.group || 'others', type, { order: 0, ...schema });
});
registerGroupLabel('basic', '{{t("Basic")}}');
registerGroupLabel('choices', '{{t("Choices")}}');
registerGroupLabel('media', '{{t("Media")}}');
registerGroupLabel('datetime', '{{t("Date & Time")}}');
registerGroupLabel('relation', '{{t("Relation")}}');
registerGroupLabel('systemInfo', '{{t("System info")}}');
registerGroupLabel('others', '{{t("Others")}}');
export const options = Object.keys(groupLabels).map((groupName) => {
return {
label: groupLabels[groupName],
children: Object.keys(fields[groupName] || {})
.map((type) => {
return {
name: type,
...fields[groupName][type],
};
})
.sort((a, b) => a.order - b.order),
};
});
export const isAssociation = (field) => {
const options = interfaces.get(field.interface);
return options?.isAssociation;
};