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

View File

@ -97,17 +97,17 @@ export const RolesResourcesActions = connect((props) => {
},
{
dataIndex: 'onNewRecord',
title: '类型',
title: t('Action type'),
render: (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',
title: '允许操作',
title: t("Allow"),
render: (enabled, action) => (
<Checkbox
checked={enabled}
@ -119,7 +119,7 @@ export const RolesResourcesActions = connect((props) => {
},
{
dataIndex: 'scope',
title: '可操作的数据范围',
title: t("Data scope"),
render: (value, action) =>
!action.onNewRecord && (
<ScopeSelect

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -292,4 +292,94 @@ export default {
"Button title": "按钮标题",
"Button icon": "按钮图标",
"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 React from 'react';
import { PoweredBy } from '../../../powered-by';
import { useSystemSettings } from '../../../system-settings';
export function AuthLayout(props: any) {
const { data } = useSystemSettings();
return (
<div
style={{
@ -11,7 +13,7 @@ export function AuthLayout(props: any) {
paddingTop: '20vh',
}}
>
<h1>NocoBase</h1>
<h1>{data?.data?.title}</h1>
{props.children}
<div
className={css`

View File

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

View File

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

View File

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