create-aomex 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-aomex",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "repository": "git@github.com:aomex/create-aomex.git",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,26 +31,26 @@
31
31
  "bin": "dist/index.js",
32
32
  "packageManager": "pnpm@9.4.0",
33
33
  "dependencies": {
34
- "@aomex/console": "^3.2.2",
35
- "@aomex/core": "^3.2.2",
34
+ "@aomex/console": "^3.2.3",
35
+ "@aomex/core": "^3.2.3",
36
36
  "@inquirer/prompts": "^6.0.1",
37
37
  "lodash.kebabcase": "^4.1.1",
38
38
  "yargs-parser": "^21.1.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@aomex/async-trace": "^3.2.2",
42
- "@aomex/cache": "^3.2.2",
43
- "@aomex/cache-redis-adapter": "^3.2.2",
44
- "@aomex/compress": "^3.2.2",
45
- "@aomex/cors": "^3.2.2",
46
- "@aomex/cron": "^3.2.2",
47
- "@aomex/etag": "^3.2.2",
48
- "@aomex/helmet": "^3.2.2",
49
- "@aomex/http-logger": "^3.2.2",
50
- "@aomex/openapi": "^3.2.2",
51
- "@aomex/response-time": "^3.2.2",
52
- "@aomex/swagger-ui": "^3.2.2",
53
- "@aomex/web": "^3.2.2",
41
+ "@aomex/async-trace": "^3.2.3",
42
+ "@aomex/cache": "^3.2.3",
43
+ "@aomex/cache-redis-adapter": "^3.2.3",
44
+ "@aomex/compress": "^3.2.3",
45
+ "@aomex/cors": "^3.2.3",
46
+ "@aomex/cron": "^3.2.3",
47
+ "@aomex/etag": "^3.2.3",
48
+ "@aomex/helmet": "^3.2.3",
49
+ "@aomex/http-logger": "^3.2.3",
50
+ "@aomex/openapi": "^3.2.3",
51
+ "@aomex/response-time": "^3.2.3",
52
+ "@aomex/swagger-ui": "^3.2.3",
53
+ "@aomex/web": "^3.2.3",
54
54
  "@prisma/client": "^5.17.0",
55
55
  "@types/lodash.kebabcase": "^4.1.9",
56
56
  "@types/node": "^20.14.12",
@@ -42,6 +42,7 @@
42
42
  ├─ src/
43
43
  ├─ commanders/ 指令控制层
44
44
  ├─ configs/ 不同环境下的配置
45
+ ├─ i18n/ 国际化语言包
45
46
  ├─ middleware/ 中间件
46
47
  ├─ routers/ 路由控制层
47
48
  ├─ services/ 业务逻辑层
@@ -4,7 +4,7 @@ import { traceMiddleware } from '@aomex/async-trace';
4
4
  import { cache } from './services/cache.service';
5
5
 
6
6
  const app = new ConsoleApp({
7
- locale: 'zh_CN',
7
+ language: 'zh_CN',
8
8
  mount: [
9
9
  cron({
10
10
  commanders: './src/commanders',
@@ -0,0 +1,10 @@
1
+ import { I18n } from '@aomex/core';
2
+ import { locales } from './locales';
3
+
4
+ export const i18n = new I18n({
5
+ locales,
6
+ defaultLanguage: 'zh_CN',
7
+ });
8
+
9
+ // 检查不同语言包的缺失字段(相对于默认语言)
10
+ export type I18nMissingKeys = typeof i18n.missingKeys;
@@ -0,0 +1,6 @@
1
+ import { I18n } from '@aomex/core';
2
+ import { zh } from './zh-cn';
3
+
4
+ export const en = I18n.satisfies(zh).define({
5
+ hello: 'Hello World',
6
+ });
@@ -0,0 +1,7 @@
1
+ import { en } from './en-us';
2
+ import { zh } from './zh-cn';
3
+
4
+ export const locales = {
5
+ zh_CN: zh,
6
+ en_US: en,
7
+ };
@@ -0,0 +1,18 @@
1
+ import { I18n } from '@aomex/core';
2
+
3
+ export const zh = I18n.define({
4
+ hello: I18n.message('你好,世界。{{count}}', {
5
+ count: {
6
+ type: 'plural',
7
+ plural: {
8
+ '1': '这是你第一次访问',
9
+ '2-4': '你表现的很熟练',
10
+ 'n': '你是个老司机',
11
+ },
12
+ },
13
+ }),
14
+ button: {
15
+ ok: '确定',
16
+ cancel: '取消',
17
+ },
18
+ });
@@ -1,6 +1,7 @@
1
1
  import { rule } from '@aomex/core';
2
2
  import { response, Router } from '@aomex/web';
3
3
  import { hello } from '@middleware/hello.middleware';
4
+ import { i18n } from '../i18n';
4
5
 
5
6
  export const router = new Router();
6
7
 
@@ -13,6 +14,6 @@ router.get('/', {
13
14
  }),
14
15
  ],
15
16
  action: (ctx) => {
16
- ctx.send(`hello world, ${ctx.visitCount}`);
17
+ ctx.send(`${i18n.t('hello', { count: ctx.visitCount })}`);
17
18
  },
18
19
  });
@@ -8,10 +8,16 @@ import { responseTime } from '@aomex/response-time';
8
8
  import { traceMiddleware } from '@aomex/async-trace';
9
9
  import { swaggerUI } from '@aomex/swagger-ui';
10
10
  import { generateOpenapi } from '@aomex/openapi';
11
+ import { I18n, middleware } from '@aomex/core';
11
12
 
12
13
  export const app = new WebApp({
13
- locale: 'zh_CN',
14
+ language: 'zh_CN',
14
15
  mount: [
16
+ middleware.web((ctx, next) => {
17
+ // 动态选择i18n语言包
18
+ const language = ctx.request.accept.language()[0] || 'zh_CN';
19
+ return I18n.provider(language, next);
20
+ }),
15
21
  httpLogger(),
16
22
  responseTime,
17
23
  traceMiddleware('生命周期', async (_record) => {