Skip to content

Commit 662a3c7

Browse files
committed
feat: add Chinese translations for file system chapter
1 parent 57d7355 commit 662a3c7

File tree

9 files changed

+81
-11
lines changed

9 files changed

+81
-11
lines changed

layouts/section.shtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</div>
3030
</ctx>
3131
<div id="footer">
32-
<div>&copy; 2025. All rights reserved.</div>
32+
<div>&copy; 2023 - 2025 <a href="https://github.com/zigcc/zig-cookbook/graphs/contributors">ZigCC and contributors</a></div>
3333
<div :text="$i18n.get('languages_menu')"></div>
3434
<div class="langs" :loop="$page.locales()">
3535
<a href="$loop.it.link()">

src/en-US/index.smd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
.title = "introduction",
2+
.title = "Introduction",
33
.date = "2024-01-01",
44
.author = "ZigCC",
55
.layout = "section.shtml",
@@ -48,11 +48,10 @@ Create corresponding recipe in the language you want to localize, localize it, a
4848

4949
# Acknowledgment
5050

51-
The **initial** version of the Zig Cookbook was inspired by several other similar projects. We would like to thank the following projects, thanks for their awesome work.
51+
Zig Cookbook was inspired by several other similar projects. We would like to thank the following projects, thanks for their awesome work.
5252

5353
- [Rust Cookbook](https://github.com/rust-lang-nursery/rust-cookbook)
54-
55-
The **current** version of the Zig Cookbook is based on [zine-ssg](https://zine-ssg.io), thanks for their awesome work.
54+
- [zine-ssg](https://zine-ssg.io), thanks to [Loris Cro](https://github.com/kristoff-it) for creating this awesome static site generator for Zig.
5655

5756
# Star History
5857

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
.title = "逐行读取文件",
3+
.date = "2024-01-01",
4+
.author = "ZigCC",
5+
.layout = "section.shtml",
6+
---
7+
8+
在 Zig 中逐行读取文件,可以使用标准库中的 [`Reader`] 类型。它提供了多种方法来读取文件内容,例如 `readAll`、`readInt` 等。这里我们将使用 `streamUntilDelimiter` 方法来按行分割读取。
9+
10+
[]($code.siteAsset('src/01-01.zig').language('zig'))
11+
12+
[`reader`]: https://ziglang.org/documentation/0.14.0/std/#std.io.Reader

src/zh-CN/01-02-mmap-file.smd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
.title = "使用内存映射读取文件",
3+
.date = "2024-01-01",
4+
.author = "ZigCC",
5+
.layout = "section.shtml",
6+
---
7+
8+
本示例展示了如何使用内存映射(mmap)来读取文件内容。内存映射文件允许程序将文件内容直接映射到内存地址空间,这样可以像访问内存一样访问文件数据,而无需显式的读写操作。
9+
10+
[]($code.siteAsset('src/01-02.zig').language('zig'))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
.title = "查找过去 24 小时修改过的文件",
3+
.date = "2024-01-01",
4+
.author = "ZigCC",
5+
.layout = "section.shtml",
6+
---
7+
8+
通过 Zig 的标准库 `std.fs`,我们可以轻松地遍历目录并检查文件的元数据。以下示例展示了如何查找在过去24小时内修改过的文件。
9+
10+
对于每个文件,我们使用 `statFile()` 函数获取其元数据,并检查 `mtime`(修改时间)字段是否在过去24小时内。
11+
12+
[]($code.siteAsset('src/01-03.zig').language('zig'))

src/zh-CN/01-04-file-exists.smd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
.title = "检查文件是否存在",
3+
.date = "2024-01-01",
4+
.author = "ZigCC",
5+
.layout = "section.shtml",
6+
---
7+
8+
在 Zig 中检查文件是否存在,可以使用标准库中的 `std.fs` 模块。具体来说,可以使用 `Dir.access` 方法来检查文件的存在性和权限。
9+
10+
[]($code.siteAsset('src/01-04.zig').language('zig'))
11+
12+
`Dir.access` 方法接受两个参数:文件路径和访问模式(如读取、写入等)。如果文件存在且具有指定的权限,函数将返回 `true`,否则返回 `false`。
13+
14+
但是,有一点需要注意的是,`Dir.access` 方法可能会受到 [Time-Of-Check-Time-Of-Use](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use)(TOCTOU)竞态条件的影响。
15+
16+
例如,在检查文件存在性和实际使用文件之间,文件的状态可能会发生变化。因此,更推荐的做法是直接尝试打开文件,并处理可能出现的错误。

src/zh-CN/01-05-iterate-dir.smd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
.title = "遍历目录",
3+
.date = "2024-01-01",
4+
.author = "ZigCC",
5+
.layout = "section.shtml",
6+
---
7+
8+
在 Zig 中遍历目录,可以使用标准库中的 `std.fs` 模块。它提供了多种方法来操作文件系统,例如打开目录、读取目录内容等,这里使用 `walk` 方法来递归遍历目录。
9+
10+
11+
[]($code.siteAsset('src/01-05.zig').language('zig'))
12+
13+
`walk` 方法接受一个回调函数作为参数,该函数会在遍历到每个文件或子目录时被调用。回调函数可以根据需要处理每个文件或目录,例如打印其路径、检查其类型等。
14+
15+
遍历时,,返回的每个文件系统条目的顺序是未定义的,如果对返回条目的顺序有任何要求,例如按字母顺序或按时间顺序排序,请相应地进行排序。否则,保持它们的原始、未排序的顺序。

src/zh-CN/index.smd

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
.title = "介绍",
3-
.date = "2024-01-01",
3+
.date = "2025-08-28T11:19:53+0800",
44
.author = "ZigCC",
55
.layout = "section.shtml",
66
---
@@ -40,21 +40,20 @@
4040

4141
# 贡献
4242

43-
本 cookbook 仍在持续完善中,我们欢迎社区贡献。如果你有想要分享的示例, [Pull Request](https://github.com/zigcc/zig-cookbook/pulls)。
43+
本 cookbook 仍在持续完善中,我们欢迎社区贡献。如果你有想要分享的示例,欢迎提 [Pull Request](https://github.com/zigcc/zig-cookbook/pulls)。
4444

4545
## 翻译
4646

4747
在对应语言目录下创建相应的要翻译的示例,翻译后 [Pull Request](https://github.com/zigcc/zig-cookbook/pulls) 即可。
4848

4949
# 致谢
5050

51-
**初始版本**的 Zig Cookbook 受到多个类似项目的启发。我们向以下项目致以诚挚感谢,感谢它们的杰出工作:
51+
Zig Cookbook 受到多个类似项目的启发。我们向以下项目致以诚挚感谢,感谢它们的杰出工作:
5252

5353
- [Rust Cookbook](https://github.com/rust-lang-nursery/rust-cookbook)
54+
- [zine-ssg](https://zine-ssg.io),感谢 [Loris Cro](https://github.com/kristoff-it) 创建了这个出色的 Zig 静态网站生成器。
5455

55-
**当前版本**的 Zig Cookbook 基于 [zine-ssg](https://zine-ssg.io),在此感谢其卓越的贡献!
56-
57-
# 星标历史
56+
# Star 历史
5857

5958
```=html
6059
<a href="https://star-history.com/#zigcc/zig-cookbook&Date">

src/zh-CN/toc.smd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@
66
---
77

88
[介绍](/)
9+
10+
- 文件系统
11+
- [逐行读取文件](01-01-read-file-line-by-line)
12+
- [内存映射文件](01-02-mmap-file)
13+
- [查找最近24小时内修改的文件](01-03-file-modified-24h-ago)
14+
- [检查文件是否存在](01-04-file-exists)
15+
- [遍历目录](01-05-iterate-dir)

0 commit comments

Comments
 (0)