docs: add Simplified Chinese translation for data structure garden - #1589
docs: add Simplified Chinese translation for data structure garden#1589lllllbbbbbxxx wants to merge 3 commits into
Conversation
lirenjie95
left a comment
There was a problem hiding this comment.
Thanks for this thorough translation! I reviewed the full file against the English source. Overall quality is good: the code blocks are character-identical to the English version (only comments translated), all links, frontmatter, and AnnotatedLine slots are intact, and the core terminology (对象/属性/索引/遍历/生命周期) is accurate and mostly consistent.
I've left inline comments for a handful of minor omissions and some translationese/awkward phrasing. The most notable ones:
- Line 498: the for-loop termination condition from the English text was dropped, which affects technical accuracy.
- Line 336: "绘制花朵的属性" mistranslates "draw the attributes of a flower" — the English means drawing the flower's parts (petals, center), not object properties.
- Line 91: the code literal
"lightblue"was turned into natural language (浅蓝色). - Minor consistency items: 帧速率 vs 帧率 (other zh-Hans tutorials use 帧率), 用户 vs 你 when addressing the reader, 20 朵花 vs 20 个花朵对象, a double space at line 622, and a missing space after
//at line 509.
None of these are blockers — with the inline suggestions addressed, this should be good to go. Nice work!
|
|
||
|  | ||
|
|
||
| 在本教程中,你将使用 p5.js 来模拟一个[交互式花园](https://editor.p5js.org/ptiarram/sketches/8xWVCzmn2)。在这个项目中,画布上会出现 20 朵随机生成的花朵,每朵花都有不同的颜色和大小。用户还可以点击画布添加新的花朵,让花园更加丰富。每朵花都会播放凋谢动画,逐渐缩小并消失,就像花朵自然凋谢一样。 |
There was a problem hiding this comment.
原文 "new, unique flowers" 中的 "unique" 没有译出,建议补上,如"用户还可以点击画布添加新的、独特的花朵"。另外两点:1) 这里用"用户",而全篇大多以"你"称呼读者,建议统一为"你";2) "每朵花都会播放凋谢动画"搭配略怪(花自己不会"播放"动画),可改为"每朵花都有凋谢动画,会逐渐缩小直至消失"。
| console.log(flower); | ||
| ``` | ||
|
|
||
| - 将背景色设置为浅蓝色。 |
There was a problem hiding this comment.
原文是 Set the background to "lightblue".,代码字面量 "lightblue" 被译成了自然语言"浅蓝色",读者照做时需要自己猜字符串值。建议保留字面量:"将背景色设置为 "lightblue""。"
| - 花朵的 x 坐标(`flower.x`) | ||
| - 花朵的 y 坐标(`flower.y`) | ||
|
|
||
| 由于这些值代表字符串和数字,因此可以像使用变量名访问其存储的值一样,在 [`text()`](/reference/p5/text) 函数中使用它们。 |
There was a problem hiding this comment.
语序照搬英文("similar to the way variable names are used..."),比较拗口。建议改为:"由于这些值是字符串和数字,因此可以像普通变量一样,直接在 text() 函数中使用它们。"
|
|
||
| 现在,让我们定义一个可以在画布上显示不同花朵的函数。我们将定义一个 `createFlower()` 函数,以便自定义我们创建的花朵对象。我们需要确保可以更改不同花朵的 x 和 y 坐标,以及它们的大小和颜色。一种方法是为花朵对象添加 `size` 和 `color` 属性。在这个项目中,我们还希望花朵出现一段时间后消失。为此,我们将为花朵对象添加一个 `lifespan` 属性。 | ||
|
|
||
| 我们希望 `createFlower()` 函数在被调用时返回信息,就像内置的 `text()` 函数在画布上返回文本一样。因此,我们必须指定一个[返回值](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Return_values)。使用*返回值*是将函数计算出的信息保存到变量或数组中的好方法。 |
There was a problem hiding this comment.
"在被调用时返回"是被动直译。建议:"我们希望调用 createFlower() 时能返回信息……"。另外,原文 "just like the built-in text() function returns text on the canvas" 译作"返回文本"容易与 return value 混淆,译成"在画布上显示文本"更贴切。
| ellipse(myFlower.x, myFlower.y, myFlower.size); | ||
| ``` | ||
|
|
||
| - 通过将帧速率更改为每秒一帧来降低每朵花出现的速率。在 [`setup()`](/reference/p5/setup) 函数中,添加: `frameRate(1);`。 |
There was a problem hiding this comment.
术语一致性:仓库已有的简体中文教程(如 variables-and-change、repeating-with-loops)统一使用"帧率",这里的"帧速率"建议改为"帧率"。
| background(220); | ||
| let y = 50; | ||
|
|
||
| // 使用 for..of 循环依次访问每个元素。 |
There was a problem hiding this comment.
原文注释是 "// Use the special for loop to look at each element as a variable.","把每个元素当作一个变量来看待"的含义丢失了,而这正是 for..of 循环的教学要点(下文 "Declare a variable to store the current element" 与之呼应)。建议:"// 使用 for..of 循环将每个元素作为变量依次访问。"
| function flowerPower() {} | ||
| ``` | ||
|
|
||
| - 在 `flowerPower()` 函数内部,使用 `for` 循环创建 20 个 花朵对象,并将它们添加到 `flowers` 数组中。 |
There was a problem hiding this comment.
"创建 20 个 花朵对象"中"个"后多了一个空格。另外全文"20 朵花"和"20 个花朵对象"混用(第 640 行还有"每个花元素"),建议统一表述。
|
|
||
| - 在 `for` 循环内,减小花朵对象的 `size` 和 `lifespan` 以模拟凋谢。 | ||
|
|
||
| 添加一个凋谢动画效果,在 `drawFlower()` 函数绘制完花朵后,花朵尺寸会缩小 1%。我们通过将当前尺寸乘以 0.99 并将结果存储回花朵的 `size` 属性来创建凋谢效果。然后,递减花朵的生命周期并将结果存储回花朵的 `lifespan` 属性。使用[乘法赋值运算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#assignment_operators)和[递减运算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Decrement),语法如下: |
There was a problem hiding this comment.
"存储回"连用两次较生硬,"递减生命周期"搭配不当(decrement 的对象是数值)。建议:"我们把当前尺寸乘以 0.99,再存回花朵的 size 属性,以此实现凋谢效果。然后把生命周期减 1,同样存回花朵的 lifespan 属性。"
|
|
||
| ## 步骤 8:使用 `mousePressed()` 向数组添加更多花朵 | ||
|
|
||
| 最后,让我们使用 [`mousePressed()`](/reference/p5/mousePressed), [`mouseX`](/reference/p5/mouseX),和 [`mouseY`](/reference/p5/mouseY) 向画布添加更多花朵。每次点击画布时,都会向花朵数组中添加一个新的花朵对象。 |
There was a problem hiding this comment.
"mousePressed(), mouseX,和 mouseY"——顿号后直接接"和"是英文 Oxford comma 的残留,应改为:"mousePressed()、mouseX 和 mouseY"。
|
|
||
| 恭喜你完成数据结构花园教程! | ||
|
|
||
| 在本教程中,你学习了 JavaScript 对象和数组的基本概念,并用它们创建了一个动态、可交互的花园。使用数组可以帮助你高效管理多个对象及其各自的属性和行为,也为之后构建更复杂的交互程序打下基础。 |
There was a problem hiding this comment.
原文结尾 "This is a powerful skill in the world of programming, opening doors to more complex and interactive applications." 的前半句评价被整句删去,属轻微遗漏。建议补上,例如:"这是编程中一项很实用的技能,也为之后构建更复杂的交互程序打下基础。"
Resolves #1579
Changes
zh-Hans) translation of the Data Structure Garden tutorial.Checks
npm run check: 0 errors, 0 warningsgit diff --cached --check: no issuesAI assistance
AI assistance was used during drafting, terminology clarification, consistency checking, and proofreading. I reviewed the full translation against the English source and manually revised and finalized the wording.
@lirenjie95 Would you be able to review the Simplified Chinese translation when convenient? Thank you!