Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/web-vue/components/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ref, reactive, inject, computed } from 'vue';
import { isString } from '../_utils/is';
import { configProviderInjectionKey } from '../config-provider/context';
import type { ArcoI18nMessages, ArcoLang } from './interface';
import type { ArcoI18nKey, ArcoI18nMessages, ArcoLang } from './interface';
import zhCN from './lang/zh-cn';

const LOCALE = ref('zh-CN');
Expand Down Expand Up @@ -55,7 +55,7 @@ export const useI18n = () => {
);
const locale = computed(() => i18nMessage.value.locale);

const transform = (key: string, ...args: any[]): string => {
const transform = (key: ArcoI18nKey, ...args: any[]): string => {
const keyArray = key.split('.');
let temp: any = i18nMessage.value;

Expand Down
17 changes: 17 additions & 0 deletions packages/web-vue/components/locale/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,20 @@ export interface ArcoLang {
}

export type ArcoI18nMessages = Record<string, ArcoLang>;

type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (
x: infer R
) => any
? R
: never;
type Flatten<T, Prefix extends string = ''> = UnionToIntersection<
{
[K in keyof T & string]: T[K] extends Record<string, string>
? T[K] extends () => void | any[] | null
? { [P in `${Prefix}${K}`]: T[K] }
: Flatten<T[K], `${Prefix}${K}.`>
: { [P in `${Prefix}${K}`]: T[K] };
}[keyof T & string]
>;

export type ArcoI18nKey = keyof Flatten<ArcoLang>;