Skip to content
Merged

I18n #111

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md

This file was deleted.

54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Zig Cookbook

[![](https://img.shields.io/discord/1155469703846834187?label=Chat%20on%20Discord)](https://discord.gg/bAehMGPb2R)
[![](https://img.shields.io/github/stars/zigcc/zig-cookbook?style=square&color=#30a14e)](https://github.com/zigcc/zig-cookbook/stargazers)
[![](https://github.com/zigcc/zig-cookbook/actions/workflows/ci.yml/badge.svg)](https://github.com/zigcc/zig-cookbook/actions/workflows/ci.yml)
[![](https://github.com/zigcc/zig-cookbook/actions/workflows/pages.yml/badge.svg)](https://github.com/zigcc/zig-cookbook/actions/workflows/pages.yml)

![Zig Cookbook Logo](./assets/images/logo.webp)

[Zig cookbook](https://github.com/zigcc/zig-cookbook) is a collection of simple Zig programs that demonstrate good practices to accomplish common programming tasks.

> - Main branch tracks Zig 0.14.0 and master, and are tested on Linux and macOS via GitHub actions.
> - Earlier Zig support could be found in [other branches](https://github.com/zigcc/zig-cookbook/branches).

# How to use

[The website](https://cookbook.ziglang.cc/) is generated by [zine-ssg](https://zine-ssg.io), a static site generator for Zig. `zine` will start a server at `http://localhost:1990` for preview.

Each recipe is accompanied by an illustrative example named after its corresponding sequence number. These examples can be executed using the command `zig build run-{chapter-num}-{sequence-num}`, or `zig build run-all` to execute all.

> ## Note
>
> Some recipes may depend on system libraries
>
> - Use `make install-deps` to install client libraries, and
> - `docker-compose up -d` to start required databases.

# Contributing

This cookbook is a work in progress, and we welcome contributions from the community. If you have a favorite recipe that you'd like to share, please submit a [pull request](https://github.com/zigcc/zig-cookbook/pulls).

## Localization

Create corresponding recipe in the language folder, localize it, and submit a [pull request](https://github.com/zigcc/zig-cookbook/pulls).

# Acknowledgment

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.

- [Rust Cookbook](https://github.com/rust-lang-nursery/rust-cookbook)

The **current** version of the Zig Cookbook is based on [zine-ssg](https://zine-ssg.io), thanks for their awesome work.

# Star History

```=html
<a href="https://star-history.com/#zigcc/zig-cookbook&Date">
<img src="https://api.star-history.com/svg?repos=zigcc/zig-cookbook&type=Date" alt="Star History">
</a>
```

# License

The markdown files are licensed under [CC BY-NC-ND 4.0 DEED](https://creativecommons.org/licenses/by-nc-nd/4.0/), and zig files are under MIT.
46 changes: 22 additions & 24 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,8 @@ body {
}

#prev-next {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
margin-top: 20px;
padding-top: 5px;
border-top: 2px solid var(--border);
}

#prev-next a {
text-decoration: none;
}
#prev-next > :last-child {
margin-left: auto;
text-align: right;
}
#prev-next > :first-child span::before {
content: "←";
}

#prev-next > :last-child span::after {
content: "→";
padding: 15px 0;
border-bottom: 1px solid var(--border);
}

a {
Expand Down Expand Up @@ -165,6 +145,20 @@ html {
max-width: 50rem;
}

article {
border-bottom: 1px solid var(--border);
}

#footer {
margin: 15px 0;
text-align: center;
font-size: 0.85rem;
}

#footer .langs * {
margin: 0 5px;
}

.toc {
width: var(--toc-width);
min-width: var(--toc-width);
Expand All @@ -176,12 +170,11 @@ html {
/* word-break: normal; */
}
.toc a {
text-decoration: none;
line-break: auto;
}

.toc a:hover {
text-decoration: underline;
color: #5eafcd;
}

.toc a[aria-current="page"] {
Expand Down Expand Up @@ -291,4 +284,9 @@ html {

h1{
margin-bottom: 0;
}
#content-header{
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: 1px solid var(--border)
}
11 changes: 11 additions & 0 deletions i18n/en-US.ziggy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"site_title": "Zig Cookbook",
"introduction": "Introduction",
"contributing": "Contributing",
"license": "License",
"toggle_toc": "Toggle Table of Contents",
"prev": "Previous: ",
"next": "Next: ",
"languages_menu": "This page is available in the following languages",
"footer_copyright": "License: text: CC BY-SA 4.0; code: MIT",
}
11 changes: 11 additions & 0 deletions i18n/zh-CN.ziggy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"site_title": "Zig Cookbook",
"introduction": "介绍",
"contributing": "贡献",
"license": "许可证",
"toggle_toc": "切换目录",
"prev": "上一示例:",
"next": "下一示例:",
"languages_menu": "此页面提供以下语言的版本",
"footer_copyright": "许可证: 文字:CC BY-NC-SA 4.0;代码:MIT",
}
33 changes: 21 additions & 12 deletions layouts/section.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,39 @@
</head>
<body id="body">
<div class="mobile-header">
<button id="toc-toggle" aria-expanded="false" aria-controls="toc" aria-label="Toggle table of contents">☰</button>
<a class="brand" href="/" :text="$site.title"></a>
<button id="toc-toggle" aria-expanded="false" aria-controls="toc" aria-label="$i18n.get('toggle_toc')">☰</button>
<a class="brand" href="/" :text="$i18n.get('site_title')"></a>
</div>
<div class="toc" id="toc">
<ctx :html="$site.page('toc').content()"></ctx>
</div>
<div class="body">
<div class="content">
<article>
<h1 :text="$page.title"></h1>
<div id="content-header">
<h1 :text="$page.title"></h1>
</div>
<div :html="$page.content()"></div>
</article>
<div id="prev-next" :if="$page.isSection().not()">
<div :if="$page.prevPage?()">
<a href="$if.link()">
<span :text="$if.title"></span>
</a>
<ctx :if="$page.isSection().not()">
<div id="prev-next">
<div :if="$page.prevPage?()">
<span :text="$i18n.get('prev')"></span><a href="$if.link()" :text="$if.title"></a>
</div>
<div :if="$page.nextPage?()">
<span :text="$i18n.get('next')"></span><a href="$if.link()" :text="$if.title"></a>
</div>
</div>
<div :if="$page.nextPage?()">
<a href="$if.link()">
<span :text="$if.title"></span>
</ctx>
<div id="footer">
<div>&copy; 2025. All rights reserved.</div>
<div :text="$i18n.get('languages_menu')"></div>
<div class="langs" :loop="$page.locales()">
<a href="$loop.it.link()">
<ctx :text="$loop.it.site().localeName()"></ctx><ctx :if="$loop.it.site().localeName().eql('English')">(Original)</ctx>
</a>
</div>
</div>
</div>
</div>
</body>
</body>
2 changes: 1 addition & 1 deletion layouts/templates/base.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head id="head">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1">
<title :text="$site.title"></title>
<title :text="$i18n.get('site_title')"></title>
<link type="text/css" rel="stylesheet" href="$site.asset('style.css').link()">
<link type="text/css" rel="stylesheet" href="$site.asset('highlight.css').link()">
<super>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions src/index.smd → src/en-US/index.smd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</a>
```

![Zig Cookbook Logo](/images/logo.webp)
![](/images/logo.webp)

[Zig cookbook](https://github.com/zigcc/zig-cookbook) is a collection of simple Zig programs that demonstrate good practices to accomplish common programming tasks.

Expand All @@ -29,7 +29,7 @@

# How to use

[The website](https://cookbook.ziglang.cc/) is generated by [zine-ssg](https://zine-ssg.io), a static site generator for Zig.`zine` will start a server at `http://localhost:1990` for preview.
[The website](https://cookbook.ziglang.cc/) is generated by [zine-ssg](https://zine-ssg.io), a static site generator for Zig. `zine` will start a server at `http://localhost:1990` for preview.

Each recipe is accompanied by an illustrative example named after its corresponding sequence number. These examples can be executed using the command `zig build run-{chapter-num}-{sequence-num}`, or `zig build run-all` to execute all.

Expand All @@ -42,6 +42,10 @@ Each recipe is accompanied by an illustrative example named after its correspond

This cookbook is a work in progress, and we welcome contributions from the community. If you have a favorite recipe that you'd like to share, please submit a [pull request](https://github.com/zigcc/zig-cookbook/pulls).

## Localization

Create corresponding recipe in the language you want to localize, localize it, and submit a pull request.

# Acknowledgment

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.
Expand Down
4 changes: 1 addition & 3 deletions src/toc.smd → src/en-US/toc.smd
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
.title = "introduction",
.title = "toc",
.date = "2024-01-01",
.author = "ZigCC",
.layout = "section.shtml",
---

# Summary

[Introduction](/)

- File System
Expand Down
67 changes: 67 additions & 0 deletions src/zh-CN/index.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
.title = "介绍",
.date = "2024-01-01",
.author = "ZigCC",
.layout = "section.shtml",
---

```=html
<a href="https://discord.gg/bAehMGPb2R">
<img src="https://img.shields.io/discord/1155469703846834187?label=在Discord上聊天" alt="在Discord上聊天">
</a>
<a href="https://github.com/zigcc/zig-cookbook/stargazers">
<img src="https://img.shields.io/github/stars/zigcc/zig-cookbook?style=square&color=#30a14e" alt="星标数量">
</a>
<a href="https://github.com/zigcc/zig-cookbook/actions/workflows/ci.yml">
<img src="https://github.com/zigcc/zig-cookbook/actions/workflows/ci.yml/badge.svg" alt="CI">
</a>
<a href="https://github.com/zigcc/zig-cookbook/actions/workflows/pages.yml">
<img src="https://github.com/zigcc/zig-cookbook/actions/workflows/pages.yml/badge.svg" alt="Pages">
</a>
```

![](/images/logo.webp)

[Zig Cookbook](https://github.com/zigcc/zig-cookbook) 是一系列简单的 Zig 程序集合,用于展示完成常见编程任务的最佳实践。

> - 主分支跟踪 Zig 0.14.0 及 master 版本,并通过 GitHub Actions 在 Linux 和 macOS 上进行测试。
> - 更早版本的 Zig 支持可在 [其他分支](https://github.com/zigcc/zig-cookbook/branches) 中找到。

# 如何使用

[网站](https://cookbook.ziglang.cc/) 由 [zine-ssg](https://zine-ssg.io) 生成,这是一个 Zig 编写的静态网站生成器。运行 `zine` 将在 `http://localhost:1990` 启动一个预览服务器。

每个示例都附带一个以对应序号命名的示例程序。可以使用命令 `zig build run-{章节号}-{序号}` 来运行单个示例,或使用 `zig build run-all` 运行所有示例。

> ## 注意
> 某些示例可能依赖系统库:
> - 使用 `make install-deps` 安装客户端库;
> - 使用 `docker-compose up -d` 启动所需的数据库。

# 贡献

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

## 翻译

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

# 致谢

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

- [Rust Cookbook](https://github.com/rust-lang-nursery/rust-cookbook)

**当前版本**的 Zig Cookbook 基于 [zine-ssg](https://zine-ssg.io),在此感谢其卓越的贡献!

# 星标历史

```=html
<a href="https://star-history.com/#zigcc/zig-cookbook&Date">
<img src="https://api.star-history.com/svg?repos=zigcc/zig-cookbook&type=Date" alt="星标历史">
</a>
```

# 许可证

Markdown 文件采用 [CC BY-NC-ND 4.0 DEED](https://creativecommons.org/licenses/by-nc-nd/4.0/) 许可,Zig 源码文件采用 MIT 许可。
8 changes: 8 additions & 0 deletions src/zh-CN/toc.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
.title = "目录",
.date = "2024-01-01",
.author = "ZigCC",
.layout = "section.shtml",
---

[介绍](/)
20 changes: 17 additions & 3 deletions zine.ziggy
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
Site {
.title = "Zig cookbook",
Multilingual {
.host_url = "https://cookbook.ziglang.cc",
.content_dir_path = "src",
.i18n_dir_path = "i18n",
.layouts_dir_path = "layouts",
.assets_dir_path = "assets",
.static_assets = [
],
.locales = [
{
.code = "en-US",
.name = "English",
.site_title = "Zig Cookbook",
.content_dir_path = "src/en-US",
.output_prefix_override = "",
},
{
.code = "zh-CN",
.name = "中文",
.site_title = "Zig Cookbook",
.content_dir_path = "src/zh-CN",
},
],
}