mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 15:43:58 +00:00
Sync with the English version & minor tweaks
This commit is contained in:
parent
8032dbccc9
commit
f4371a8367
@ -4,6 +4,7 @@ contributors:
|
|||||||
- ["Adam Brenecki", "https://github.com/adambrenecki"]
|
- ["Adam Brenecki", "https://github.com/adambrenecki"]
|
||||||
translators:
|
translators:
|
||||||
- ["Zach Zhang", "https://github.com/checkcheckzz"]
|
- ["Zach Zhang", "https://github.com/checkcheckzz"]
|
||||||
|
- ["Jiang Haiyun", "https://github.com/haiiiiiyun"]
|
||||||
filename: learnyaml-cn.yaml
|
filename: learnyaml-cn.yaml
|
||||||
lang: zh-cn
|
lang: zh-cn
|
||||||
---
|
---
|
||||||
@ -21,16 +22,18 @@ YAML根本不容许文字制表符。
|
|||||||
# 标量类型 #
|
# 标量类型 #
|
||||||
################
|
################
|
||||||
|
|
||||||
# 我们的根对象 (它们在整个文件里延续) 将会是一个地图,
|
# 我们的根对象 (它们在整个文件里延续) 将会是一个映射,
|
||||||
# 它等价于在别的语言里的一个字典,哈西表或对象。
|
# 它等价于在别的语言里的一个字典,哈西表或对象。
|
||||||
key: value
|
key: value
|
||||||
another_key: Another value goes here.
|
another_key: Another value goes here.
|
||||||
a_number_value: 100
|
a_number_value: 100
|
||||||
|
# 如果你想将数字 1 作为值,你必须要将它括在引号中。
|
||||||
|
# 不然 YAML 解析器会假定它是一个布尔值 true。
|
||||||
scientific_notation: 1e+12
|
scientific_notation: 1e+12
|
||||||
boolean: true
|
boolean: true
|
||||||
null_value: null
|
null_value: null
|
||||||
key with spaces: value
|
key with spaces: value
|
||||||
# 注意到字符串不需要被引用。但是,它们可以被引用。
|
# 注意到字符串不需要被括在引号中。但是,它们可以被括起来。
|
||||||
"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
|
"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
|
||||||
|
|
||||||
# 多行字符串既可以写成像一个'文字块'(使用 |),
|
# 多行字符串既可以写成像一个'文字块'(使用 |),
|
||||||
@ -64,18 +67,24 @@ a_nested_map:
|
|||||||
another_nested_map:
|
another_nested_map:
|
||||||
hello: hello
|
hello: hello
|
||||||
|
|
||||||
# 地图不用有字符串键值。
|
# 映射的键值不必是字符串。
|
||||||
0.25: a float key
|
0.25: a float key
|
||||||
|
|
||||||
# 键值也可以是多行对象,用?表明键值的开始。
|
# 键值也可以是复合型的,比如多行对象
|
||||||
|
# 我们用 ? 后跟一个空格来表示一个复合键的开始。
|
||||||
? |
|
? |
|
||||||
This is a key
|
This is a key
|
||||||
that has multiple lines
|
that has multiple lines
|
||||||
: and this is its value
|
: and this is its value
|
||||||
|
|
||||||
# YAML也容许键值是集合类型,但是很多语言将会抱怨。
|
# YAML 也允许使用复杂键语法表示序列间的映射关系。
|
||||||
|
# 但有些语言的解析器可能会不支持。
|
||||||
|
# 一个例子:
|
||||||
|
? - Manchester United
|
||||||
|
- Real Madrid
|
||||||
|
: [ 2001-01-01, 2002-02-02 ]
|
||||||
|
|
||||||
# 序列 (等价于表或数组) 看起来像这样:
|
# 序列 (等价于列表或数组) 看起来像这样:
|
||||||
a_sequence:
|
a_sequence:
|
||||||
- Item 1
|
- Item 1
|
||||||
- Item 2
|
- Item 2
|
||||||
@ -87,35 +96,55 @@ a_sequence:
|
|||||||
- This is a sequence
|
- This is a sequence
|
||||||
- inside another sequence
|
- inside another sequence
|
||||||
|
|
||||||
# 因为YAML是JSON的超集,你也可以写JSON风格的地图和序列:
|
# 因为 YAML 是 JSON 的超集,你也可以写 JSON 风格的映射和序列:
|
||||||
json_map: {"key": "value"}
|
json_map: {"key": "value"}
|
||||||
json_seq: [3, 2, 1, "takeoff"]
|
json_seq: [3, 2, 1, "takeoff"]
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# 其余的YAML特点 #
|
# 其余的 YAML 特性 #
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
# YAML还有一个方便的特点叫'锚',它让你简单地在整个文件里重复内容。
|
# YAML 还有一个方便的特性叫 '锚',它能让你很容易在文档中进行文本复用。
|
||||||
# 两个键值将会有相同的值:
|
# 如下两个键会有相同的值:
|
||||||
anchored_content: &anchor_name This string will appear as the value of two keys.
|
anchored_content: &anchor_name This string will appear as the value of two keys.
|
||||||
other_anchor: *anchor_name
|
other_anchor: *anchor_name
|
||||||
|
|
||||||
|
# 锚也可被用来复制/继承属性
|
||||||
|
base: &base
|
||||||
|
name: Everyone has same name
|
||||||
|
|
||||||
|
foo: &foo
|
||||||
|
<<: *base
|
||||||
|
age: 10
|
||||||
|
|
||||||
|
bar: &bar
|
||||||
|
<<: *base
|
||||||
|
age: 20
|
||||||
|
|
||||||
|
# foo 和 bar 将都含有 name: Everyone has same name
|
||||||
|
|
||||||
# YAML 还有标签,你可以用它显示地声明类型。
|
# YAML 还有标签,你可以用它显示地声明类型。
|
||||||
explicit_string: !!str 0.5
|
explicit_string: !!str 0.5
|
||||||
# 一些解析器实现特定语言的标签,就像这个为了Python的复数类型。
|
# 一些解析器实现特定语言的标签,就像这个针对 Python 的复数类型。
|
||||||
python_complex_number: !!python/complex 1+2j
|
python_complex_number: !!python/complex 1+2j
|
||||||
|
|
||||||
|
# 我们也可以在 YAML 的复合键中使用特定语言的标签
|
||||||
|
? !!python/tuple [5, 7]
|
||||||
|
: Fifty Seven
|
||||||
|
# 将会是 Python 中的 {(5, 7): 'Fifty Seven'}
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# 其余的 YAML 类型 #
|
# 其余的 YAML 类型 #
|
||||||
####################
|
####################
|
||||||
|
|
||||||
# 字符串和数字不是仅有的YAML可以理解的标量。
|
# 除了字符串和数字,YAML 还能理解其它标量。
|
||||||
# ISO 格式的日期和日期时间文字也是可以被解析的。
|
# ISO 格式的日期和日期时间文本也可以被解析。
|
||||||
datetime: 2001-12-15T02:59:43.1Z
|
datetime: 2001-12-15T02:59:43.1Z
|
||||||
datetime_with_spaces: 2001-12-14 21:59:43.10 -5
|
datetime_with_spaces: 2001-12-14 21:59:43.10 -5
|
||||||
date: 2002-12-14
|
date: 2002-12-14
|
||||||
|
|
||||||
# 这个!!binary标签表明一个字符串实际上是一个二进制blob的base64编码表示。
|
# 这个 !!binary 标签表明这个字符串实际上
|
||||||
|
# 是一个用 base64 编码表示的二进制 blob。
|
||||||
gif_file: !!binary |
|
gif_file: !!binary |
|
||||||
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
|
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
|
||||||
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
|
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
|
||||||
@ -128,9 +157,14 @@ set:
|
|||||||
? item2
|
? item2
|
||||||
? item3
|
? item3
|
||||||
|
|
||||||
# 像Python一样,集合仅是有null数值的地图;上面的集合等价于:
|
# 像 Python 一样,集合仅是值为 null 的映射;上面的集合等价于:
|
||||||
set2:
|
set2:
|
||||||
item1: null
|
item1: null
|
||||||
item2: null
|
item2: null
|
||||||
item3: null
|
item3: null
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 更多资源
|
||||||
|
|
||||||
|
+ [YAML official website](http://yaml.org/)
|
||||||
|
+ [Online YAML Validator](http://codebeautify.org/yaml-validator)
|
||||||
|
Loading…
Reference in New Issue
Block a user