mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 10:42:19 +08:00
fix(auth): allows to set the auth type title translation from server end (#4616)
* fix(auth): allows to set auth type title translation from server end * chore: move tval to utils * chore: mark deprecated * fix: test
This commit is contained in:
parent
b9fda22fb1
commit
0fb18b495f
@ -11,6 +11,10 @@ import i18next, { TFuncKey, TOptions } from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import locale from '../locale';
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* use {@link @nocobase/utils/client#tval} instead
|
||||
*/
|
||||
export function tval(text: TFuncKey | TFuncKey[], options?: TOptions) {
|
||||
if (options) {
|
||||
return `{{t(${JSON.stringify(text)}, ${JSON.stringify(options)})}}`;
|
||||
|
@ -29,3 +29,4 @@ export * from './uid';
|
||||
export * from './url';
|
||||
export { dayjs, lodash };
|
||||
export * from './parseHTML';
|
||||
export * from './i18n';
|
||||
|
17
packages/core/utils/src/i18n.ts
Normal file
17
packages/core/utils/src/i18n.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { TFuncKey, TOptions } from 'i18next';
|
||||
|
||||
export function tval(text: TFuncKey | TFuncKey[], options?: TOptions) {
|
||||
if (options) {
|
||||
return `{{t(${JSON.stringify(text)}, ${JSON.stringify(options)})}}`;
|
||||
}
|
||||
return `{{t(${JSON.stringify(text)})}}`;
|
||||
}
|
@ -33,5 +33,6 @@ export * from './requireModule';
|
||||
export * from './toposort';
|
||||
export * from './uid';
|
||||
export * from './url';
|
||||
export * from './i18n';
|
||||
|
||||
export { dayjs, lodash };
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"Sign in via SMS": "Sign in via SMS",
|
||||
"User will be registered automatically if not exists.": "User will be registered automatically if not exists.",
|
||||
"Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist"
|
||||
"Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist",
|
||||
"SMS": "SMS"
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"Sign in via SMS": "短信登录",
|
||||
"User will be registered automatically if not exists.": "用户不存在时将自动注册。",
|
||||
"Sign up automatically when the user does not exist": "用户不存在时自动注册"
|
||||
"Sign up automatically when the user does not exist": "用户不存在时自动注册",
|
||||
"SMS": "短信"
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
import VerificationPlugin from '@nocobase/plugin-verification';
|
||||
import { InstallOptions, Plugin } from '@nocobase/server';
|
||||
import { resolve } from 'path';
|
||||
import { authType } from '../constants';
|
||||
import { authType, namespace } from '../constants';
|
||||
import { SMSAuth } from './sms-auth';
|
||||
import { tval } from '@nocobase/utils';
|
||||
|
||||
export class PluginAuthSMSServer extends Plugin {
|
||||
afterAdd() {}
|
||||
@ -38,6 +38,7 @@ export class PluginAuthSMSServer extends Plugin {
|
||||
|
||||
this.app.authManager.registerTypes(authType, {
|
||||
auth: SMSAuth,
|
||||
title: tval('SMS', { ns: namespace }),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import { AuthTypeContext, AuthTypesContext, useAuthTypes } from './authType';
|
||||
import { useValuesFromOptions, Options } from './Options';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAuthTranslation } from '../locale';
|
||||
import { Schema } from '@formily/react';
|
||||
|
||||
const useCloseAction = () => {
|
||||
const { setVisible } = useActionContext();
|
||||
@ -81,7 +82,7 @@ export const Authenticator = () => {
|
||||
const types = res?.data?.data || [];
|
||||
return types.map((type: { name: string; title?: string }) => ({
|
||||
key: type.name,
|
||||
label: t(type.title || type.name),
|
||||
label: Schema.compile(type.title || type.name, { t }),
|
||||
value: type.name,
|
||||
}));
|
||||
}),
|
||||
|
@ -17,11 +17,11 @@
|
||||
"Please enter a valid email": "Please enter a valid email",
|
||||
"Please enter your username or email": "Please enter your username or email",
|
||||
"Please enter a password": "Please enter a password",
|
||||
"SMS": "SMS",
|
||||
"Username/Email": "Username/Email",
|
||||
"Auth UID": "Auth UID",
|
||||
"The authentication allows users to sign in via username or email.": "The authentication allows users to sign in via username or email.",
|
||||
"No authentication methods available.": "No authentication methods available.",
|
||||
"The password is inconsistent, please re-enter": "The password is inconsistent, please re-enter",
|
||||
"Sign-in": "Sign-in"
|
||||
"Sign-in": "Sign-in",
|
||||
"Password": "Password"
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
"Please enter a valid email": "请输入有效的邮箱",
|
||||
"Please enter your username or email": "请输入用户名或邮箱",
|
||||
"Please enter a password": "请输入密码",
|
||||
"SMS": "短信",
|
||||
"Username/Email": "用户名/邮箱",
|
||||
"Auth UID": "认证标识",
|
||||
"The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。",
|
||||
"No authentication methods available.": "没有可用的认证方式。",
|
||||
"The password is inconsistent, please re-enter": "密码不一致,请重新输入",
|
||||
"Sign-in": "登录"
|
||||
"Sign-in": "登录",
|
||||
"Password": "密码"
|
||||
}
|
||||
|
@ -38,10 +38,9 @@ describe('actions', () => {
|
||||
|
||||
it('should list authenticator types', async () => {
|
||||
const res = await agent.resource('authenticators').listTypes();
|
||||
expect(res.body.data).toEqual([
|
||||
expect(res.body.data).toMatchObject([
|
||||
{
|
||||
name: 'Email/Password',
|
||||
title: 'Password',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
@ -15,19 +15,16 @@ import { namespace, presetAuthType, presetAuthenticator } from '../preset';
|
||||
import authActions from './actions/auth';
|
||||
import authenticatorsActions from './actions/authenticators';
|
||||
import { BasicAuth } from './basic-auth';
|
||||
import { enUS, zhCN } from './locale';
|
||||
import { AuthModel } from './model/authenticator';
|
||||
import { Storer } from './storer';
|
||||
import { TokenBlacklistService } from './token-blacklist';
|
||||
import { tval } from '@nocobase/utils';
|
||||
|
||||
export class PluginAuthServer extends Plugin {
|
||||
cache: Cache;
|
||||
|
||||
afterAdd() {}
|
||||
async beforeLoad() {
|
||||
this.app.i18n.addResources('zh-CN', namespace, zhCN);
|
||||
this.app.i18n.addResources('en-US', namespace, enUS);
|
||||
|
||||
this.app.db.registerModels({ AuthModel });
|
||||
}
|
||||
|
||||
@ -61,7 +58,7 @@ export class PluginAuthServer extends Plugin {
|
||||
|
||||
this.app.authManager.registerTypes(presetAuthType, {
|
||||
auth: BasicAuth,
|
||||
title: 'Password',
|
||||
title: tval('Password', { ns: namespace }),
|
||||
});
|
||||
// Register actions
|
||||
Object.entries(authActions).forEach(
|
||||
|
@ -10,12 +10,12 @@
|
||||
import { ArrayTable } from '@formily/antd-v5';
|
||||
import { ISchema, useForm } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import {
|
||||
ActionContextProvider,
|
||||
IField,
|
||||
RecordProvider,
|
||||
SchemaComponent,
|
||||
tval,
|
||||
useAPIClient,
|
||||
useActionContext,
|
||||
useCollectionManager_deprecated,
|
||||
|
@ -7,10 +7,10 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { tval } from '@nocobase/client';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
|
||||
const NAMESPACE = 'field-markdown-vditor';
|
||||
|
||||
export function generateNTemplate(key: string) {
|
||||
return tval(key, { ns: NAMESPACE })
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
import { ISchema } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import {
|
||||
SchemaComponentOptions,
|
||||
tval,
|
||||
useActionContext,
|
||||
useRecord,
|
||||
useRequest,
|
||||
|
@ -7,7 +7,8 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { Plugin, tval } from '@nocobase/client';
|
||||
import { Plugin } from '@nocobase/client';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { UsersManagement } from './UsersManagement';
|
||||
import ACLPlugin from '@nocobase/plugin-acl/client';
|
||||
import { RoleUsersManager } from './RoleUsersManager';
|
||||
|
Loading…
x
Reference in New Issue
Block a user