mirror of
https://github.com/logto-io/logto.git
synced 2025-03-24 22:41:28 -05:00
refactor(console): refactor the logic of getting connector name in preferred language (#1666)
This commit is contained in:
parent
220ba58364
commit
26d300c65c
5 changed files with 288 additions and 94 deletions
packages
pnpm-lock.yaml
|
@ -1,3 +1,4 @@
|
|||
import { languageEnumGuard } from '@logto/phrases';
|
||||
import { ConnectorDto, ConnectorType } from '@logto/schemas';
|
||||
import { conditional } from '@silverhand/essentials';
|
||||
import i18next from 'i18next';
|
||||
|
@ -31,10 +32,10 @@ const Guide = ({ connector, onClose }: Props) => {
|
|||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
const { id: connectorId, type: connectorType, name, configTemplate, readme } = connector;
|
||||
|
||||
const locale = i18next.language;
|
||||
const localeRaw = i18next.language;
|
||||
const result = languageEnumGuard.safeParse(localeRaw);
|
||||
const connectorName = result.success ? name[result.data] : name.en;
|
||||
|
||||
const foundName = Object.entries(name).find(([lang]) => lang === locale);
|
||||
const connectorName = foundName ? foundName[1] : name.en;
|
||||
const isSocialConnector =
|
||||
connectorType !== ConnectorType.SMS && connectorType !== ConnectorType.Email;
|
||||
const methods = useForm<GuideForm>({ reValidateMode: 'onBlur' });
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
"url": "https://github.com/logto-io/logto/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@silverhand/essentials": "^1.1.4"
|
||||
"@silverhand/essentials": "^1.1.4",
|
||||
"zod": "^3.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@silverhand/eslint-config": "^0.17.0",
|
||||
|
|
|
@ -4,7 +4,7 @@ import en from './locales/en';
|
|||
import zhCN from './locales/zh-cn';
|
||||
import { Resource, Language } from './types';
|
||||
|
||||
export { Language, languageOptions } from './types';
|
||||
export { Language, languageOptions, languageEnumGuard } from './types';
|
||||
export type Translation = typeof en.translation;
|
||||
export type Errors = typeof en.errors;
|
||||
export type LogtoErrorCode = NormalizeKeyPaths<Errors>;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
|
||||
import { z } from 'zod';
|
||||
|
||||
/* Copied from i18next/index.d.ts */
|
||||
export type Resource = Record<Language, ResourceLanguage>;
|
||||
|
@ -14,6 +15,8 @@ export enum Language {
|
|||
Chinese = 'zh-CN',
|
||||
}
|
||||
|
||||
export const languageEnumGuard = z.nativeEnum(Language);
|
||||
|
||||
export const languageOptions = [
|
||||
{ value: Language.English, title: 'English' },
|
||||
{ value: Language.Chinese, title: '中文' },
|
||||
|
|
367
pnpm-lock.yaml
generated
367
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue