2022-10-10 09:43:13 +08:00
|
|
|
import { fallback } from '@logto/core-kit';
|
2022-10-21 13:14:17 +08:00
|
|
|
import type { LanguageTag } from '@logto/language-kit';
|
|
|
|
import { languages } from '@logto/language-kit';
|
|
|
|
import type { NormalizeKeyPaths } from '@silverhand/essentials';
|
2022-10-10 09:43:13 +08:00
|
|
|
import { z } from 'zod';
|
2022-01-24 17:26:08 +08:00
|
|
|
|
2021-07-28 01:13:51 +08:00
|
|
|
import en from './locales/en';
|
2022-08-14 14:36:10 +02:00
|
|
|
import fr from './locales/fr';
|
2022-07-30 23:48:50 +09:00
|
|
|
import koKR from './locales/ko-kr';
|
2022-09-02 00:23:54 +01:00
|
|
|
import ptPT from './locales/pt-pt';
|
2022-07-30 16:48:45 +03:00
|
|
|
import trTR from './locales/tr-tr';
|
2021-07-28 01:13:51 +08:00
|
|
|
import zhCN from './locales/zh-cn';
|
2022-10-21 13:14:17 +08:00
|
|
|
import type { LocalPhrase } from './types';
|
2022-10-10 09:43:13 +08:00
|
|
|
|
|
|
|
export type { LocalPhrase } from './types';
|
|
|
|
|
|
|
|
export type I18nKey = NormalizeKeyPaths<typeof en.translation>;
|
|
|
|
|
|
|
|
export const builtInLanguages = ['en', 'fr', 'pt-PT', 'zh-CN', 'ko-KR', 'tr-TR'] as const;
|
|
|
|
|
|
|
|
export const builtInLanguageOptions = builtInLanguages.map((languageTag) => ({
|
|
|
|
value: languageTag,
|
|
|
|
title: languages[languageTag],
|
|
|
|
}));
|
|
|
|
|
|
|
|
export const builtInLanguageTagGuard = z.enum(builtInLanguages);
|
|
|
|
|
|
|
|
export type BuiltInLanguageTag = z.infer<typeof builtInLanguageTagGuard>;
|
2021-07-28 01:13:51 +08:00
|
|
|
|
2022-07-15 17:03:07 +08:00
|
|
|
export type Errors = typeof en.errors;
|
|
|
|
export type LogtoErrorCode = NormalizeKeyPaths<Errors>;
|
2021-08-14 21:39:37 +08:00
|
|
|
export type LogtoErrorI18nKey = `errors:${LogtoErrorCode}`;
|
2022-10-10 09:43:13 +08:00
|
|
|
|
2022-03-04 12:47:02 +08:00
|
|
|
export type AdminConsoleKey = NormalizeKeyPaths<typeof en.translation.admin_console>;
|
2021-07-28 01:13:51 +08:00
|
|
|
|
2022-10-10 09:43:13 +08:00
|
|
|
export const getDefaultLanguageTag = (languages: string): LanguageTag =>
|
|
|
|
builtInLanguageTagGuard.or(fallback<LanguageTag>('en')).parse(languages);
|
|
|
|
|
|
|
|
export const isBuiltInLanguageTag = (language: string): language is BuiltInLanguageTag =>
|
|
|
|
builtInLanguageTagGuard.safeParse(language).success;
|
|
|
|
|
|
|
|
export type Resource = Record<BuiltInLanguageTag, LocalPhrase>;
|
|
|
|
|
2021-07-28 01:13:51 +08:00
|
|
|
const resource: Resource = {
|
2022-08-30 16:53:49 +08:00
|
|
|
en,
|
|
|
|
fr,
|
2022-09-02 00:23:54 +01:00
|
|
|
'pt-PT': ptPT,
|
2022-08-30 16:53:49 +08:00
|
|
|
'zh-CN': zhCN,
|
|
|
|
'ko-KR': koKR,
|
|
|
|
'tr-TR': trTR,
|
2021-07-28 01:13:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default resource;
|