Skip to content

Commit

Permalink
Merge pull request #1 from jiyinyiyong/cn
Browse files Browse the repository at this point in the history
翻译页面开头部分
  • Loading branch information
island205 committed Oct 9, 2013
2 parents 95ede2c + e82e122 commit 47ff340
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 170 deletions.
154 changes: 69 additions & 85 deletions documentation/index.html
Expand Up @@ -16,12 +16,12 @@
<a id="logo" href="#top"><img src="documentation/images/logo.png" width="225" height="39" alt="CoffeeScript" /></a>
<div class="navigation toc">
<div class="button">
Table of Contents
目录
</div>
<div class="contents menu">
<a href="#overview">Overview</a>
<a href="#installation">Installation</a>
<a href="#usage">Usage</a>
<a href="#overview">概览</a>
<a href="#installation">安装</a>
<a href="#usage">用法</a>
<a href="#literate">Literate CoffeeScript</a>
<a href="#language">Language Reference</a>
<a href="#literals">Literals: Functions, Objects and Arrays</a>
Expand Down Expand Up @@ -49,7 +49,7 @@
</div>
<div class="navigation try">
<div class="button">
Try CoffeeScript
试一试 CoffeeScript
<div class="repl_bridge"></div>
</div>
<div class="contents repl_wrapper">
Expand All @@ -70,7 +70,7 @@
</div>
<div class="navigation annotated">
<div class="button">
Annotated Source
代码和注释
</div>
<div class="contents menu">
<a href="documentation/docs/grammar.html">Grammar Rules &mdash; src/grammar</a>
Expand All @@ -94,23 +94,21 @@
<span class="bookmark" id="top"></span>

<p>
<b>CoffeeScript is a little language that compiles into JavaScript.</b>
Underneath that awkward Java-esque patina, JavaScript has always had
a gorgeous heart. CoffeeScript is an attempt to expose
the good parts of JavaScript in a simple way.
<b>CoffeeScript 是一门编译到 JavaScript 的小巧语言.</b>
在 Java 般笨拙的外表下, JavaScript 其实是内秀.
CoffeeScript 是个尝试, 用简洁的方式展示 JavaScript 优秀的部分.
</p>

<p>
The golden rule of CoffeeScript is: <i>"It's just JavaScript"</i>. The code
compiles one-to-one into the equivalent JS, and there is
no interpretation at runtime. You can use any existing JavaScript library
seamlessly from CoffeeScript (and vice-versa). The compiled output is
readable and pretty-printed, will work in every JavaScript runtime, and tends
to run as fast or faster than the equivalent handwritten JavaScript.
CoffeeScript 的指导原则是: <b>"她仅仅是 JavaScript"</b>.
她的代码一一对应地编译到 JS, 不会在编译过程中进行解释.
已有的 JavaScript 类库可以无缝地和 CoffeeScript 搭配使用, 反之亦然.
编译后的代码是可读的, 且经过美化, 能在所有 JavaScript 环境中运行,
并且应该和对应手写的 JavaScript 一样快或者更快.
</p>

<p>
<b>Latest Version:</b>
<b>最新版本:</b>
<a href="http://github.com/jashkenas/coffee-script/tarball/1.6.3">1.6.3</a>
</p>

Expand All @@ -119,167 +117,153 @@

<h2>
<span id="overview" class="bookmark"></span>
Overview
概览
</h2>

<p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
<p>左边是 CoffeeScript, 右边是编译后的 JavaScript.</p>

<%- @code_for 'overview', 'cubes', false %>

<h2>
<span id="installation" class="bookmark"></span>
Installation
安装
</h2>

<p>
The CoffeeScript compiler is itself
<a href="documentation/docs/grammar.html">written in CoffeeScript</a>,
using the <a href="http://jison.org">Jison parser generator</a>. The
command-line version of <tt>coffee</tt> is available as a
<a href="http://nodejs.org/">Node.js</a> utility. The
<a href="extras/coffee-script.js">core compiler</a> however, does not
depend on Node, and can be run in any JavaScript environment, or in the
browser (see "Try CoffeeScript", above).
CoffeeScript 编译器本身<a href="documentation/docs/grammar.html">是 CoffeeScript 写的</a>,
使用了 <a href="http://jison.org">Jison parser generator</a>.
命令行版本的 <tt>coffee</tt> 是一个实用的 <a href="http://nodejs.org/">Node.js</a> 工具.
不过<a href="extras/coffee-script.js">编译器</a>并不依赖 Node,
而是能做运行于任何 JavaScript 环境, 或者说在浏览器里(看上边的"试一试 CoffeeScript").
</p>

<p>
To install, first make sure you have a working copy of the latest stable version of
<a href="http://nodejs.org/">Node.js</a>, and <a href="http://npmjs.org">npm</a>
(the Node Package Manager). You can then install CoffeeScript with npm:
安装前你需要最新稳定版 <a href="http://nodejs.org/">Node.js</a>,
<a href="http://npmjs.org">npm</a> (Node Package Manager).
借助 npm 可以安装 CoffeeScript:
</p>

<pre>
npm install -g coffee-script</pre>

<p>
(Leave off the <tt>-g</tt> if you don't wish to install globally.)
(如果不想全局安装可以去掉 <tt>-g</tt> 选项.)
</p>

<p>
If you'd prefer to install the latest <b>master</b> version of CoffeeScript, you
can clone the CoffeeScript
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
from GitHub, or download
<a href="http://github.com/jashkenas/coffee-script/tarball/master">the source</a> directly.
To install the lastest master CoffeeScript compiler with npm:
如果你希望安装 <b>master</b> 分支上最新的 CoffeeScript,
你可以从<a href="http://github.com/jashkenas/coffee-script">源码仓库</a> clone CoffeeScript,
或直接下载<a href="http://github.com/jashkenas/coffee-script/tarball/master">源码</a>.
还有通过 npm 方式安装 master 分支最新的 CoffeeScript 编译器:
</p>

<pre>
npm install -g http://github.com/jashkenas/coffee-script/tarball/master</pre>

<p>
Or, if you want to install to <tt>/usr/local</tt>, and don't want to use
npm to manage it, open the <tt>coffee-script</tt> directory and run:
或者你想将其安装到 <tt>/usr/local</tt>, 而不用 npm 进行管理,
进入 <tt>coffee-script</tt> 目录执行:
</p>

<pre>
sudo bin/cake install</pre>

<h2>
<span id="usage" class="bookmark"></span>
Usage
用法
</h2>

<p>
Once installed, you should have access to the <tt>coffee</tt> command,
which can execute scripts, compile <tt>.coffee</tt> files into <tt>.js</tt>,
and provide an interactive REPL. The <tt>coffee</tt> command takes the
following options:
安装之后, 应该也可以执行的 <tt>coffee</tt> 命令, 可以用来执行脚本,
编译 <tt>.coffee</tt> 文件到 <tt>.js</tt> 文件, 和提供一个交互式的 REPL.
<tt>coffee</tt> 命令有下列参数:
</p>

<table>
<tr>
<td><code>-c, --compile</code></td>
<td>
Compile a <tt>.coffee</tt> script into a <tt>.js</tt> JavaScript file
of the same name.
编译一个 <tt>.coffee</tt> 脚本到一个同名的 <tt>.js</tt> 的 JavaScript 文件.
</td>
</tr>
<tr>
<td><code>-m, --map</code></td>
<td>
Generate source maps alongside the compiled JavaScript files. Adds
<tt>sourceMappingURL</tt> directives to the JavaScript as well.
随 JavaScript 文件一起生成 source maps. 并且在 JavaScript 里加上 <tt>sourceMappingURL</tt> 指令.
</td>
</tr>
<tr>
<td width="25%"><code>-i, --interactive</code></td>
<td>
Launch an interactive CoffeeScript session to try short snippets.
Identical to calling <tt>coffee</tt> with no arguments.
启动一个交互式的 CoffeeScript 回话用来尝试一些代码片段.
等同于执行 <tt>coffee</tt> 而不加参数.
</td>
</tr>
<tr>
<td><code>-o, --output [DIR]</code></td>
<td>
Write out all compiled JavaScript files into the specified directory.
Use in conjunction with <tt>--compile</tt> or <tt>--watch</tt>.
将所有编译后的 JavaScript 文件写到指定文件夹.
<tt>--compile</tt> <tt>--watch</tt> 搭配使用.
</td>
</tr>
<tr>
<td><code>-j, --join [FILE]</code></td>
<td>
Before compiling, concatenate all scripts together in the order they
were passed, and write them into the specified file.
Useful for building large projects.
编译之前, 按参数传入顺序连接所有脚本到一起, 编译后写到指定的文件.
对于编译大型项目有用.
</td>
</tr>
<tr>
<td><code>-w, --watch</code></td>
<td>
Watch files for changes, rerunning the specified command when any
file is updated.
监视文件改变, 任何文件更新时重新执行命令.
</td>
</tr>
<tr>
<td><code>-p, --print</code></td>
<td>
Instead of writing out the JavaScript as a file, print it
directly to <b>stdout</b>.
JavaScript 直接打印到 <b>stdout</b> 而不是写到一个文件.
</td>
</tr>
<tr>
<td><code>-s, --stdio</code></td>
<td>
Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
Good for use with processes written in other languages. An example:<br />
CoffeeScript 传递到 STDIN 后从 STDOUT 获取 JavaScript.
对其他语言写的进程有好处. 比如:<br />
<tt>cat src/cake.coffee | coffee -sc</tt>
</td>
</tr>
<tr>
<td><code>-l, --literate</code></td>
<td>
Parses the code as Literate CoffeeScript. You only need to specify
this when passing in code directly over <b>stdio</b>, or using some sort
of extension-less file name.
将代码作为 Literate CoffeeScript 解析.
只会在从 <b>stdio</b> 直接传入代码或者处理某些没有后缀的文件名需要写明这点.
</td>
</tr>
<tr>
<td><code>-e, --eval</code></td>
<td>
Compile and print a little snippet of CoffeeScript directly from the
command line. For example:<br /><tt>coffee -e "console.log num for num in [10..1]"</tt>
直接从命令行编译和打印一小段 CoffeeScript. 比如:<br />
<tt>coffee -e "console.log num for num in [10..1]"</tt>
</td>
</tr>
<tr>
<td><code>-b, --bare</code></td>
<td>
Compile the JavaScript without the
<a href="#lexical-scope">top-level function safety wrapper</a>.
编译到 JavaScript 时去掉<a href="#lexical-scope">顶层函数的包裹</a>.
</td>
</tr>
<tr>
<td><code>-t, --tokens</code></td>
<td>
Instead of parsing the CoffeeScript, just lex it, and print out the
token stream: <tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
不对 CoffeeScript 进行解析, 仅仅进行 lex, 打印出 token stream:
<tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
</td>
</tr>
<tr>
<td><code>-n, --nodes</code></td>
<td>
Instead of compiling the CoffeeScript, just lex and parse it, and print
out the parse tree:
不对 CoffeeScript 进行编译, 仅仅 lex 和解析, 打印 parse tree:
<pre class="no_bar">
Expressions
Assign
Expand All @@ -293,42 +277,42 @@ <h2>
<tr>
<td><code>--nodejs</code></td>
<td>
The <tt>node</tt> executable has some useful options you can set,
such as<br /> <tt>--debug</tt>, <tt>--debug-brk</tt>, <tt>--max-stack-size</tt>,
and <tt>--expose-gc</tt>. Use this flag to forward options directly to Node.js.
To pass multiple flags, use <tt>--nodejs</tt> multiple times.
<tt>node</tt> 命令有一些实用的参数, 比如<br />
<tt>--debug</tt>, <tt>--debug-brk</tt>, <tt>--max-stack-size</tt>,
<tt>--expose-gc</tt>. 用这个参数直接把参数转发到 Node.js.
重复使用 <tt>--nodejs</tt> 来传递多个参数.
</td>
</tr>
</table>

<p>
<b>Examples:</b>
<b>例子:</b>
</p>

<ul>
<li>
Compile a directory tree of <tt>.coffee</tt> files in <tt>src</tt> into a parallel
tree of <tt>.js</tt> files in <tt>lib</tt>:<br />
编译一个 <tt>.coffee</tt> 文件的树形目录 <tt>src</tt> 到一个同级
<tt>.js</tt> 文件树形目录 <tt>lib</tt>:<br />
<tt>coffee --compile --output lib/ src/</tt>
</li>
<li>
Watch a file for changes, and recompile it every time the file is saved:<br />
监视一个文件的改变, 每次文件被保证时重新编译:<br />
<tt>coffee --watch --compile experimental.coffee</tt>
</li>
<li>
Concatenate a list of files into a single script:<br />
合并一组文件到单个脚本:<br />
<tt>coffee --join project.js --compile src/*.coffee</tt>
</li>
<li>
Print out the compiled JS from a one-liner:<br />
从一个 one-liner 打印编译后的 JS:<br />
<tt>coffee -bpe "alert i for i in [0..10]"</tt>
</li>
<li>
All together now, watch and recompile an entire project as you work on it:<br />
现在全部一起, 在你工作时监视和重复编译整个项目:<br />
<tt>coffee -o lib/ -cw src/</tt>
</li>
<li>
Start the CoffeeScript REPL (<tt>Ctrl-D</tt> to exit, <tt>Ctrl-V</tt>for multi-line):<br />
运行 CoffeeScript REPL (<tt>Ctrl-D</tt> 来终止, <tt>Ctrl-V</tt> 激活多行):<br />
<tt>coffee</tt>
</li>
</ul>
Expand Down

0 comments on commit 47ff340

Please sign in to comment.