Skip to content

Commit

Permalink
Update Thai translated for Getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
iphayao committed May 27, 2018
1 parent 7dbf73f commit e363e06
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 117 deletions.
4 changes: 2 additions & 2 deletions _includes/header/header-th.html
Expand Up @@ -28,12 +28,12 @@
</li>
<li>
<a href="/{{ page.lang }}/starter/basic-routing.html">
เราเตอร์เบื้องต้น
เส้นทางเบื้องต้น
</a>
</li>
<li>
<a href="/{{ page.lang }}/starter/static-files.html">
ไฟล์แบบสแตติก
บริการไฟล์คงที่
</a>
</li>
<li>
Expand Down
15 changes: 13 additions & 2 deletions css/th.css
@@ -1,7 +1,18 @@
@font-face {
font-family: 'TH SarabunNew';
src: url("../fonts/th/THSarabunNew.woff")
}

#description .description {
position: relative;
top: -5px;
font: 100 4.1em "TH SarabunPSK", "Helvetica Neue", "Open Sans", sans-serif;
font: 100 4.1em "TH SarabunNew", "Helvetica Neue", "Open Sans", sans-serif;
color: #aeaeae;
line-height: .87;
}
}

/* Non-English pages use pre and code tags for code blocks */
.non-en-doc .page pre[class*="language-"] {
padding-top: 10px !important;
padding-bottom: 10px !important;
}
Binary file added fonts/th/THSarabunNew.woff
Binary file not shown.
33 changes: 16 additions & 17 deletions th/starter/basic-routing.md
Expand Up @@ -5,61 +5,60 @@ menu: starter
lang: th
---

# Basic routing
# เส้นทางเบื้องต้น

_Routing_ refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on).
_เส้นทาง (Routing)_ เป็นการกำหนดการอ้างอิงว่าแอปพลิเคชันจะตอบสนองต่อคำร้องขอของเครื่องลูกข่ายที่มายังปลายทาง (endpoint) โดยเฉพาะได้อย่างไร ซึ่งเป็น URI (หรือ path) และวิธีการร้องขอ HTTP (GET, POST, และ อื่นๆ)

Each route can have one or more handler functions, which are executed when the route is matched.
แต่ละเส้นทางสามารถมีได้มากกว่าหนึ่งฟังชันส์จัดการ (handler function) ซึ่งสามารถดำเนินการเมื่อเส้นทางถูกจับคู่

Route definition takes the following structure:
การกำหนดเส้นทางใช้โครงสร้างดังนี้:

```js
app.METHOD(PATH, HANDLER)
```

Where:
เมื่อ:

- `app` is an instance of `express`.
- `METHOD` is an [HTTP request method](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods), in lowercase.
- `PATH` is a path on the server.
- `HANDLER` is the function executed when the route is matched.
- `app` เป็นอินสแตนซ์ของ `express`.
- `METHOD` เป็น [HTTP request method](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods), เป็นตัวพิมพ์เล็ก.
- `PATH` เป็นเส้นทางบนเซิร์ฟเวอร์.
- `HANDLER` เป็นฟังชันส์ที่กระทำเมื่อเส้นทางถูกจับคู่.

<div class="doc-box doc-notice" markdown="1">
This tutorial assumes that an instance of `express` named `app` is created and the server is running. If you are not familiar with creating an app and starting it, see the [Hello world example](/{{ page.lang }}/starter/hello-world.html).
การสอนนี้จะสมมติว่าอินสแตนซ์ของ `express` ชื่อว่า `app` จะถูกสร้างขึ้นเมื่อรันเซิร์ฟเวอร์ ถ้าไม่คุ้นเคยกับการสร้าง app และโครงสร้างของมัน ดูเพิ่มเติมได้ที่ [ตัวอย่าง Hello world](/{{ page.lang }}/starter/hello-world.html)
</div>

The following examples illustrate defining simple routes.
ตัวอย่างดังต่อไปนี้จะแสดงให้เห็นการกำหนดเส้นทางอย่างง่าย

Respond with `Hello World!` on the homepage:
ตอบสนองด้วยข้อความ `Hello World!` บนเพจหลัก:

```js
app.get('/', function (req, res) {
res.send('Hello World!')
})
```

Respond to POST request on the root route (`/`), the application's home page:
ตอบสนองต่อการร้องขอด้วยวิธี POST บนเส้นทาง root (`/`) บนเพจหลักของแอปพลิเคชัน:

```js
app.post('/', function (req, res) {
res.send('Got a POST request')
})
```

Respond to a PUT request to the `/user` route:
ตอบสนองต่อการร้องขอด้วยวิธี PUT บนเส้นทาง `/user`:

```js
app.put('/user', function (req, res) {
res.send('Got a PUT request at /user')
})
```

Respond to a DELETE request to the `/user` route:
ตอบสนองต่อการร้องขอด้วยวิธี DELETE บนเส้นทาง `/user`:

```js
app.delete('/user', function (req, res) {
res.send('Got a DELETE request at /user')
})
```

For more details about routing, see the [routing guide](/{{ page.lang }}/guide/routing.html).
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการกำหนดเส้นทาง ดูได้ที่ [คำแนะนำการกำหนดเส้นทาง](/{{ page.lang }}/guide/routing.html)
72 changes: 31 additions & 41 deletions th/starter/faq.md
Expand Up @@ -5,70 +5,62 @@ menu: starter
lang: th
---

# FAQ
# คำถามที่พบบ่อย

## How should I structure my application?
## โครงสร้างแอปพลิเคชันของผมควรจะเป็นอย่าไร?

There is no definitive answer to this question. The answer depends
on the scale of your application and the team that is involved. To be as
flexible as possible, Express makes no assumptions in terms of structure.
ไม่มีการกำหนดนิยามของคำตอบสำหรับคำถามนี้ คำตอบขึ้นอยู่กับว่าขนาดของแอปพลิเคชันเท่าใด
และทีมงานที่ร่วมทำงานด้วยมีจำนวนขนาดไหน เพื่อที่จะทำงานคล่องตัวที่สุด Express ไม่มีข้อบังคับของโครงสร้าง

Routes and other application-specific logic can live in as many files
as you wish, in any directory structure you prefer. View the following
examples for inspiration:
เส้นทางและตรรกะเฉพาะแอปพลิเคชัน (application-specific) อื่นๆ สามารถทำงานในหลากหลายไฟล์ที่คุณต้องการ
ในหลายๆ ไดเรกเทอรีที่คุณต้องการ สามารถดูตัวอย่างด้านล่างนี้เพื่อเป็นแนวทาง:

* [Route listings](https://github.com/strongloop/express/blob/4.13.1/examples/route-separation/index.js#L32-47)
* [Route map](https://github.com/strongloop/express/blob/4.13.1/examples/route-map/index.js#L52-L66)
* [MVC style controllers](https://github.com/strongloop/express/tree/master/examples/mvc)

Also, there are third-party extensions for Express, which simplify some of these patterns:
ยังมีแหล่งตัวอย่างอื่นๆ สำหรับ Express ซึ่งทำให้ง่ายโดยใช้รูปแบบ:

* [Resourceful routing](https://github.com/expressjs/express-resource)

## How do I define models?
## จะกำหมดโมเกลอย่างไร?

Express has no notion of a database. This concept is
left up to third-party Node modules, allowing you to
interface with nearly any database.
Express ไม่มีความคิดของฐานข้อมูล แนวคิดนี้อยู่ในโมดูลอื่นของ Node ที่จะทำให้คุณติดต่อกับหลากหลายฐานข้อมูล

See [LoopBack](http://loopback.io) for an Express-based framework that is centered around models.
ดู [LoopBack](http://loopback.io) for an Express-based framework that is centered around models.

## How can I authenticate users?
## จะพิสูจน์ตัวตนของผู้ใช้งานได้อย่างไร?

Authentication is another opinionated area that Express does not
venture into. You may use any authentication scheme you wish.
For a simple username / password scheme, see [this example](https://github.com/expressjs/express/tree/master/examples/auth).
การพิสูจน์ตัวตนของผู้ใช้งานเป็นอีกส่วนหนี่งที่ Express ไม่ได้เข้าร่วม คุณอาจใช้รูปแบบพิสูจน์ตัวตนของผู้ใช้งานที่คุณต้องการ
สำหรับตัวอย่างที่ง่ายที่สุดคือรูปแบบ username / password, ดู [ตัวอย่างนี้](https://github.com/expressjs/express/tree/master/examples/auth)


## Which template engines does Express support?
## template engines ไหนบ้างที่ Express รองรับ?

Express supports any template engine that conforms with the `(path, locals, callback)` signature.
To normalize template engine interfaces and caching, see the
[consolidate.js](https://github.com/visionmedia/consolidate.js)
project for support. Unlisted template engines might still support the Express signature.
Express รองรับทุก template engine ที่สอดคล้องกับ `(path, locals, callback)`
เพื่อสร้างอินเทอร์เฟสสำหรับ template engine และการเคช ดูที่ [consolidate.js](https://github.com/visionmedia/consolidate.js)
โครงการที่รองรับ ที่ไม่อยู่ในรายการ template engines อาจยังคงรองรับโดย Express

For more information, see [Using template engines with Express](/{{page.lang}}/guide/using-template-engines.html).
สำหรับข้อมูลเพิ่มเติม, ดูที่ [การใช้ template engine กับ Express](/{{page.lang}}/guide/using-template-engines.html)

## How do I handle 404 responses?
## จะจัดการกับการตอบสนอง 404 ได้อย่างไร?

In Express, 404 responses are not the result of an error, so
the error-handler middleware will not capture them. This behavior is
because a 404 response simply indicates the absence of additional work to do;
in other words, Express has executed all middleware functions and routes,
and found that none of them responded. All you need to
do is add a middleware function at the very bottom of the stack (below all other functions)
to handle a 404 response:
ใน Express, การตอบสนอง 404 ไม่ใช้ผลของความผิดพลาด ดังนั้น
มิดเดิลแวร์ที่จัดการกับความผิดพลาด (error-handler) จะไม่ตรวจจับมัน พฤติกรรมเป็นแบบนี้
เพราะว่าการตอบสนอง 404 เป็นการบ่งชี้ว่ามีสิ่งผิดปรกติเกิดขึ้นอาจจะต้อมีสิ่งเพิ่มเติมมาจัดการ
ในงานอื่นๆ Express จะดำเนินการฟังก์ชันมิดเดิลแวร์และเส้นทางทั้งหมด และพบว่าไม่มีอะไรที่จะตอบสนอง
สิ่งที่คุณต้องทำคือเพิ่มฟังก์ชันมิดเดิลแวร์ที่ด้านล่างสุดเพื่อจัดการกับการตอบสนอง 404:

```js
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
```

## How do I setup an error handler?
## จะตั้งค่าจัดการความผิดพลาดได้อย่างไร?

You define error-handling middleware in the same way as other middleware,
except with four arguments instead of three; specifically with the signature `(err, req, res, next)`:
กำหนดมิดเดิลแวร์จัดการความผิดพลาด (error-handler) เช่นเดียวกับมิดเดิลแวร์อื่น ยกเว้นอาร์กิวเมนต์ 4 ตัวแทนที่จะเป็น 3 ตัว
ดังนี้ `(err, req, res, next)`

```js
app.use(function (err, req, res, next) {
Expand All @@ -77,11 +69,9 @@ app.use(function (err, req, res, next) {
})
```

For more information, see [Error handling](/{{ page.lang }}/guide/error-handling.html).
สำหรับข้อมูลเพิ่มเติม, ดูที่ [Error handling](/{{ page.lang }}/guide/error-handling.html).

## How do I render plain HTML?
## จะสร้าง HTML ธรรมดาได้อย่างไร?

You don't! There's no need to "render" HTML with the `res.render()` function.
If you have a specific file, use the `res.sendFile()` function.
If you are serving many assets from a directory, use the `express.static()`
middleware function.
คุณไม่ต้อง! ไม่จำเป็นต้องสร้าง HTML ด้วยฟังก์ชัน `res.render()`
ถ้าคุณมีไฟล์เฉพาะ ใช้ฟังก์ชัน `res.sendFile()` ถ้าคุณต้องการบริการหลายสินทรัพย์จากไดเรกเทอรี ใช้ฟังก์ชันมิดเดิลแวร์ `express.static()`
25 changes: 11 additions & 14 deletions th/starter/generator.md
Expand Up @@ -5,17 +5,16 @@ menu: starter
lang: th
---

# Express application generator
# เครื่องมือสร้าง Express

Use the application generator tool, `express-generator`, to quickly create an application skeleton.
ใช้เครื่องมือสร้าง โดยพินพ์คำสั่ง `express-generator` เพื่อสร้างโครงสร้างหลักของแอปพลิเคชันอย่างรวดเร็ว

The `express-generator` package installs the `express` command-line tool. Use the following command to do so:
`express-generator` ติดตั้งแพ็กเกจไปยังชุดคำสั่ง `express` ใช้คำสั่งด้านล่างนี้เพื่อติดตั้ง:

```sh
$ npm install express-generator -g
```

Display the command options with the `-h` option:
แสดงตัวเลือกคำสั่งทั้งหมดด้วย `h`:

```sh
$ express -h
Expand All @@ -35,8 +34,7 @@ $ express -h
--git add .gitignore
-f, --force force on non-empty directory
```

For example, the following creates an Express app named _myapp_. The app will be created in a folder named _myapp_ in the current working directory and the view engine will be set to <a href="https://pugjs.org/" target="_blank" title="Pug documentation">Pug</a>:
สำหรับตัวอย่าง คำสั่งข้างล่างนี้เพื่อสร้าง Express app ที่ชื่อว่า _myapp_ โดยจะสร้างโฟล์เดอร์ชื่อ _myapp_ ในไดเรกเทอรีที่ใช้งานอยู่ และตั้ง view engine เป็น <a href="https://pugjs.org/" target="_blank" title="Pug documentation">Pug</a>:

```sh
$ express --view=pug myapp
Expand All @@ -59,29 +57,28 @@ $ express --view=pug myapp
create : myapp/bin
create : myapp/bin/www
```

Then install dependencies:
แล้วติดตั้งโมดูลเกี่ยวโยง (dependencies):

```sh
$ cd myapp
$ npm install
```

On MacOS or Linux, run the app with this command:
บน MacOS หรือ Linux รัน app ด้วยคำสั่งนี้:

```sh
$ DEBUG=myapp:* npm start
```

On Windows, use this command:
บน Windows ใช้คำสั่งนี้:

```sh
> set DEBUG=myapp:* & npm start
```

Then load `http://localhost:3000/` in your browser to access the app.
แล้วโหลด `http://localhost:3000/` ในเว็บเบราว์เซอร์ของคุณเพื่อเข้าถึง app

The generated app has the following directory structure:
หลังจากสร้าง app แล้วจะได้โครงสร้างไดเรกทอรีดังนี้:

```sh
.
Expand All @@ -106,5 +103,5 @@ The generated app has the following directory structure:
```

<div class="doc-box doc-info" markdown="1">
The app structure created by the generator is just one of many ways to structure Express apps. Feel free to use this structure or modify it to best suit your needs.
โครงสร้าง app ที่สร้างโดยเครื่องมือสร้างเป็นเพียงวิธีหนึ่งของอีกหลายวิธี ของการสร้างโครงสร้าง app ของ Express สามารถใช้โครงสร้างนี้ได้ หรือว่าจะแก้ไขเพื่อให้เหมาะสมที่สุดสำหรับความต้องการของคุณ
</div>

0 comments on commit e363e06

Please sign in to comment.