0
Fork 0
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 ()

This commit is contained in:
Darcy Ye 2022-07-25 18:15:59 +08:00 committed by GitHub
parent 220ba58364
commit 26d300c65c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 288 additions and 94 deletions
packages
console/src/pages/Connectors/components/Guide
phrases
pnpm-lock.yaml

View file

@ -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' });

View file

@ -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",

View file

@ -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>;

View file

@ -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

File diff suppressed because it is too large Load diff