Skip to content

Commit be3c9c2

Browse files
committed
translate some /intro-to-rails pages to zh-tw
1 parent 7994475 commit be3c9c2

5 files changed

+89
-99
lines changed

sites/zh-tw/intro-to-rails/CRUD_with_scaffolding.step

+34-46
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
goals {
33

44
message <<-MARKDOWN
5-
At the core, most database driven web sites are the same. They need to store records and provide a way to do the following:
5+
大部份基於資料庫的網站,其核心都是一樣的,都要把資料存起來並且提供方法來做這些事:
66

7-
* **C**reate new records in the database
8-
* **R**ead or show the records in the database
9-
* **U**pdate existing records
10-
* **D**estroy or delete records
7+
* **C** - 建立(**C**reate)新資料並存進資料庫。
8+
* **R** - 讀取(**R**ead)或顯示資料庫裡的資料。
9+
* **U** - 更新(**U**pdate)既有的資料。
10+
* **D** - 刪除(**D**estroy)資料。
1111

12-
Because these 4 actions (CRUD) are so common, rails includes the scaffold command to make creating them easier.
12+
這四個操作(CRUD)常見到 Rails 把它內建到 scaffold 指令裡面,我們可以很容易實作出來。
1313
MARKDOWN
1414
}
1515

@@ -20,87 +20,75 @@ steps {
2020
}
2121

2222
step {
23-
message "Point your browser to [http://localhost:3000/topics](http://localhost:3000/topics)"
24-
message "You should see a page listing topics that looks something like this:"
23+
message "在瀏覽器打開 [http://localhost:3000/topics](http://localhost:3000/topics)"
24+
message "你應該會看到一個頁面,列出所有 topics ,長得像這樣:"
2525

2626
img src: "img/Seattle_topic_list_page.png", alt: "Topic List Page"
2727
}
2828

2929
step {
3030
message <<-MARKDOWN
31-
* Click on "New Topic"
32-
* Fill in the form and click "Create Topic"
33-
* You should see a confirmation page like this:
31+
* 按一下 "New Topic"
32+
* 填寫表單,然後按一下 "Create Topic"
33+
* 你應該會看到一個確認頁,像這樣:
3434
MARKDOWN
3535

3636
img alt: "topic created", src: "img/Seattle_topic_created.png"
3737
}
3838

3939
step {
4040
message <<-MARKDOWN
41-
* Click on "back"
42-
* You should see the topic list again, this time with your new topic listed:
41+
* 按一下 "back"
42+
* 你應該會再看到 topics 列表,這次還有你剛剛新增的 topic
4343

4444
![list with topic](img/Seattle_list_with_topic.png)
4545

46-
* Try the 'show', 'edit', and 'destroy' links to see what they do
47-
* You've created a basic database driven web site, congrats!
46+
* 試試看 'show''edit''destroy' 連結看看會發生什麼事。
47+
* 賀!你已經建立了一個基本的資料庫網站了!
4848
MARKDOWN
4949
}
5050
}
5151

5252
explanation {
5353

5454
message <<-MARKDOWN
55-
How did all those pages get created and hooked together? The rails scaffold did it for you.
55+
這些網頁到底怎麼建出來,又是如何連在一起的呢?Rails 的 scaffold 幫你處理好了。
5656

57-
Let's take a closer look at some of the files rails created:
57+
我們來仔細瞧瞧 rails 幫我們建立的檔案:
5858

5959
* `app/models/topic.rb`
60-
* This file contains code for our topic model. If you look at it,
61-
it's nearly blank. Creating, reading, updating, and deleting
62-
records are built into rails.
60+
* 這個檔案裡面有我們的 topic model 的程式碼。如果你仔細看,他其實幾乎是空白的。
61+
對資料的新增、讀取、更新、刪除操作在 Rails 是內建的。
6362

6463
* `app/views/topics`
65-
* This folder contains all the views for our topics model. This is
66-
where the code for the forms you used above is stored. Rails
67-
created all of these pages as part of the scaffold.
68-
* If you've written HTML before, many lines in the views should
69-
look familiar. Rails views are HTML with some extra code added
70-
to display data from the database.
64+
* 這個資料夾裡面有我們的 topics model 的 view 的程式碼。
65+
你剛剛使用的表單的程式碼就放在這裡面。Rails 會幫你建好這些檔案作為 scaffold 的一部分。
66+
* 如果你以前寫過 HTML,這些程式你應該不陌生。
67+
Rails 的 view 只是 HTML 加上一些用來顯示資料庫來的資料的程式。
7168

7269
* `app/views/topics/index.html.erb`
73-
* This is the code for the page that lists all the topics.
74-
* Index is the name given to the "default" page for a web site or a
75-
section of a web site. When you navigate to
76-
http://localhost:3000/topics the topics index page is what is
77-
sent to your computer.
70+
* 這個程式是用在列出所有 topics 的頁面。
71+
* index 是用來表示一個網站或網站的一部分的「預設」頁面。當你打開
72+
http://localhost:3000/topics 的時候,topics 的 index 頁面會傳送到你的電腦上。
7873

7974
* `app/views/topics/show.html.erb`
80-
* This is the page you get when you click the "show" link on the
81-
"Listing topics" page.
75+
* 是當你在 "Listing topics" 按一下 "show" 時會看到的頁面。
8276

8377
* `app/views/topics/new.html.erb`
84-
* This is the page you get when you click on "New Topic".
78+
* 是當你按一下 "New Topic" 時會看到的頁面。
8579

8680
* `app/views/topics/edit.html.erb`
87-
* This is the page you get when you click on "Edit"
81+
* 是當你按一下 "Edit" 時會看到的頁面。
8882

8983
* `app/views/topics/_form.html.erb`
90-
* You may have noticed that the page for new topics and the page
91-
to edit topics looked similar. That's because they both use the
92-
code from this file to show a form. This file is called a
93-
partial since it only contains code for part of a page. Partials
94-
always have filenames starting with an underscore character.
84+
* 你或許注意到了,新增 topic 和編輯 topics 的頁面長得很像。這是因為他們都使用了這個檔案來顯示表單。
85+
這種檔案稱作 "partial",因為他只有網頁裡面一部分的內容。Partial 的檔名一定是底線開頭的。
9586

96-
* Challenge question: Can you find the line of code in new.html.erb
97-
and edit.html.erb that makes the form partial appear?
87+
* 挑戰題:你可以找到 partial 是在 new.html.erb 和 edit.html.erb 的哪一行程式被引用的嗎?
9888

9989
* `app/controllers/topics_controller.rb`
100-
* This is the controller file that rails created as part of the scaffold
101-
* If you look you'll see a method (a line beginning with
102-
<code>def</code>) for each of the views listed above (except
103-
_form.html.erb)
90+
* 這稱為 controller 檔,Rails 自動透過 scaffold 產生的。
91+
* 如果你打開來看,你會看到每一個 view ,除了 _form.html.erb 之外都對應到一個 method(開頭是 `def`)。
10492
MARKDOWN
10593
}
10694

sites/zh-tw/intro-to-rails/add_the_project_to_a_git_repo.step

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11

22
goals do
3-
goal "Create a local git repository"
4-
goal "Add all our files to the git repository"
3+
goal "建一個本地的 git repository(倉庫)"
4+
goal "把所有檔案加入 git repository"
55

6-
message "In order to publish our application, we need to add our application and any changes we make over time to a \"revision control system\". In our case we're going to use *git* because it is (relatively) easy and it is what our app server, *Heroku*, uses."
6+
message "為了把我們的應用程式發佈到網路上,我們要把我們的程式和過程中的修改都加到「版本控制系統」。我們會用 *git* ,因為它比較簡單,而且 Heroku 也用它。"
77
end
88

99
steps do
1010

1111
step do
1212
console "git init"
1313

14-
message "It doesn't look like anything really happened, but 'git init' initialized its repository (repo) in a hidden directory called `.git`. You can see this by typing `ls -a` (list all files)."
14+
message "跑完之後它看起來沒有做什麼事,然而事實上 'git init' 已經把 repository(repo)初始化到一個叫做 `.git` 的資料夾。
15+
你可以打 `ls -a` (列出所有檔案)來看到它。"
1516
end
1617

1718
step do
1819
console "git status"
1920

20-
message "`git status` tells you everything git sees as modified, new, or missing."
21-
message "The first time you run this, you should see a ton of stuff."
22-
message "The second time you run this, you shouldn't see much of anything."
21+
message "`git status` 會告訴你 git 所見所有改過、新增、刪掉的東西。"
22+
message "第一次跑這個指令的時候,會看到很多東西。"
23+
message "第二次跑這個指令的時候,你不會看到很多東西。"
2324
end
2425

2526
step do
2627
console "git add ."
27-
message "`git add .` tells git that you want to add the current directory (aka `.`) and everything under it to the repo."
28+
message "`git add .` 告訴 git 你想要把目前資料夾(即 `.`)還有它底下的所有東西加進 repo"
2829
tip "git add" do
2930
message <<-MARKDOWN
30-
With Git, there are usually many ways to do very similar things.
31+
Git 裡,有多個指令可以做到類似的事:
3132

32-
* `git add foo.txt` adds a file named `foo.txt`
33-
* `git add .` adds all new files and changed files, but *keeps* files that you've deleted
34-
* `git add -A` adds everything, including deletions
33+
* `git add foo.txt` 把名叫 `foo.txt` 的檔案加進追蹤修訂。
34+
* `git add .` ("git add dot") 把所有新檔案和改過的檔案加進追蹤修訂,但*「保留」*你刪掉的檔案。
35+
* `git add -A` 全部加進追蹤修訂,包括刪掉的檔案。
3536

36-
"Adding deletions" may sound weird, but if you think of a version control system as keeping
37-
track of *changes*, it might make more sense. Most people use `git add .` but `git add -A`
38-
can be safer. No matter what, `git status` is your friend.
37+
「把刪掉的檔案加進來」聽起來很奇怪,但如果你把版本控制系統想像成是追蹤*「修改」*的工具,或許就會懂了。
38+
多數人用 `git add .` 但 `git add -A` 會比較安全。無論無何,`git status` 都能幫上你的忙。
3939
MARKDOWN
4040
end
4141
end
4242

4343
step do
4444
console "git commit -m \"Added all the things\""
45-
message "`git commit` tells git to actually _do_ all things you've said you wanted to do."
46-
message "This is done in two steps so you can group multiple changes together."
47-
message "`-m \"Added all the things\"` is just a shortcut to say what your commit message is. You can skip that part and git will bring up an editor to fill out a more detailed message."
45+
message "`git commit` 告訴 git *真的要*執行你叫它做的事。"
46+
message "分成 add 和 commit 兩個步驟的好處是,如此你就可以把多個修改合併在一起。"
47+
message "`-m \"Added all the things\"` 這個捷徑讓你可以直接寫下 commit message。你可以省略之,這樣子 git 會打開一個編輯器請你填寫詳細的 commit message"
4848
end
4949
end
5050

5151
explanation do
5252
message <<-MARKDOWN
53-
By checking your application into git now, you're creating a record of your starting point. Whenever you make a change during today's workshop, we'll add it to git before moving on. This way, if anything ever breaks, or you make a change you don't like, you can use git as an all-powerful "undo" technique. But that only works when you remember to commit early and often!
53+
現在你已經把你的程式放進 git 了,等於你在一開始做了一個存檔點。在今天的工作坊的任何時候,你若要修改程式碼,我們都會先把它加進 git 再往下走。這樣子的話,如果之後改爛,或是改出來你不喜歡,你都可以利用 git 來「還原」到先前的狀態。不過當然你要隨時存檔啦!
5454
MARKDOWN
5555
end
5656

sites/zh-tw/intro-to-rails/creating_a_migration.step

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ goals {
22

33
model_diagram header: 'Topics', fields: %w(id title description)
44

5-
message "The suggestotron has a list of topics that people can vote on. We'll store our topics in the database. In this step you'll do the following:"
5+
message "我們的 suggestotron 會有一個 Topics (主題)列表讓大家來投票。我們會把 Topics 存進 database 裡面。在這一步你會做這些事:"
66

7-
goal "Create a a simple *Table* in the database for topics with a title and a description"
8-
goal "Automatically generate the corresponding *Scaffold* in Rails (namely, the *Model*, the *View*, and the *Controller*)."
7+
goal "在資料庫裡建立一個簡單的*「表格(Table)」*來儲存 Topics,Topic 有標題和內文。"
8+
goal "在 Rails 裡自動產生相對應的 *Scaffold*(包含 *Model**View**Controller*)。"
99

1010
}
1111

@@ -14,33 +14,33 @@ steps {
1414
step {
1515
console "rails generate scaffold topic title:string description:text"
1616
message <<-MARKDOWN
17-
* `generate scaffold` tells rails to create everything necessary to get up and running with topics.
18-
* `topic` tells rails the name of the new model.
19-
* `title:string` says that topics have a title, which is a "string".
20-
* `description:text` says that topics have a description which is a "text". (What's the difference between "string" and "text"? Basically "text" is for strings that might be very long.)
17+
* `generate scaffold` 告訴 Rails 去建立一堆檔案讓 topics 可以動。
18+
* `topic` 是告訴 rails 新的 Model 的名字是什麼。
19+
* `title:string` 是說 topics 有標題(title),它是一個字串(String)。
20+
* `description:text` 是說 topics 有內文(description),它是一段文字(Text)。(「字串」跟「文字」的差別?基本上「文字」是用來儲存可能會很長的字串。)
2121

2222
MARKDOWN
23-
message "If you want, take some time to poke around the files listed in this step. You can learn about them in the [Rails Architecture](rails_architecture) page."
23+
message "你若有興趣,可以花一點時間研究一下自動產生出來的檔案。你可以在[Rails Architecture](rails_architecture)這一頁學到更多。"
2424
link "rails_architecture"
2525
}
2626

2727
step {
2828
console "rake db:migrate"
29-
message "This tells rails to update the database to include a table for our new model."
29+
message "告訴 Rails 更新資料庫來建立一個用來儲存新的 Model 的表格(Table)。"
3030
}
3131
}
3232

3333
explanation {
3434

3535
h2 "Rake"
3636
message <<-MARKDOWN
37-
`rake` _(ruby make)_ is a tool that allows you to run small Ruby programs (**tasks**) that you use often in your application.
37+
`rake` _(ruby make)_ 這個工具讓你可以執行小型的 Ruby 程式(稱為 **tasks**),這些程式是你的程式常常會用到的。
3838

39-
Here, `rake db:migrate` is a task provided by the Rails framework. It uses the migration file we just created (`db/migrate/201xxxxxxxxxxx_create_topics.rb`) to change the database. Database migration files can be crucial to code collaboration.
39+
這裡的 `rake db:migrate` 是由 Rails framework 提供的 task。它會使用我們剛建立的 migration (`db/migrate/201xxxxxxxxxxx_create_topics.rb`) 來更改資料庫。資料庫的 migration 檔對於合作寫程式是非常重要的。
4040

4141
MARKDOWN
4242

43-
tip "You can run `rake -T` to see a list of all the `rake` commands your app currently responds to, along with a short description of each task."
43+
tip "你可以執行 `rake -T` 來看看目前你的應用程式認得什麼樣的 `rake` 指令,還會附上簡單的說明。"
4444
}
4545

4646

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
goals {
22

3-
goal "Create a database table for topics with a title and a description"
3+
goal "做一個資料庫表格來儲存 topic,topic 有 title description"
44

5-
message "In this step we'll learn a bit about Rails architecture. By the end of this step you should understand the following concepts:"
5+
message "在這一步我們會學一點 Rails 的架構。最終你應該會瞭解這些觀念:"
66

77
ul {
88
li "Table"
@@ -14,36 +14,38 @@ goals {
1414

1515
explanation {
1616

17-
h2 "Rails architecture and its relation to the database"
17+
h2 "Rails 的架構以及它與資料庫的關聯"
1818

1919
img(src: "img/mvc.png", alt: "MVC")
2020

21-
message "Rails implements a very specific notion of the **Model/View/Controller** pattern, which guides how you structure your web applications."
21+
message "Rails **Model/View/Controller** 的設計模式實作得非常具體,來指引你如何設計你的網路應用程式。"
2222

2323
h3 "Model"
2424
message <<-MARKDOWN
25-
* For all the Models we create in RailsBridge, Model objects have a corresponding record in the the database. The name of the table in the database is the plural version of the Model's class name. For example, if the Model is called 'Duck', it will automatically query or write to the 'ducks' table in the database.
26-
* Methods internal to Rails make it easy to automatically write records to the the database and query the database to get the records again later.
27-
* The Model is a bridge between the database and your application's code.
25+
* 我們在 RailsBridge 建立的 Model,其每一個 Model object 都在資料庫裡面有對應的資料。資料庫裡面的表格(table)是 Modelclass name 的複數形。例如,如果 Model 叫做 'Duck',就會自動去資料庫讀寫 'ducks' 這個表格。
26+
* Rails 內部的 methods 讓我們可以很容易把資料寫入到資料庫,之後再從資料庫裡面查詢(query)出來。
27+
* Model 是介於資料庫和你的程式碼之間的橋樑。
2828
MARKDOWN
2929

3030
h3 "View"
3131
message <<-MARKDOWN
32-
* The View generates the HTML that will be displayed in the browser.
33-
* View files are written in ERB, a templating language. It contains HTML with Ruby code embedded in it. The ruby variables in the view stand as placeholders for content that will be filled in when a user requests the page.
34-
* (There are several other templating languages available, but in RailsBridge we always stick to ERB.)
32+
* View 會產生 HTML 來顯示在瀏覽器。
33+
* View 檔案是用 ERB 寫的,它是一種樣板語言(Template Language)。裡面是 HTML 加上內嵌的 Ruby 程式碼。View 裡面的 Ruby 的變數便是當使用者要瀏覽該頁面的時候,所要填入的內容。
34+
* (還有別的樣板語言,但是在 RailsBridge 我們只用 ERB。)
3535
MARKDOWN
3636

3737
h3 "Controller"
3838
message <<-MARKDOWN
39-
* Controllers pass Ruby objects between the Models and the Views.
40-
* Each url corresponds to a specific method in a Controller.
41-
* After this step, when you visit any page in your application, that request will be handled by a method in a Controller.
39+
* Controller 把 Ruby objects 在 Model 和 View 之間傳來傳去。
40+
* 每一個 URL 都對應到 Controller 裡面的某一個特定的 method
41+
* 在這一步驟以後,當你打開你應用程式裡面的任何一個頁面,該請求(request)會被某個 Controller 的 method 處理。
4242
MARKDOWN
4343

4444
message <<-MARKDOWN
45-
When Models, Views and Controllers are all put together, they follow a pattern: Given a URL, Rails will look up which Controller method (also called an "Action") to use. The Controller Action will use methods in a corresponding Model. The Model will need to read or write to the database, and return an object containing that data to the Controller. The Controller will take that object and pass it to the View. (Actions normally have a corresponding View file, and Rails will automatically find and use that file.)
45+
當我們把 ModelsViewsControllers 放在一起的時候,他們會遵循以下的模式:
4646

47-
Models, Views and Controllers each have specific jobs. Separating responsibilities like this make it easier to develop, especially as it gets bigger. (When each file has a clear responsibility it's easier to fix problems and add new features.)
47+
給一個 URL,Rails 會去檢查要使用哪一個 Controller 裡面的 method(又稱為 "Action")。Controller Action 會去呼叫 Model 裡面對應的 methods。Model 會去讀寫資料庫,然後把包含資料的 object 回傳到 Controller。Controller 會拿到這個 object 並且丟到 View 裡面。Action 通常會有對應的 View 檔案,Rails 會自動尋找並使用之。)
48+
49+
Models、Views、Controllers 有各自的工作。像這樣把責任拆開來,會比較容易開發,尤其是它長得愈來愈大的時候。(每個檔案都有清晰的責任,會比較容易處理問題、增加新功能。)
4850
MARKDOWN
4951
}

0 commit comments

Comments
 (0)