Skip to content

Commit 0cbeeab

Browse files
authored
Add Chinese translation (#150)
* Create README.md * Add Chinese translation of readme.md * Create comment.md * Create hello_world.md * Create strings.md * Create variables.md * Create keywords.md * Create primitives.md * Create README.md * Create README.md * Create if-else.md * Create loops.md * Create match.md * Create operator.md * Create README.md * Update operator.md * Create README.md * Add Chinese translation of section * Add Chinese translation of section_4 * Update README.md * Update README.md * Update README.md
1 parent a0c81f0 commit 0cbeeab

File tree

24 files changed

+1565
-1
lines changed

24 files changed

+1565
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# V by Example
22

3-
[Brazilian Portuguese](/pt-br/README.md) | [Deutsch](/de/README.md) | [English](README.md) | [Bahasa Indonesia](/id/README.md)
3+
[Brazilian Portuguese](/pt-br/README.md) | [Deutsch](/de/README.md) | [English](README.md) | [Bahasa Indonesia](/id/README.md) | [Chinese](cn/examples/README.md)
44
> Learn V by Examples
55
66
V by Example is a direct introduction to V by using annotated program examples.

cn/examples/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# V by Example
2+
3+
[Brazilian Portuguese](pt-br/README.md) | [Deutsch](de/README.md) | [English](en/README.md) | [Chinese](cn/README.md)
4+
5+
> Learn V by Examples
6+
7+
V by Example是使用带注释的程序示例对V语言的介绍。
8+
9+
- [例子](#examples)
10+
- [贡献](#contributing)
11+
- [版权](#license)
12+
13+
Discord: [https://discord.gg/d3Qk65J](https://discord.gg/d3Qk65J)
14+
15+
## Section 1
16+
17+
通过一些基本的例子和练习来介绍V语言。
18+
19+
- [Hello World](section_1/hello_world.md)
20+
- [V Keywords](section_1/keywords.md)
21+
- [Primitives](section_1/primitives.md)
22+
- [Variables](section_1/variables.md)
23+
- [Strings](section_1/strings.md)
24+
- [Comment](section_1/comment.md)
25+
26+
## Section 2
27+
28+
本节讨论V语言中主要的运算和条件语句。
29+
30+
- [Operator](section_2/operator.md)
31+
- [If-else](section_2/if-else.md)
32+
- [Match](section_2/match.md)
33+
- [Loops](section_2/loops.md)
34+
35+
## Section 3
36+
37+
学习V语言函数和方法以及最重要的数据结构:数组和结构体
38+
39+
- [Functions](section_3/functions.md)
40+
- [Arrays](section_3/arrays.md)
41+
- [Struct](section_3/struct.md)
42+
- [Methods](section_3/methods.md)
43+
44+
## Section 4
45+
46+
在本节中,我们将深入研究数组对象内部的特征。其他的例子,比如JSON、写/读文件和测试,都会涉及到。
47+
48+
- [Array Functions](section_4/array-functions.md)
49+
- [Testing](section_4/testing.md)
50+
- [Files](section_4/files.md)
51+
- [JSON](section_4/json.md)
52+
53+
## Team
54+
55+
当前维护者/作者列表:
56+
57+
- [Don Alfons Nisnoni](https://github.com/dhonx)
58+
- [Ivo-Balbaert](https://github.com/ibalbaert)
59+
- [Sven Patrick Meier](https://github.com/SuicideS3ason)
60+
- [Swastik Baranwal](https://github.com/Delta456)
61+
- [Vitor Oliveira](https://github.com/vbrazo)
62+
63+
## Contributing
64+
65+
先阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 然后开始贡献. 我们通常根据贡献来选择新的维护者。
66+
67+
## License
68+
69+
[MIT](LICENSE)

cn/examples/section_1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 第一节

cn/examples/section_1/comment.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 注释
2+
3+
V支持单行注释`//`和多行注释`/**/`
4+
它们应该用于记录代码,以便让其他用户知道代码是如何工作的。
5+
它还可以用于临时注释代码,以后必须使用。
6+
7+
```v
8+
// 这是单行注释
9+
10+
/* 这是
11+
* 多行注释
12+
* /* 这也可以嵌套*/
13+
*/
14+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 格式化打印
2+
3+
打印由各种I/O流函数处理。人们应该要知道如何去使用它们。
4+
- `print`:用于将文本打印到不带换行符的输出流。
5+
- `println`:与`print`相同,但它会自动追加换行符。
6+
- `eprint`:与`print`相同,但它会输出到错误流(stderr)。
7+
- `eprintln`:与`println`相同,不过它会输出到错误流(stderr)。
8+
- `panic`:程序的输出和退出。
9+
10+
```v
11+
print('Hello World')
12+
print('Hello V')
13+
```
14+
15+
它在屏幕上将会打印 `Hello WorldHello V`
16+
17+
如果要在新行上打印下一行,则必须执行`\n`
18+
19+
```v
20+
print('Hello World \n')
21+
print('Hello V ')
22+
```
23+
24+
如果不想使用`\n`,则可以使用`println`
25+
26+
# 注释
27+
28+
V支持单行注释`//`和多行注释`/**/`
29+
它们应该用于记录代码,以便让其他用户知道代码是如何工作的。
30+
它还可以用于临时注释代码,以后不得不使用。
31+
32+
```v
33+
// 这是单行注释
34+
35+
/* 这是
36+
* 多行注释
37+
* /* 这也可以嵌套*/
38+
*/
39+
```
40+
41+
42+
## 练习
43+
44+
尝试在`hello.v`中删掉代码的注释,看看会发生什么。

cn/examples/section_1/keywords.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 关键字
2+
3+
V是一种非常小巧的语言,所以它很少有关键字。大约有25个关键字。
4+
5+
| Keywords | in | V | Programming | Language |
6+
| -------- | ------ | --- | ----------- | --------- |
7+
| break | const | as | continue | defer |
8+
| else | enum | fn | for | struct |
9+
| go | goto | if | import | return |
10+
| type | pub | mut | in | interface |
11+
| match | module | or | none | |
12+
13+
与其他语言一样,它们不能用作变量。
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Primitives
2+
3+
V的基本类型比Go少。
4+
5+
## 基本数据类型
6+
7+
- bool 也就是 `true` 或者 `false`
8+
9+
- string 字符类型
10+
11+
- 整数类型 `int`
12+
13+
- 浮点数类型 `float`
14+
15+
- rune (Unicode字符串)
16+
17+
## 复合类型
18+
19+
- arrays `[]`
20+
21+
- map `{}`
22+
23+
- struct
24+
25+
## 整数
26+
27+
整数被细分为“signed”和“unsigned”。`signed`表示正或负,`unsigned`仅表示正。
28+
29+
### Signed Integer
30+
31+
| 类型 | 大小 | 范围 |
32+
| ------ | :------: | --------------------------------------: |
33+
| int8 | 8 bits | -128 to 2<sup>7</sup> -1 |
34+
| int16 | 16 bits | -2<sup>15</sup> to 2<sup>15</sup> - 1 |
35+
| int | 32 bits | -2<sup>31</sup> to 2<sup>31</sup> - 1 |
36+
| int64 | 64 bits | -2<sup>63</sup> to 2<sup>63</sup> - 1 |
37+
| int128 | 128 bits | -2<sup>127</sup> to 2<sup>127</sup> - 1 |
38+
39+
### Unsigned Integer
40+
41+
| 类型 | 大小 | 范围 |
42+
| ---- | :------: | -----------------------: |
43+
| byte | 8 bits | 0 to 2<sup>7</sup> -1 |
44+
| u16 | 16 bits | 0 to 2<sup>15</sup> - 1 |
45+
| u32 | 32 bits | 0 to 2<sup>31</sup> - 1 |
46+
| u64 | 64 bits | 0 to 2<sup>63</sup> - 1 |
47+
| u128 | 128 bits | 0 to 2<sup>127</sup> - 1 |

cn/examples/section_1/strings.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# 字符串
2+
3+
在V中,可以使用`:=`运算符定义字符串。默认情况下,字符串(与其他变量一样)是不可变的。
4+
一个可以使用`""``''`来表示字符串。使用`vfmt`时,除非包含单引号字符,否则所有双引号字符串都将转换为单引号字符串。
5+
6+
```go
7+
name := 'Bob'
8+
println(name) // Bob
9+
println(name.len) // 3
10+
```
11+
12+
获取字符串的长度使用`.len`
13+
14+
## 插入
15+
16+
可以在变量前面使用`$`进行字符串插值:
17+
18+
```go
19+
name:= 'Bob'
20+
println('Hello $name!') // Hello Bob!
21+
```
22+
23+
使用`${}`可以有更复杂的插值语法表达式:
24+
25+
```go
26+
struct User {
27+
name string
28+
age int
29+
}
30+
bob := User {
31+
name: 'Bob'
32+
age: 17
33+
}
34+
println('Say Hello to a new User: ${bob.name}, ${bob.age}') // Say Hello to new User: Bob, 17
35+
println('${bob.name}s age is higher or equal to 18: ${bob.age >= 18}') // 0 <=> number representation for false
36+
```
37+
38+
## 连接操作符
39+
40+
使用`+`运算符符字符串会被连接。
41+
42+
```go
43+
text := 'Hello'
44+
concatenated_text := text + ' World!'
45+
println(text) // Hello
46+
println(text + ' World!') // Hello World!
47+
println(concatenated_text) // Hello World!
48+
```
49+
50+
添加到字符串与连接可以使用`+=`运算符。因为字符串在默认情况下是不可变的,所以只有用`mut`声明它们时才能这样做。
51+
52+
```go
53+
mut hello := 'Hello '
54+
hello += 'from V!' // 附加“从V!”到hello中存储的字符串。
55+
println(hello) // Hello from V!
56+
```
57+
58+
在V中,字符串数据使用UTF-8编码,字符串本身是一个只读字节数组。这使得切片成为可能,这意味着我们可以访问单个字符的文本或字符串变量的切片。
59+
```go
60+
robert := 'Robert'
61+
bert := robert[2..robert.len] // bert
62+
rob := robert[0..3] // Rob
63+
println('The persons of interest are: $robert, $bert, $rob') // The persons of interest are: Robert, bert, Rob
64+
```
65+
66+
### Notes
67+
68+
V中的所有运算符两边必须具有相同类型的值。下面的代码无法编译,因为`age``int`类型的:
69+
70+
```go
71+
age := 25
72+
println('age = ' + age)
73+
```
74+
75+
因此,我们需要使用`.str()`或使用字符串插值(最好用的方法)将其转换为字符串:
76+
77+
```go
78+
age := 25
79+
println('age = ' + age.str()) // age = 25
80+
println('age = $age') // age = 25
81+
```
82+
83+
要定义字符,可以使用:` `` `。原始字符串可以定义为前缀`r`
84+
85+
```go
86+
hello := 'Hello\nWorld'
87+
println(hello) // Hello
88+
// World
89+
raw_hello := r'Hello\nWorld'
90+
println(raw_hello) // Hello\nWorld
91+
```

cn/examples/section_1/variables.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# 变量
2+
3+
在V语言中,变量可以用`:=`运算符声明和初始化。变量只能以这种方式在V中声明,这意味着所有变量都有一个初始值。变量的类型是从右边的值推断出来的。默认情况下,V中的变量是不可变的。
4+
5+
```go
6+
age := 23 // int
7+
name := 'Alice' // string
8+
is_adult := age > 21 // bool
9+
10+
println(age_str) // 23
11+
println(name) // Alice
12+
println(is_adult) // true
13+
```
14+
15+
> Note:变量只能在函数中定义。所以在V中没有全局变量和全局状态。
16+
17+
要更改变量的值,要确保它必须是可变的。这可以在声明变量时使用`mut`关键字来完成。要给变量赋值,可以使用`=`
18+
19+
```go
20+
mut age := 20 // 声明可变变量age并将其赋给值20。
21+
println(age) // 20
22+
age = 21 // 为age赋个新的值
23+
println(age) // 21
24+
```
25+
26+
在此处省略`mut`关键字将导致错误,因为无法更改不可变变量的值。
27+
28+
```go
29+
fn main() {
30+
age = 20
31+
println(age)
32+
}
33+
```
34+
35+
上面的代码在编译过程中会导致错误,因为未声明变量`age`
36+
37+
```go
38+
fn main() {
39+
mut age := 20 // 我们声明可变变量age并将其赋给值20。
40+
println(age) // 20
41+
age := 21 // 错误
42+
}
43+
```
44+
45+
这里的`age:=21`在编译时将导致另一个错误,因为变量`age`已在作用域中定义。记住这一点很简单,只要用`:=`声明值并用`=`赋值。
46+
47+
像Go一样,您还可以使用`_`忽略掉不需要的值。通常用于多返回函数。
48+
49+
```go
50+
_ := "I don't need this value"
51+
println(_) // 错误:不能将“_”用作值
52+
```
53+
54+
## Naming Rules
55+
56+
以下是命名变量时应记住的规则。
57+
-名称不应该包含像`AlphaTest`这样的大写字母`
58+
-使用下划线作为分隔符,如`hello_world``
59+
-名称应该尽可能具有描述性
60+
-名称不应该包含`__`
61+
-名称不应该包含任何空格
62+
-如果名称大于11,则必须要使用`_`作为分隔符
63+
64+
这些规则来自[`Snake_Case`](https://en.wikipedia.org/wiki/Snake_Case) V语言使用Snake Case,并且更喜欢它,因为它更易于阅读、书写和理解。
65+
66+
### 有效名称
67+
68+
```go
69+
boby
70+
john_dads
71+
myfamily_number
72+
```
73+
74+
### 无效名称
75+
76+
```go
77+
IamNotValid
78+
new Make
79+
```

cn/examples/section_2/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 第二节

0 commit comments

Comments
 (0)