Skip to content

Commit

Permalink
refactor(i18n): use @alwatr/type
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Jan 8, 2023
1 parent bd5f11c commit e097b99
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions core/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
"@alwatr/logger": "^0.27.0",
"@alwatr/signal": "^0.27.0",
"tslib": "^2.4.1"
},
"devDependencies": {
"@alwatr/type": "^0.27.0"
}
}
2 changes: 2 additions & 0 deletions core/i18n/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
27 changes: 4 additions & 23 deletions core/i18n/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {L10Resource, Locale} from '@alwatr/type';

export {L10Resource, Locale};

declare global {
interface AlwatrSignals {
'locale-change': Locale;
Expand All @@ -9,29 +13,6 @@ declare global {
}
}

export type LocalCode = `${Lowercase<string>}-${Uppercase<string>}`;

export type L10Resource = Record<string, string> & {
_code: LocalCode;
};

export type Locale = {
/**
* fa-IR, en-US, ...
*/
code: LocalCode;

/**
* fa, en, ...
*/
language: Lowercase<string>;

/**
* ltr, rtl
*/
direction: 'rtl' | 'ltr';
};

export type I18nConfig = {
/**
* Automatically fetch the localization resource from `resourcePath/localCode.json`.
Expand Down
1 change: 1 addition & 0 deletions core/i18n/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"include": ["src/**/*.ts"],
"exclude": [],
"references": [
{"path": "../type"},
{"path": "../logger"},
{"path": "../signal"},
{"path": "../fetch"}
Expand Down
22 changes: 22 additions & 0 deletions core/type/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type LocalCode = `${Lowercase<string>}-${Uppercase<string>}`;

export type L10Resource = Record<string, string> & {
_code: LocalCode;
};

export type Locale = {
/**
* fa-IR, en-US, ...
*/
code: LocalCode;

/**
* fa, en, ...
*/
language: Lowercase<string>;

/**
* ltr, rtl
*/
direction: 'rtl' | 'ltr';
};
1 change: 1 addition & 0 deletions core/type/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit e097b99

Please sign in to comment.