From e097b99f1f3e1fa2d30978f5f472fc3d5890d7e4 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sun, 8 Jan 2023 13:52:10 +0330 Subject: [PATCH] refactor(i18n): use `@alwatr/type` --- core/i18n/package.json | 3 +++ core/i18n/src/i18n.ts | 2 ++ core/i18n/src/type.ts | 27 ++++----------------------- core/i18n/tsconfig.json | 1 + core/type/src/i18n.ts | 22 ++++++++++++++++++++++ core/type/src/index.ts | 1 + 6 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 core/type/src/i18n.ts diff --git a/core/i18n/package.json b/core/i18n/package.json index 226d37b2f..5287a957b 100644 --- a/core/i18n/package.json +++ b/core/i18n/package.json @@ -36,5 +36,8 @@ "@alwatr/logger": "^0.27.0", "@alwatr/signal": "^0.27.0", "tslib": "^2.4.1" + }, + "devDependencies": { + "@alwatr/type": "^0.27.0" } } diff --git a/core/i18n/src/i18n.ts b/core/i18n/src/i18n.ts index b0a6d99a2..a74b9789b 100644 --- a/core/i18n/src/i18n.ts +++ b/core/i18n/src/i18n.ts @@ -4,6 +4,8 @@ import {SignalInterface} from '@alwatr/signal'; import type {I18nConfig, L10Resource, Locale} from './type.js'; +export * from './type.js'; + const logger = createLogger('alwatr/i18n'); globalAlwatr.registeredList.push({ diff --git a/core/i18n/src/type.ts b/core/i18n/src/type.ts index b61e33c15..04c8a6f61 100644 --- a/core/i18n/src/type.ts +++ b/core/i18n/src/type.ts @@ -1,3 +1,7 @@ +import type {L10Resource, Locale} from '@alwatr/type'; + +export {L10Resource, Locale}; + declare global { interface AlwatrSignals { 'locale-change': Locale; @@ -9,29 +13,6 @@ declare global { } } -export type LocalCode = `${Lowercase}-${Uppercase}`; - -export type L10Resource = Record & { - _code: LocalCode; -}; - -export type Locale = { - /** - * fa-IR, en-US, ... - */ - code: LocalCode; - - /** - * fa, en, ... - */ - language: Lowercase; - - /** - * ltr, rtl - */ - direction: 'rtl' | 'ltr'; -}; - export type I18nConfig = { /** * Automatically fetch the localization resource from `resourcePath/localCode.json`. diff --git a/core/i18n/tsconfig.json b/core/i18n/tsconfig.json index 891f4a867..3ed144cb7 100644 --- a/core/i18n/tsconfig.json +++ b/core/i18n/tsconfig.json @@ -10,6 +10,7 @@ "include": ["src/**/*.ts"], "exclude": [], "references": [ + {"path": "../type"}, {"path": "../logger"}, {"path": "../signal"}, {"path": "../fetch"} diff --git a/core/type/src/i18n.ts b/core/type/src/i18n.ts new file mode 100644 index 000000000..05507cc15 --- /dev/null +++ b/core/type/src/i18n.ts @@ -0,0 +1,22 @@ +export type LocalCode = `${Lowercase}-${Uppercase}`; + +export type L10Resource = Record & { + _code: LocalCode; +}; + +export type Locale = { + /** + * fa-IR, en-US, ... + */ + code: LocalCode; + + /** + * fa, en, ... + */ + language: Lowercase; + + /** + * ltr, rtl + */ + direction: 'rtl' | 'ltr'; +}; diff --git a/core/type/src/index.ts b/core/type/src/index.ts index 8d17fadec..96a3e6360 100644 --- a/core/type/src/index.ts +++ b/core/type/src/index.ts @@ -2,6 +2,7 @@ export * from './chat.js'; export * from './service-response.js'; export * from './storage.js'; export * from './global.js'; +export * from './i18n.js'; export * from './type-helper.js'; Alwatr.registeredList.push({