Skip to content

Commit 324d41b

Browse files
committed
Merge pull request facebook#1244 from rayqian/master
add chinese translation support
2 parents b0dce15 + f6a2888 commit 324d41b

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

docs/docs/01-why-react.zh-CN.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
id: why-react-zh-CN
3+
title: 为什么使用 React?
4+
layout: docs
5+
permalink: why-react-zh-CN.html
6+
next: displaying-data.html
7+
---
8+
9+
React 是一个 Facebook 和 Instagram 用来创建用户界面的 JavaScript 库。很人多认为 React 是 **[MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)** 中的 **V**(视图)。
10+
11+
我们创造 React 是为了解决一个问题:**构建随着时间数据不断变化的大规模应用程序**。为了达到这个目标,React 采用下面两个主要的思想。
12+
13+
### 简单
14+
15+
仅仅只要表达出你的应用程序在任一个时间点应该长的样子,然后当底层的数据变了,React 会自动处理所有用户界面的更新。
16+
17+
### 表达能力 (Declarative)
18+
19+
当数据变化了,React 概念上是类似点击了更新的按钮,但仅会更新变化的部分。
20+
21+
## 构建可组合的组件
22+
23+
React 都是关于构建可复用的组件。事实上,通过 React 你*唯一*要做的事情就是构建组件。得益于其良好的封装性,组件使代码复用、测试和关注分离(separation of concerns)更加简单。
24+
25+
## 给它5分钟的时间
26+
27+
React挑战了很多传统的知识,第一眼看上去可能很多想法有点疯狂。当你阅读这篇指南,请[给它5分钟的时间](http://37signals.com/svn/posts/3124-give-it-five-minutes);那些疯狂的想法已经帮助 Facebook 和 Instagram 从里到外创建了上千的组件了。
28+
29+
## 了解更多
30+
31+
你可以从这篇[博客](http://facebook.github.io/react/blog/2013/06/05/why-react.html)了解更多我们创造 React 的动机。
32+
33+

docs/docs/getting-started.zh-CN.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
id: getting-started-zh-CN
3+
title: 入门教程
4+
layout: docs
5+
next: tutorial.html
6+
---
7+
8+
## JSFiddle
9+
10+
开始 Hack React 的最简单的方法是用下面 JSFiddle 的Hello Worlds
11+
12+
* **[React JSFiddle](http://jsfiddle.net/vjeux/kb3gN/)**
13+
* [React JSFiddle without JSX](http://jsfiddle.net/vjeux/VkebS/)
14+
15+
## 入门教程包 (Starter Kit)
16+
17+
开始先下载入门教程包
18+
19+
<div class="buttons-unit downloads">
20+
<a href="/react/downloads/react-{{site.react_version}}.zip" class="button">
21+
下载入门教程 {{site.react_version}}
22+
</a>
23+
</div>
24+
25+
在入门教程包的根目录,创建一个含有下面代码的 `helloworld.html`
26+
27+
```html
28+
<!DOCTYPE html>
29+
<html>
30+
<head>
31+
<script src="build/react.js"></script>
32+
<script src="build/JSXTransformer.js"></script>
33+
</head>
34+
<body>
35+
<div id="example"></div>
36+
<script type="text/jsx">
37+
/** @jsx React.DOM */
38+
React.renderComponent(
39+
<h1>Hello, world!</h1>,
40+
document.getElementById('example')
41+
);
42+
</script>
43+
</body>
44+
</html>
45+
```
46+
47+
在 JavaScript 代码里写着 XML 格式的代码称为 JSX;可以去 [JSX 语法](/react/docs/jsx-in-depth.html) 里学习更多 JSX 相关的知识。为了把 JSX 转成标准的 JavaScript,我们用 `<script type="text/jsx">` 标签包裹着含有 JSX 的代码,然后引入 `JSXTransformer.js` 库来实现在浏览器里的代码转换。
48+
49+
### 分离文件
50+
51+
你的 React JSX 代码文件可以写在另外的文件里。新建下面的 `src/helloworld.js`
52+
53+
```javascript
54+
/** @jsx React.DOM */
55+
React.renderComponent(
56+
<h1>Hello, world!</h1>,
57+
document.getElementById('example')
58+
);
59+
```
60+
61+
然后在 `helloworld.html` 引用该文件:
62+
63+
```html{10}
64+
<script type="text/jsx" src="src/helloworld.js"></script>
65+
```
66+
67+
### 离线转换
68+
69+
先安装命令行工具(依赖 [npm](http://npmjs.org/)):
70+
71+
```
72+
npm install -g react-tools
73+
```
74+
75+
然后把你的 `src/helloworld.js` 文件转成标准的 JavaScript:
76+
77+
```
78+
jsx --watch src/ build/
79+
80+
```
81+
82+
只要你修改了, `build/helloworld.js` 文件会自动生成。
83+
84+
```javascript{3}
85+
/** @jsx React.DOM */
86+
React.renderComponent(
87+
React.DOM.h1(null, 'Hello, world!'),
88+
document.getElementById('example')
89+
);
90+
```
91+
92+
> 注意:
93+
>
94+
> 目前注释解析器还是非常严格;为了让它能够找出 `@jsx` 修饰符,有两个限制是必须的。`@jsx` 注释块必须是代码文件第一个注释。注释必须以 `/**` (`/*``//` 不起作用) 开头。如果解析器找不到 `@jsx` 注释,它就不会转换代码,直接原样输出到文件。
95+
96+
对照下面更新你的 HTML 代码
97+
98+
```html{6,10}
99+
<!DOCTYPE html>
100+
<html>
101+
<head>
102+
<title>Hello React!</title>
103+
<script src="build/react.js"></script>
104+
<!-- No need for JSXTransformer! -->
105+
</head>
106+
<body>
107+
<div id="example"></div>
108+
<script src="build/helloworld.js"></script>
109+
</body>
110+
</html>
111+
```
112+
113+
## 想用 CommonJS?
114+
115+
如果你想在一个模块系统里使用 React,[fork 我们的代码](http://github.com/facebook/react)`npm install` 然后运行 `grunt`。一个漂亮的 CommonJS 模块集将会被生成。我们的 `jsx` 转换工具可以很轻松的集成到大部分打包系统里(不仅仅是 CommonJS)。
116+
117+
## 下一步
118+
119+
去看看[入门教程](/react/docs/tutorial.html),然后学习其他在 `/examples` 目录里的示例代码。祝你好运,欢迎来到 React 的世界。
120+

0 commit comments

Comments
 (0)