@_tc/template-core 0.2.0-bate.10 → 0.2.0-bate.11

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/AGENT_README.md CHANGED
@@ -423,7 +423,7 @@ import { Button, DataTable, Form, Input, Modal, Select } from '@_tc/template-cor
423
423
  - 组件加载辅助:`renderImportComponent(import('./Page'))` 会用 `React.lazy` + `Suspense` 渲染动态组件。
424
424
  - Schema 通信:`schemaEventBus`、`eventsInfo`、`merge`。
425
425
  - 共享状态:`modeStore`、`schemaStore`、`apiFreezerStore` 及对应 hooks。
426
- - 多语言:`addLanguageResources()` 追加或新增某语种文案,`setLanguage()` 切换语言,React render 中用 `useText()`,非 React 工具代码用 `getText()`,配置文案可写 `$i18n::...`。
426
+ - 多语言:`addLanguageResources()` 追加或新增某语种文案,`setLanguage()` 切换语言。React render 中用 `useText()`,非 React 工具代码用 `getText()`;`$i18n::` 前缀会被去掉后查询资源,无前缀字符串会按原 key 查询,未命中时原样返回。配置文案推荐写 `$i18n::...`,也可写普通字符串。
427
427
  - 主题:`ThemeSwitch` 会同步根节点 `dark` class 和 `localStorage`。
428
428
  - `Input type="password"` 会自动显示密码显隐按钮;`allowClear` 不作用于密码输入。
429
429
  - RAF 风格计时器由 `@tc/common/rafTimer` 提供,浏览器优先使用 RAF,Node/SSR 自动降级到 `setTimeout`。
package/README.md CHANGED
@@ -455,7 +455,9 @@ setLanguage('ja-JP')
455
455
 
456
456
  `addLanguageResources()` 用于追加或新增某个语种的文案,默认会深合并同语种资源;传 `{ merge: false }` 可以替换该语种资源。`setResources(resources, { merge: true })` 可批量合并多语种资源。`LanguageSwitch` 默认会把已注册语种加入选项;需要自定义展示文案时仍可传入 `options`。
457
457
 
458
- React 组件 render 中使用 `useText()` 读取文案。它会订阅语言和资源变化,调用 `setLanguage()` 后组件会自动重渲染:
458
+ React 组件 render 中使用 `useText()` 读取文案。它会订阅语言和资源变化,调用 `setLanguage()` 后组件会自动重渲染。
459
+
460
+ `useText()` / `getText()` 遇到 `$i18n::` 前缀会先去掉前缀再查语言资源;没有前缀时会直接把传入字符串作为 key 查询,查不到才原样返回:
459
461
 
460
462
  ```tsx
461
463
  import { useText } from '@_tc/template-core/fe'
@@ -463,7 +465,12 @@ import { useText } from '@_tc/template-core/fe'
463
465
  function ProductTitle() {
464
466
  const text = useText()
465
467
 
466
- return <h1>{text('$i18n::app.product.menu')}</h1>
468
+ return (
469
+ <>
470
+ <h1>{text('$i18n::app.product.menu')}</h1>
471
+ <span>{text('Plain title')}</span>
472
+ </>
473
+ )
467
474
  }
468
475
  ```
469
476
 
@@ -25,8 +25,8 @@ var registerFrontendI18nResources = async (resources) => {
25
25
  });
26
26
  };
27
27
  var getText = (key, fillingData, options) => {
28
- if (key.includes("$i18n::")) return i18n(key.replace(i18nKeyPrefix, ""), fillingData, options);
29
- return key;
28
+ if (key.startsWith("$i18n::")) return i18n(key.slice(i18nKeyPrefix.length), fillingData, options);
29
+ return i18n(key, fillingData, options);
30
30
  };
31
31
  var t = i18n;
32
32
  //#endregion
@@ -6,8 +6,8 @@ import { useCallback } from "react";
6
6
  var useText = () => {
7
7
  const translate = useI18n();
8
8
  return useCallback((key, fillingData, options) => {
9
- if (key.includes("$i18n::")) return translate(key.replace(i18nKeyPrefix, ""), fillingData, options);
10
- return key;
9
+ if (key.startsWith("$i18n::")) return translate(key.slice(i18nKeyPrefix.length), fillingData, options);
10
+ return translate(key, fillingData, options);
11
11
  }, [translate]);
12
12
  };
13
13
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.2.0-bate.10",
3
+ "version": "0.2.0-bate.11",
4
4
  "description": "A full-stack TypeScript admin framework powered by Koa, React, and Vite - monorepo root",
5
5
  "types": "./types/index.d.ts",
6
6
  "exports": {