mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(phrases): replace Normalize with NormalizeKeyPaths (#192)
This commit is contained in:
parent
9dc0ea32c0
commit
070506f934
4 changed files with 19 additions and 20 deletions
|
@ -24,6 +24,9 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/logto-io/logto/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@silverhand/essentials": "^1.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@silverhand/eslint-config": "^0.4.0",
|
||||
"@silverhand/ts-config": "^0.4.0",
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { NormalizeKeyPaths } from '@silverhand/essentials';
|
||||
|
||||
import en from './locales/en';
|
||||
import zhCN from './locales/zh-cn';
|
||||
import { Normalize, Resource } from './types';
|
||||
import { Resource } from './types';
|
||||
|
||||
export type LogtoErrorCode = Normalize<typeof en.errors>;
|
||||
export type LogtoErrorCode = NormalizeKeyPaths<typeof en.errors>;
|
||||
export type LogtoErrorI18nKey = `errors:${LogtoErrorCode}`;
|
||||
export type Languages = keyof Resource;
|
||||
|
||||
|
|
|
@ -9,21 +9,4 @@ export interface ResourceLanguage {
|
|||
[namespace: string]: ResourceKey;
|
||||
}
|
||||
|
||||
export type ResourceKey =
|
||||
| string
|
||||
| {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/* Copied from react-i18next/ts4.1/index.d.ts */
|
||||
// Normalize single namespace
|
||||
type AppendKeys<K1, K2> = `${K1 & string}.${K2 & string}`;
|
||||
type AppendKeys2<K1, K2> = `${K1 & string}.${Exclude<K2, keyof any[]> & string}`;
|
||||
type Normalize2<T, K = keyof T> = K extends keyof T
|
||||
? T[K] extends Record<string, any>
|
||||
? T[K] extends readonly any[]
|
||||
? AppendKeys2<K, keyof T[K]> | AppendKeys2<K, Normalize2<T[K]>>
|
||||
: AppendKeys<K, keyof T[K]> | AppendKeys<K, Normalize2<T[K]>>
|
||||
: never
|
||||
: never;
|
||||
export type Normalize<T> = keyof T | Normalize2<T>;
|
||||
export type ResourceKey = string | { [key: string]: any };
|
||||
|
|
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
|
@ -126,11 +126,14 @@ importers:
|
|||
packages/phrases:
|
||||
specifiers:
|
||||
'@silverhand/eslint-config': ^0.4.0
|
||||
'@silverhand/essentials': ^1.1.4
|
||||
'@silverhand/ts-config': ^0.4.0
|
||||
eslint: ^8.1.0
|
||||
lint-staged: ^11.1.1
|
||||
prettier: ^2.3.2
|
||||
typescript: ^4.3.5
|
||||
dependencies:
|
||||
'@silverhand/essentials': 1.1.4
|
||||
devDependencies:
|
||||
'@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0
|
||||
'@silverhand/ts-config': 0.4.0_typescript@4.5.3
|
||||
|
@ -3142,6 +3145,14 @@ packages:
|
|||
lodash.orderby: 4.6.0
|
||||
lodash.pick: 4.4.0
|
||||
|
||||
/@silverhand/essentials/1.1.4:
|
||||
resolution: {integrity: sha512-5pHjIz42CjILcqGWhmfP7/RCbmlWIWmj0H3RMJDGW3QKZyNkWawG6gKwtEQ75N0MoZOzXjNE4HD4DK3moPa5sg==}
|
||||
engines: {node: '>=14.15.0', pnpm: '>=6'}
|
||||
dependencies:
|
||||
lodash.orderby: 4.6.0
|
||||
lodash.pick: 4.4.0
|
||||
dev: false
|
||||
|
||||
/@silverhand/ts-config-react/0.4.0_typescript@4.5.3:
|
||||
resolution: {integrity: sha512-8D/VFFFGDrOf4zspfkvasXViOpwC+S/VrJx/rHD7Ztbn8+HPeHQRZeykXI2Tgg/G8cBkmlhW9ufrtCBYElJd+g==}
|
||||
engines: {node: '>=14.15.0'}
|
||||
|
|
Loading…
Add table
Reference in a new issue