Skip to content

Conversation

@ifyour
Copy link
Contributor

@ifyour ifyour commented Jul 26, 2018

翻译章节

《API 和 微服务—— Node 和 Express 基础》

变更文件

  • basic-node-and-express.json

  • basic-node-and-express.md

翻译进度

  • 60%

  • 0%

"description": [
"During the development process, it is important to be able to check what’s going on in your code. Node is just a JavaScript environment. Like client side JavaScript, you can use the console to display useful debug information. On your local machine, you would see the console output in a terminal. On Glitch you can open the logs in the lower part of the screen. You can toggle the log panel with the button ‘Logs’ (top-left, under the app name).",
"To get started, just print the classic \"Hello World\" in the console. We recommend to keep the log panel open while working at these challenges. Reading the logs you can be aware of the nature of the errors that may occur."
"在开发中,能够检查代码发生变化这非常重要。Node 只是一个 JavaScript 环境。与客户端 JavaScript 一样,你可以使用控制台输出有用的调试信息。在本地计算机上,你可以在终端中输出调试信息。在 Glitch 上,你可以打开屏幕下方的日志。使用 \"Logs\" 按钮切换日志面板(在左上角,应用名称的下面)。",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the development process, it is important to be able to check what’s going on in your code.
在开发中,能够检查代码发生变化这非常重要。
代码发生变化和控制台有什么关系?
看看这样是不是更准确些:
在开发过程中,能够随时看到代码的运行结果是非常重要的。

{
"text": "<code>\"Hello World\"</code> should be in the console",
"testString": "getUserInput => $.get(getUserInput('url') + '/_api/hello-console').then(data => { assert.isTrue(data.passed, '\"Hello World\" is not in the server console'); }, xhr => { throw new Error(xhr.responseText); })"
"text": "应该在控制台中打印出 <code>\"Hello World\"</code>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会不会好点:
控制台应该输出:<code>\"Hello World\"</code>"

"Let’s serve our first string! In Express, routes takes the following structure: <code>app.METHOD(PATH, HANDLER)</code>. METHOD is an http method in lowercase. PATH is a relative path on the server (it can be a string, or even a regular expression). HANDLER is a function that Express calls when the route is matched.",
"Handlers take the form <code>function(req, res) {...}</code>, where req is the request object, and res is the response object. For example, the handler",
"myApp.js 文件的前两行中,你可以看到创建一个 Express 应用对象是很简单的。这个 Express 对象有几个方法,在这些挑战中,我们将会学习它们更多的方法。一个基础的方法是 <code>app.listen(port)</code>。它告诉服务器监听指定的端口,并且让这个服务处于运行状态。你可以在文件的底部看到它们。它在注释里面,因为出于测试原因,我们需要知道这个应用正在后台运行。你想要添加的所有代码,都放在这两部分之间。Glitch 将端口号存储在环境变量 <code>process.env.PORT</code>中。它的值是 <code>3000</code>",
"我们来让服务器输出第一个字符串!在 Express 中,路由采用这种结构:<code>app.METHOD(PATH, HANDLER)</code>。<code>METHOD</code> 是小写的 http 方法。<code>PATH</code> 是服务器上的相对路径(它是一个字符串,甚至是正则表达式)<code>HANDLER</code> 是 Express 匹配路由时调用的处理函数。",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's == let us 让我们

{
"text": "Your app should serve the string 'Hello Express'",
"testString": "getUserInput => $.get(getUserInput('url')).then(data => { assert.equal(data, 'Hello Express', 'Your app does not serve the text \"Hello Express\"'); }, xhr => { throw new Error(xhr.responseText); })"
"text": "应用应该响应 'Hello Express' 字符串",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app 保留原文不翻译
serve 的翻译应该和你上面保存一致。
app 应该输出 'Hello Express' 字符串。

@huluoyang huluoyang added the need update Use when a translation (?) PR has been reviewed and needs to address comments label Jul 28, 2018
Copy link
Contributor

@S1ngS1ng S1ngS1ng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意 <code> 两边不加空格,任何时候都不加

"While an HTML server serves (you guessed it!) HTML, an API serves data. A <dfn>REST</dfn> (REpresentational State Transfer) API allows data exchange in a simple way, without the need for clients to know any detail about the server. The client only needs to know where the resource is (the URL), and the action it wants to perform on it (the verb). The GET verb is used when you are fetching some information, without modifying anything. These days, the preferred data format for moving information around the web is JSON. Simply put, JSON is a convenient way to represent a JavaScript object as a string, so it can be easily transmitted.",
"Let's create a simple API by creating a route that responds with JSON at the path <code>/json</code>. You can do it as usual, with the <code>app.get()</code> method. Inside the route handler use the method <code>res.json()</code>, passing in an object as an argument. This method closes the request-response loop, returning the data. Behind the scenes it converts a valid JavaScript object into a string, then sets the appropriate headers to tell your browser that you are serving JSON, and sends the data back. A valid object has the usual structure <code>{key: data}</code>. Data can ba a number, a string, a nested object or an array. Data can also be a variable or the result of a function call; in which case it will be evaluated before being converted into a string.",
"Serve the object <code>{\"message\": \"Hello json\"}</code> as a response in JSON format, to the GET requests to the route <code>/json</code>. Then point your browser to your-app-url/json, you should see the message on the screen."
"HTML 服务器返回 HTMLAPI 服务器返回处理的数据。<dfn>REST</dfn>(表现层状态转换)API 允许使用更简易的方式交换数据,从而不需要客户端知道服务器的实现细节。客户端只需要通过 URL 知道请求的资源在哪,以及需要对请求的数据进行何种动作。比如 GET 这个动作,就是从服务器上获取某些信息,它不会修改任何数据。如今,在 web 上传输数据的首选数据格式是 JSON。简言之,JSON 是一种将 JavaScript 对象表示为字符串的简易方式,因此可以很容易地传输这些数据。",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML 服务器返回 HTML,API 服务器返回处理的数据。 建议 =>
HTML 服务器提供 HTML,API 服务器提供数据。


客户端只需要通过 URL 知道请求的资源在哪,以及需要对请求的数据进行何种动作。 =>
客户端只要知道需请求资源对应的 URL 是什么,以及需要对这个 URL 进行何种操作就够了。

注意,不是通过 URL 知道资源在哪儿,而是资源就是 URL。以及,不是对数据进行操作,而是对 URL 进行操作


"Let's create a simple API by creating a route that responds with JSON at the path <code>/json</code>. You can do it as usual, with the <code>app.get()</code> method. Inside the route handler use the method <code>res.json()</code>, passing in an object as an argument. This method closes the request-response loop, returning the data. Behind the scenes it converts a valid JavaScript object into a string, then sets the appropriate headers to tell your browser that you are serving JSON, and sends the data back. A valid object has the usual structure <code>{key: data}</code>. Data can ba a number, a string, a nested object or an array. Data can also be a variable or the result of a function call; in which case it will be evaluated before being converted into a string.",
"Serve the object <code>{\"message\": \"Hello json\"}</code> as a response in JSON format, to the GET requests to the route <code>/json</code>. Then point your browser to your-app-url/json, you should see the message on the screen."
"HTML 服务器返回 HTMLAPI 服务器返回处理的数据。<dfn>REST</dfn>(表现层状态转换)API 允许使用更简易的方式交换数据,从而不需要客户端知道服务器的实现细节。客户端只需要通过 URL 知道请求的资源在哪,以及需要对请求的数据进行何种动作。比如 GET 这个动作,就是从服务器上获取某些信息,它不会修改任何数据。如今,在 web 上传输数据的首选数据格式是 JSON。简言之,JSON 是一种将 JavaScript 对象表示为字符串的简易方式,因此可以很容易地传输这些数据。",
"我们来创建一个简单的 API,通过创建一个简易的路由 <code>/json</code>,当客户端请求这个路由时,返回一个 JSON 数据。你可以像之前那样通过 <code>app.get()</code> 方法来做。在路由处理程序中使用 <code>res.json()</code> 方法返回 JSON 格式的数据,只需要给它传一个对象作为参数。这个方法会结束请求响应循环(request-response loop),然后返回数据。<code>res.json()</code> 将一个有效的 JavaScript 对象转化为字符串,然后会设置适当的头信息(headers)来告诉浏览器,这是一个 JSON 数据,最后返回给客户端进行处理。一个有效的对象通常是这种结构:<code>{key: data}</code>。数据可以是数字、字符串、嵌套对象或数组。也可以是变量或者函数返回值,在这种情况下,将以它们的实际值为准(转成字符串)。",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

route that responds with JSON at the path <code>/json</code>
一个路径为<code>/json</code>且返回数据是 JSON 格式的路由path/json,而不是路由是 /json


。在路由处理程序中使用 <code>res.json()</code> 方法返回 JSON 格式的数据,只需要给它传一个对象作为参数。 不通顺,注意这部分是承接上文的,而且 passing 是对前面的修饰。可以翻译成:
,然后在路由处理部分使用<code>res.json()</code>方法返回 JSON 格式的数据,这个方法可以接收一个配置对象。

https://expressjs.com/en/api.html


将以它们的实际值为准(转成字符串)。 =>
会以它们的执行结果为基准,再转成字符串。

"Handlers take the form <code>function(req, res) {...}</code>, where req is the request object, and res is the response object. For example, the handler",
"myApp.js 文件的前两行中,你可以看到创建一个 Express 应用对象是很简单的。这个 Express 对象有几个方法,在这些挑战中,我们将会学习它们更多的方法。一个基础的方法是 <code>app.listen(port)</code>。它告诉服务器监听指定的端口,并且让这个服务处于运行状态。你可以在文件的底部看到它们。它在注释里面,因为出于测试原因,我们需要知道这个应用正在后台运行。你想要添加的所有代码,都放在这两部分之间。Glitch 将端口号存储在环境变量 <code>process.env.PORT</code>中。它的值是 <code>3000</code>",
"让我们在服务端输出第一个字符串!在 Express 中,路由采用这种结构:<code>app.METHOD(PATH, HANDLER)</code>。<code>METHOD</code> 是小写的 http 方法。<code>PATH</code> 是服务器上的相对路径(它是一个字符串,甚至是正则表达式)<code>HANDLER</code> 是 Express 匹配路由时调用的处理函数。",
"处理函数采用这种形式:<code>function(req, res) {...}</code>,在这个处理函数的参数中 <code>req</code>and 是请求对象。<code>res</code> 是响应对象。举个例子,处理函数:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<code>req</code> 前面多了个空格。

后面的 and 删掉。

Copy link
Contributor

@S1ngS1ng S1ngS1ng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

底下还有很多地方 <code> 前面多了个空格。
有个 and 多余的。
请尽快修改下,别的没问题,先 approve 了

"will serve the string 'Response String'.",
"Use the <code>app.get()</code> method to serve the string Hello Express, to GET requests matching the / root path. Be sure that your code works by looking at the logs, then see the results in your browser, clicking the button ‘Show Live’ in the Glitch UI."
"将会响应一个字符串 'Response String'",
"当 GET 请求根路由( \"/\" )时,使用 <code>app.get()</code> 方法端响应一个 \"Hello Express\" 字符串。在 Glitch 中点击 \"Show Live\" 按钮,通过查看日志确保你的代码正常运行,然后在浏览器中查看结果。"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<code> 前面多了个空格

@S1ngS1ng S1ngS1ng added the :shipit: ship it Use when a translation (?) PR is ready for shipping label Aug 3, 2018
@ifyour
Copy link
Contributor Author

ifyour commented Aug 6, 2018

我先暂时批量替换了<code>code</code>前后的空格,下面还未翻译小节不用 review。🙂

@S1ngS1ng S1ngS1ng removed the need update Use when a translation (?) PR has been reviewed and needs to address comments label Aug 6, 2018
@S1ngS1ng
Copy link
Contributor

S1ngS1ng commented Aug 6, 2018

Thanks 👍

@huluoyang huluoyang merged commit f0e0178 into FreeCodeCampChina:translate Aug 7, 2018
@huluoyang huluoyang removed the :shipit: ship it Use when a translation (?) PR is ready for shipping label Aug 7, 2018
@ifyour ifyour deleted the translate_v2 branch August 7, 2018 15:01
SSShooter pushed a commit to SSShooter/challenges that referenced this pull request Sep 7, 2018
* Translate basic-node-and-express

* Translate basic-node-and-express 2/12 & Revise the previous version

* Translate basic-node-and-express 1/12

* fix typo

* Translate basic-node-and-express 1/12 & revise

* fix typo

* fix typo

* Translate basic-node-and-express 1/12 & Revise the previous version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants