feat: translations

This commit is contained in:
chenos 2022-04-23 11:55:33 +08:00
parent 5c0184a397
commit 1f04f90a00
15 changed files with 127 additions and 35 deletions

View File

@ -1,6 +1,7 @@
import { onFieldChange } from '@formily/core'; import { onFieldChange } from '@formily/core';
import { message } from 'antd'; import { message } from 'antd';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next';
import { useAPIClient, useRequest } from '../../api-client'; import { useAPIClient, useRequest } from '../../api-client';
import { useRecord } from '../../record-provider'; import { useRecord } from '../../record-provider';
import { SchemaComponent } from '../../schema-component'; import { SchemaComponent } from '../../schema-component';
@ -8,6 +9,7 @@ import { SchemaComponent } from '../../schema-component';
export const RoleConfigure = () => { export const RoleConfigure = () => {
const api = useAPIClient(); const api = useAPIClient();
const record = useRecord(); const record = useRecord();
const { t } = useTranslation();
return ( return (
<SchemaComponent <SchemaComponent
schema={{ schema={{
@ -36,25 +38,25 @@ export const RoleConfigure = () => {
filterByTk: record.name, filterByTk: record.name,
values: form.values, values: form.values,
}); });
message.success('保存成功!'); message.success(t('Saved successfully'));
}); });
}, },
}, },
properties: { properties: {
allowConfigure: { allowConfigure: {
title: '配置权限', title: t('Configure permissions'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Checkbox', 'x-component': 'Checkbox',
'x-content': '允许配置系统,包括界面配置、数据表配置、权限配置、系统配置等全部配置项', 'x-content': '允许配置系统,包括界面配置、数据表配置、权限配置、系统配置等全部配置项',
}, },
'strategy.actions': { 'strategy.actions': {
title: '通用数据操作权限', title: t('General action permissions'),
description: '所有数据表都默认使用通用数据操作权限;同时,可以针对每个数据表单独配置权限。', description: '所有数据表都默认使用通用数据操作权限;同时,可以针对每个数据表单独配置权限。',
'x-component': 'StrategyActions', 'x-component': 'StrategyActions',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
}, },
allowNewMenu: { allowNewMenu: {
title: '新增菜单项默认访问权限', title: t('Menu permissions'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Checkbox', 'x-component': 'Checkbox',
'x-content': '新增菜单项默认允许访问', 'x-content': '新增菜单项默认允许访问',

View File

@ -97,17 +97,17 @@ export const RolesResourcesActions = connect((props) => {
}, },
{ {
dataIndex: 'onNewRecord', dataIndex: 'onNewRecord',
title: '类型', title: t('Action type'),
render: (onNewRecord) => render: (onNewRecord) =>
onNewRecord ? ( onNewRecord ? (
<Tag color={'green'}>{t('Operate on new record')}</Tag> <Tag color={'green'}>{t('Action on new records')}</Tag>
) : ( ) : (
<Tag color={'geekblue'}>{t('Operate on existing record')}</Tag> <Tag color={'geekblue'}>{t('Action on existing records')}</Tag>
), ),
}, },
{ {
dataIndex: 'enabled', dataIndex: 'enabled',
title: '允许操作', title: t("Allow"),
render: (enabled, action) => ( render: (enabled, action) => (
<Checkbox <Checkbox
checked={enabled} checked={enabled}
@ -119,7 +119,7 @@ export const RolesResourcesActions = connect((props) => {
}, },
{ {
dataIndex: 'scope', dataIndex: 'scope',
title: '可操作的数据范围', title: t("Data scope"),
render: (value, action) => render: (value, action) =>
!action.onNewRecord && ( !action.onNewRecord && (
<ScopeSelect <ScopeSelect

View File

@ -48,22 +48,22 @@ export const StrategyActions = connect((props) => {
columns={[ columns={[
{ {
dataIndex: 'displayName', dataIndex: 'displayName',
title: '操作', title: t('Action display name'),
render: (value) => compile(value), render: (value) => compile(value),
}, },
{ {
dataIndex: 'onNewRecord', dataIndex: 'onNewRecord',
title: '类型', title: t('Action type'),
render: (onNewRecord) => render: (onNewRecord) =>
onNewRecord ? ( onNewRecord ? (
<Tag color={'green'}>{t('Operate on new record')}</Tag> <Tag color={'green'}>{t('Action on new records')}</Tag>
) : ( ) : (
<Tag color={'geekblue'}>{t('Operate on existing record')}</Tag> <Tag color={'geekblue'}>{t('Action on existing records')}</Tag>
), ),
}, },
{ {
dataIndex: 'enabled', dataIndex: 'enabled',
title: '允许操作', title: t('Allow'),
render: (enabled, action) => ( render: (enabled, action) => (
<Checkbox <Checkbox
checked={enabled} checked={enabled}
@ -80,15 +80,15 @@ export const StrategyActions = connect((props) => {
}, },
{ {
dataIndex: 'scope', dataIndex: 'scope',
title: '可操作的数据范围', title: t('Data scope'),
render: (scope, action) => render: (scope, action) =>
!action.onNewRecord && ( !action.onNewRecord && (
<Select <Select
size={'small'} size={'small'}
value={scope} value={scope}
options={[ options={[
{ label: 'All records', value: 'all' }, { label: t('All records'), value: 'all' },
{ label: 'Own records', value: 'own' }, { label: t('Own records'), value: 'own' },
]} ]}
onChange={(value) => { onChange={(value) => {
scopes[action.name] = value; scopes[action.name] = value;

View File

@ -14,7 +14,7 @@ const collection = {
name: 'title', name: 'title',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Role title")}}', title: '{{t("Role display name")}}',
type: 'number', type: 'number',
'x-component': 'Input', 'x-component': 'Input',
required: true, required: true,
@ -25,7 +25,7 @@ const collection = {
name: 'name', name: 'name',
interface: 'input', interface: 'input',
uiSchema: { uiSchema: {
title: '{{t("Role name")}}', title: '{{t("Role UID")}}',
type: 'string', type: 'string',
'x-component': 'Input', 'x-component': 'Input',
} as ISchema, } as ISchema,
@ -213,7 +213,7 @@ export const roleSchema: ISchema = {
}, },
column4: { column4: {
type: 'void', type: 'void',
title: 'Actions', title: '{{t("Actions")}}',
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
actions: { actions: {

View File

@ -133,7 +133,7 @@ export const scopesSchema: ISchema = {
}, },
scope: { scope: {
type: 'object', type: 'object',
title: 'Data scope', title: '{{t("Data scope")}}',
name: 'filter', name: 'filter',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Filter', 'x-component': 'Filter',
@ -260,7 +260,7 @@ export const scopesSchema: ISchema = {
}, },
scope: { scope: {
type: 'object', type: 'object',
title: 'Data scope', title: '{{t("Data scope")}}',
name: 'filter', name: 'filter',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Filter', 'x-component': 'Filter',

View File

@ -14,8 +14,8 @@ export function AntdConfigProvider(props) {
}, },
{ {
onSuccess(data) { onSuccess(data) {
const locale = localStorage.getItem('locale'); const locale = localStorage.getItem('NOCOBASE_LANG');
if (data?.data?.lang && locale !== data?.data?.lang) { if (data?.data?.lang && !locale) {
i18n.changeLanguage(data?.data?.lang); i18n.changeLanguage(data?.data?.lang);
} }
}, },

View File

@ -30,7 +30,7 @@ export class APIClient {
services: Record<string, Result<any, any>>; services: Record<string, Result<any, any>>;
tokenKey = 'nocobaseToken'; tokenKey = 'NOCOBASE_TOKEN';
constructor(instance?: AxiosInstance | AxiosRequestConfig) { constructor(instance?: AxiosInstance | AxiosRequestConfig) {
this.services = observable({}); this.services = observable({});

View File

@ -24,7 +24,7 @@ const getSchema = (schema: IField): ISchema => {
...cloneDeep(schema.default), ...cloneDeep(schema.default),
interface: schema.name, interface: schema.name,
}; };
initialValue.uiSchema.title = schema.title; // initialValue.uiSchema.title = schema.title;
return { return {
type: 'object', type: 'object',
properties: { properties: {

View File

@ -23,8 +23,7 @@ const getSchema = (schema: IField): ISchema => {
...cloneDeep(schema.default), ...cloneDeep(schema.default),
interface: schema.name, interface: schema.name,
}; };
initialValue.uiSchema.title = schema.title; // initialValue.uiSchema.title = schema.title;
console.log('initialValue', initialValue);
return { return {
type: 'object', type: 'object',
properties: { properties: {

View File

@ -7,7 +7,7 @@ const log = require('debug')('i18next');
export const i18n = i18next.createInstance(); export const i18n = i18next.createInstance();
i18n.use(initReactI18next).init({ i18n.use(initReactI18next).init({
lng: localStorage.getItem('locale') || 'en-US', lng: localStorage.getItem('NOCOBASE_LANG') || 'en-US',
// debug: true, // debug: true,
defaultNS: 'client', defaultNS: 'client',
// parseMissingKeyHandler: (key) => { // parseMissingKeyHandler: (key) => {
@ -29,9 +29,9 @@ function setMomentLng(language) {
moment.locale(lng); moment.locale(lng);
} }
setMomentLng(localStorage.getItem('locale')); setMomentLng(localStorage.getItem('NOCOBASE_LANG'));
i18n.on('languageChanged', (lng) => { i18n.on('languageChanged', (lng) => {
localStorage.setItem('locale', lng); localStorage.setItem('NOCOBASE_LANG', lng);
setMomentLng(lng); setMomentLng(lng);
}); });

View File

@ -292,4 +292,94 @@ export default {
"Button title": "按钮标题", "Button title": "按钮标题",
"Button icon": "按钮图标", "Button icon": "按钮图标",
"Submitted successfully": "提交成功", "Submitted successfully": "提交成功",
"Open mode": "打开方式",
'Menu item title': '菜单项名称',
'Menu item icon': '菜单项图标',
'Target': '目标',
'Position': '位置',
'Insert before': '在前面插入',
'Insert after': '在后面插入',
'UI Editor': '界面配置',
'ASC': 'ASC',
'DESC': 'DESC',
'Add sort field': '添加排序字段',
'ID': 'ID',
'Drawer': '抽屉',
'Dialog': '对话框',
'Delete action': '删除操作',
'Custom column title': '自定义列标题',
'Original title: ': '原始标题: ',
'Delete table column': '删除列',
'Skip required validation': '跳过必填校验',
'Form values': '表单值',
'When submitting the following fields, the saved values are': '提交以下字段时,保存的值为',
'After successful submission': '提交成功后',
'Then': '然后',
'Stay on current page': '停留在当前页面',
'Redirect to': '跳转到',
'Save action': '保存操作',
'Exists': '存在',
'Filename': '文件名',
'Add condition': '添加条件',
'Add condition group': '添加条件分组',
'exists': '存在',
'not exists': '不存在',
'is current logged-in user': '为当前登录用户',
'=': '=',
'≠': '≠',
'>': '>',
'≥': '≥',
'<': '<',
'≤': '≤',
'Role UID': '角色标识',
'Precision': '精确度',
'Accept': '文件格式',
'Rich Text': '富文本',
'Junction collection': '中间表',
'Fields': '字段',
'Edit field title': '编辑字段标题',
'Field title': '字段标题',
'Original field title: ': '原始字段标题:',
'Edit tooltip': '编辑提示信息',
'Delete field': '删除字段',
'Select collection': '选择数据表',
'Blank block': '空区块',
'Duplicate template': '复制模板',
'Reference template': '引用模板',
'Create calendar block': '创建日历区块',
'Create kanban block': '创建看板区块',
'Group field': '分组字段',
'Tab name': '标签名称',
'Current record blocks': '当前数据区块',
'Pop-up message': '弹窗提示消息',
'Delete role': '删除角色',
'Role display name': '角色名称',
'Default role': '默认角色',
'Global permissions': '全局配置',
'General action permissions': '通用操作权限',
'Action display name': '操作名称',
'Allow': '允许',
'Data scope': '数据范围',
'Action on new records': '对新增数据操作',
'Action on existing records': '对已有数据操作',
'All records': '所有数据',
'Own records': '自己的数据',
'Permission policy': '权限策略',
'Individual': '单独配置',
'General': '通用配置',
'Accessible': '允许访问',
'Configure permission': '配置权限',
'Action permission': '操作权限',
'Field permission': '字段权限',
'Scope name': '数据范围名称',
} }

View File

@ -1,8 +1,10 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import React from 'react'; import React from 'react';
import { PoweredBy } from '../../../powered-by'; import { PoweredBy } from '../../../powered-by';
import { useSystemSettings } from '../../../system-settings';
export function AuthLayout(props: any) { export function AuthLayout(props: any) {
const { data } = useSystemSettings();
return ( return (
<div <div
style={{ style={{
@ -11,7 +13,7 @@ export function AuthLayout(props: any) {
paddingTop: '20vh', paddingTop: '20vh',
}} }}
> >
<h1>NocoBase</h1> <h1>{data?.data?.title}</h1>
{props.children} {props.children}
<div <div
className={css` className={css`

View File

@ -140,7 +140,7 @@ export const ActionDesigner = (props) => {
properties: { properties: {
successMessage: { successMessage: {
// default: t('Submitted successfully!'), // default: t('Submitted successfully!'),
title: 'Pop-up message', title: t('Pop-up message'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input.TextArea', 'x-component': 'Input.TextArea',
'x-component-props': {}, 'x-component-props': {},

View File

@ -279,7 +279,7 @@ SchemaSettings.FormItemTemplate = (props) => {
setVisible(false); setVisible(false);
const gridSchema = findGridSchema(fieldSchema); const gridSchema = findGridSchema(fieldSchema);
console.log('gridSchema', gridSchema); console.log('gridSchema', gridSchema);
const values = await FormDialog('Save as template', () => { const values = await FormDialog(t('Save as template'), () => {
return ( return (
<FormLayout layout={'vertical'}> <FormLayout layout={'vertical'}>
<SchemaComponent <SchemaComponent

View File

@ -83,7 +83,6 @@ export const SigninPage = () => {
useCurrentDocumentTitle('Signin'); useCurrentDocumentTitle('Signin');
const ctx = useSystemSettings(); const ctx = useSystemSettings();
const allowSignUp = ctx?.data?.data?.allowSignUp; const allowSignUp = ctx?.data?.data?.allowSignUp;
console.log('ctx.data.allowSignUp', ctx?.data?.data?.allowSignUp);
return ( return (
<div> <div>
<SchemaComponent scope={{ useSignin, allowSignUp }} schema={schema} /> <SchemaComponent scope={{ useSignin, allowSignUp }} schema={schema} />