Skip to content

Commit d80c2bf

Browse files
committed
fix: 增加碰撞框选的文字提示并支持国际化提示,框选距离增加最小阈值条件显示
1 parent b1de2fa commit d80c2bf

8 files changed

Lines changed: 58 additions & 100 deletions

File tree

.trae/skills/manage-translations/SKILL.md

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ app/src/locales/
1818
├── zh_CN.yml # 简体中文
1919
├── zh_TW.yml # 繁体中文
2020
├── zh_TWC.yml # 接地气繁体中文
21+
├── ... # 其他语言翻译文件
2122
└── README.md # 翻译系统说明
2223
```
2324

@@ -28,97 +29,3 @@ app/src/locales/
2829
```bash
2930
ls app/src/locales/*.yml
3031
```
31-
32-
## 添加新翻译
33-
34-
### 1. 确定翻译键名
35-
36-
翻译使用层级结构,通常按功能模块组织:
37-
38-
```yaml
39-
# 基本结构
40-
moduleName:
41-
featureName:
42-
title: "标题文本"
43-
description: "描述文本"
44-
```
45-
46-
### 2. 在所有语言文件中添加
47-
48-
为每个 `.yml` 文件添加对应的翻译。例如添加一个设置项的翻译:
49-
50-
**zh_CN.yml:**
51-
52-
```yaml
53-
settings:
54-
enableNewFeature:
55-
title: "启用新功能"
56-
description: "开启后将启用新功能特性"
57-
options:
58-
option1: "选项一"
59-
option2: "选项二"
60-
```
61-
62-
**en.yml:**
63-
64-
```yaml
65-
settings:
66-
enableNewFeature:
67-
title: "Enable New Feature"
68-
description: "Enable to activate the new feature"
69-
options:
70-
option1: "Option 1"
71-
option2: "Option 2"
72-
```
73-
74-
**其他语言文件同理...**
75-
76-
### 3. 翻译内容规范
77-
78-
- **title**: 简短标题,3-10个字
79-
- **description**: 详细描述,可以包含多行(使用 `|`)
80-
- **options**: 仅枚举类型需要,列出所有选项的显示文本
81-
82-
## 翻译使用方式
83-
84-
### 在代码中使用
85-
86-
```typescript
87-
import i18next from "i18next";
88-
89-
// 简单翻译
90-
const title = i18next.t("settings.enableNewFeature.title");
91-
92-
// 带参数的翻译
93-
const message = i18next.t("common.deleted", { count: 5 });
94-
95-
// 指定命名空间(如 keyBinds)
96-
const keyBindTitle = i18next.t("saveFile.title", { ns: "keyBinds", defaultValue: "" });
97-
```
98-
99-
### 在 React 组件中使用
100-
101-
```tsx
102-
import { useTranslation } from "react-i18next";
103-
104-
function MyComponent() {
105-
const { t } = useTranslation();
106-
107-
return <div>{t("settings.enableNewFeature.title")}</div>;
108-
}
109-
```
110-
111-
## 添加新语言
112-
113-
1. 在 `app/src/locales/` 目录下创建新的 `.yml` 文件
114-
2. 复制现有语言文件(如 `en.yml`)作为模板
115-
3. 将所有值翻译为目标语言
116-
4. 在语言配置中添加新语言(如有语言选择功能)
117-
118-
## 注意事项
119-
120-
1. **保持键名一致**: 所有语言文件中的键名必须完全一致
121-
2. **不要遗漏**: 添加新翻译时,确保为所有语言文件都添加
122-
3. **使用英文作为后备**: 如果某个翻译缺失,系统会回退到英文
123-
4. **参数占位符**: 使用 `{{paramName}}` 语法添加可变参数
124-
5. **多行文本**: 使用 `|` 符号表示多行文本

app/src/core/render/canvas2d/renderer.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { isFrame, isMac } from "@/utils/platform";
1111
import { Color, mixColors, Vector } from "@graphif/data-structures";
1212
import { CubicBezierCurve, Rectangle } from "@graphif/shapes";
1313
import { GlobalMaskRenderer } from "./utilsRenderer/globalMaskRenderer";
14+
import i18next from "i18next";
1415

1516
/**
1617
* 渲染器
@@ -215,6 +216,12 @@ export class Renderer {
215216
this.project.stageStyleManager.currentStyle.SelectRectangleBorder,
216217
);
217218
}
219+
220+
// 只有当移动距离超过阈值时才显示文字提示
221+
const moveDistance = this.project.rectangleSelect.getSelectMoveDistance();
222+
const minMoveDistance = 10; // 最小移动距离阈值
223+
const shouldShowText = moveDistance > minMoveDistance;
224+
218225
const selectMode = this.project.rectangleSelect.getSelectMode();
219226
if (selectMode === "intersect") {
220227
this.project.shapeRenderer.renderRect(
@@ -223,6 +230,16 @@ export class Renderer {
223230
this.project.stageStyleManager.currentStyle.SelectRectangleBorder,
224231
1,
225232
);
233+
// 碰撞框选的提示
234+
if (shouldShowText) {
235+
const text = i18next.t("rectangleSelect.intersect", { ns: "renderer", defaultValue: "" });
236+
this.project.textRenderer.renderText(
237+
text,
238+
this.transformWorld2View(rectangle.leftBottom).add(new Vector(20, 10)),
239+
10,
240+
this.project.stageStyleManager.currentStyle.SelectRectangleBorder,
241+
);
242+
}
226243
} else if (selectMode === "contain") {
227244
this.project.shapeRenderer.renderRect(
228245
this.transformWorld2View(rectangle),
@@ -236,12 +253,15 @@ export class Renderer {
236253
1,
237254
);
238255
// 完全覆盖框选的提示
239-
this.project.textRenderer.renderText(
240-
"完全覆盖框选",
241-
this.transformWorld2View(rectangle.leftBottom).add(new Vector(20, 10)),
242-
10,
243-
this.project.stageStyleManager.currentStyle.SelectRectangleBorder,
244-
);
256+
if (shouldShowText) {
257+
const text = i18next.t("rectangleSelect.contain", { ns: "renderer", defaultValue: "" });
258+
this.project.textRenderer.renderText(
259+
text,
260+
this.transformWorld2View(rectangle.leftBottom).add(new Vector(20, 10)),
261+
10,
262+
this.project.stageStyleManager.currentStyle.SelectRectangleBorder,
263+
);
264+
}
245265
}
246266
}
247267
// if (Stage.selectMachine.isUsing && Stage.selectMachine.selectingRectangle) {

app/src/core/service/controlService/rectangleSelectEngine/rectangleSelectEngine.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,9 @@ export class RectangleSelect {
230230
return Settings.rectangleSelectWhenLeft;
231231
}
232232
}
233+
234+
// 获取框选的移动距离
235+
public getSelectMoveDistance(): number {
236+
return this.selectStartLocation.distance(this.selectEndLocation);
237+
}
233238
}

app/src/locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ settings:
855855
description: |
856856
When enabled, matching keyboard shortcut hints will be displayed when pressing modifier keys (Ctrl/Alt/Shift/Win on Windows or ⌘/⌥/⇧/⌃ on Mac).
857857
Hold the modifier key to view the first page of shortcuts, release and press again to page through more.
858+
renderer:
859+
rectangleSelect:
860+
intersect: Intersection Select
861+
contain: Contain Select
862+
858863
plugins:
859864
welcome:
860865
title: Welcome to the Plugin System

app/src/locales/id.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ settings:
946946
Saat diaktifkan, petunjuk tombol pintas yang cocok akan ditampilkan saat menekan tombol modifikasi (Ctrl/Alt/Shift/Win di Windows atau ⌘/⌥/⇧/⌃ di Mac).
947947
Tahan tombol modifikasi untuk melihat halaman pertama tombol pintas, lepaskan dan tekan lagi untuk melihat lebih banyak.
948948
949+
renderer:
950+
rectangleSelect:
951+
intersect: Seleksi Tabrakan
952+
contain: Seleksi Penuh
953+
949954
effects:
950955
CircleChangeRadiusEffect:
951956
title: Efek Perubahan Radius Lingkaran

app/src/locales/zh_CN.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ settings:
962962
按住修饰键不放可查看第一页快捷键,松开后再次按下可翻页查看更多。
963963
964964
965+
renderer:
966+
rectangleSelect:
967+
intersect: 碰撞框选
968+
contain: 完全覆盖框选
969+
965970
effects:
966971
CircleChangeRadiusEffect:
967972
title: 圆形变换半径效果

app/src/locales/zh_TW.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ settings:
962962
按住修飾鍵不放可查看第一頁快捷鍵,鬆開後再次按下可翻頁查看更多。
963963
964964
965+
renderer:
966+
rectangleSelect:
967+
intersect: 碰撞框選
968+
contain: 完全覆蓋框選
969+
965970
effects:
966971
CircleChangeRadiusEffect:
967972
title: 圓形變換半徑效果

app/src/locales/zh_TWC.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,12 @@ settings:
969969
description: |
970970
開啟後,當按下 Ctrl/Alt/Shift/Win(Windows)或 ⌘/⌥/⇧/⌃(Mac)等修飾鍵時,會顯示匹配的快捷鍵提示。
971971
按住修飾鍵不放可查看第一頁快捷鍵,鬆開後再次按下可翻頁查看更多。
972+
973+
renderer:
974+
rectangleSelect:
975+
intersect: 碰撞框選
976+
contain: 完全覆蓋框選
977+
972978
effects:
973979
CircleChangeRadiusEffect:
974980
title: 圆形变换半径效果

0 commit comments

Comments
 (0)