Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88996a8

Browse files
Binlogoochococo
authored andcommitted
Translate to chinese
1 parent f2117da commit 88996a8

29 files changed

+170
-173
lines changed

‎generate-playground-cn.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# Note: I think this part is absolute garbage but it's a snapshot of my current skills with Bash.
44
# Would love to rewrite it in Swift soon.
55

6-
combineSwift() {
7-
cat source/startComment > 2ドル
6+
combineSwiftCN() {
7+
cat source-cn/startComment > 2ドル
88
cat 1ドル/header.md >> 2ドル
9-
cat source/contents.md >> 2ドル
10-
cat source/endComment >> 2ドル
11-
cat source/imports.swift >> 2ドル
9+
cat source-cn/contents.md >> 2ドル
10+
cat source-cn/endComment >> 2ドル
11+
cat source-cn/imports.swift >> 2ドル
1212
cat 1ドル/*.swift >> 2ドル
1313
{ rm 2ドル && awk '{gsub("\\*//\\*:", "", 0ドル); print}' > 2ドル; } < 2ドル
1414
}
1515

1616
move() {
17-
mv 1ドル.swift Design-Patterns.playground/Pages/1ドル.xcplaygroundpage/Contents.swift
17+
mv 1ドル.swift Design-Patterns-CN.playground/Pages/1ドル.xcplaygroundpage/Contents.swift
1818
}
1919

2020
playground() {
21-
combineSwift source/1ドル 1ドル.swift
21+
combineSwift source-cn/1ドル 1ドル.swift
2222
move 1ドル
2323
}
2424

@@ -28,14 +28,14 @@ combineMarkdown() {
2828
{ rm 2ドル && awk '{gsub("\\*/", "", 0ドル); print}' > 2ドル; } < 2ドル
2929
{ rm 2ドル && awk '{gsub("/\\*:", "", 0ドル); print}' > 2ドル; } < 2ドル
3030

31-
cat source/startSwiftCode >> 2ドル
31+
cat source-cn/startSwiftCode >> 2ドル
3232
cat 1ドル/*.swift >> 2ドル
3333

3434
{ rm 2ドル && awk '{gsub("\\*//\\*:", "", 0ドル); print}' > 2ドル; } < 2ドル
3535
{ rm 2ドル && awk '{gsub("\\*/", "\n```swift", 0ドル); print}' > 2ドル; } < 2ドル
3636
{ rm 2ドル && awk '{gsub("/\\*:", "```\n", 0ドル); print}' > 2ドル; } < 2ドル
3737

38-
cat source/endSwiftCode >> 2ドル
38+
cat source-cn/endSwiftCode >> 2ドル
3939

4040
{ rm 2ドル && awk '{gsub("```swift```", "", 0ドル); print}' > 2ドル; } < 2ドル
4141

@@ -44,21 +44,21 @@ combineMarkdown() {
4444
}
4545

4646
readme() {
47-
combineMarkdown source/1ドル 1ドル.md
47+
combineMarkdown source-cn/1ドル 1ドル.md
4848
}
4949

5050
playground Index
5151
playground Behavioral
5252
playground Creational
5353
playground Structural
5454

55-
zip -r -X Design-Patterns.playground.zip ./Design-Patterns.playground
55+
zip -r -X Design-Patterns-CN.playground.zip ./Design-Patterns-CN.playground
5656

5757
echo "" > README.md
5858

5959
readme Index
60-
cat source/contentsReadme.md >> README.md
60+
cat source-cn/contentsReadme.md >> README.md
6161
readme Behavioral
6262
readme Creational
6363
readme Structural
64-
cat source/footer.md >> README.md
64+
cat source-cn/footer.md >> README.md

‎source-cn/Index/header.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

2-
Design Patterns implemented in Swift 5.0
2+
设计模式(Swift 5.0 实现)
33
========================================
44

5-
A short cheat-sheet with Xcode 10.2 Playground ([Design-Patterns.playground.zip](https://raw.githubusercontent.com/ochococo/Design-Patterns-In-Swift/master/Design-Patterns.playground.zip)).
5+
👷 源项目由 [@nsmeme](http://twitter.com/nsmeme) (Oktawian Chojnacki) 维护。
66

7-
👷 Project maintained by: [@nsmeme](http://twitter.com/nsmeme) (Oktawian Chojnacki)
8-
9-
🚀 How to generate README, Playground and zip from source: [GENERATE.md](https://github.com/ochococo/Design-Patterns-In-Swift/blob/master/GENERATE.md)
7+
🇨🇳 中文版由 [@binglogo](https://twitter.com/binglogo) 整理翻译。

‎source-cn/behavioral/chain_of_responsibility.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*:
2-
🐝 Chain Of Responsibility
3-
--------------------------
2+
🐝 责任链(Chain Of Responsibility)
3+
------------------------------
44

5-
The chain of responsibility pattern is used to process varied requests, each of which may be dealt with by a different handler.
5+
责任链模式在面向对象程式设计里是一种软件设计模式,它包含了一些命令对象和一系列的处理对象。每一个处理对象决定它能处理哪些命令对象,它也知道如何将它不能处理的命令对象传递给该链中的下一个处理对象。
66

7-
### Example:
7+
### 示例:
88
*/
99

1010
protocol Withdrawing {
@@ -82,15 +82,15 @@ final class ATM: Withdrawing {
8282
}
8383
}
8484
/*:
85-
### Usage
86-
*/
87-
// Create piles of money and link them together 10 < 20 < 50 < 100.**
85+
### 用法
86+
*/
87+
// 创建一系列的钱堆,并将其链接起来:10<20<50<100
8888
let ten = MoneyPile(value: 10, quantity: 6, next: nil)
8989
let twenty = MoneyPile(value: 20, quantity: 2, next: ten)
9090
let fifty = MoneyPile(value: 50, quantity: 2, next: twenty)
9191
let hundred = MoneyPile(value: 100, quantity: 1, next: fifty)
9292

93-
// Build ATM.
93+
// 创建 ATM 实例
9494
var atm = ATM(hundred: hundred, fifty: fifty, twenty: twenty, ten: ten)
9595
atm.withdraw(amount: 310) // Cannot because ATM has only 300
9696
atm.withdraw(amount: 100) // Can withdraw - 1x100

‎source-cn/behavioral/command.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*:
2-
👫 Command
3-
----------
4-
5-
The command pattern is used to express a request, including the call to be made and all of its required parameters, in a command object. The command may then be executed immediately or held for later use.
6-
7-
### Example:
2+
👫 命令(Command)
3+
------------
4+
命令模式是一种设计模式,它尝试以对象来代表实际行动。命令对象可以把行动(action) 及其参数封装起来,于是这些行动可以被:
5+
* 重复多次
6+
* 取消(如果该对象有实现的话)
7+
* 取消后又再重做
8+
### 示例:
89
*/
910
protocol DoorCommand {
1011
func execute() -> String
@@ -52,7 +53,7 @@ final class HAL9000DoorsOperations {
5253
}
5354
}
5455
/*:
55-
### Usage:
56+
### 用法
5657
*/
5758
let podBayDoors = "Pod Bay Doors"
5859
let doorModule = HAL9000DoorsOperations(doors:podBayDoors)

‎source-cn/behavioral/header.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
Behavioral
3-
==========
4-
5-
>In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
6-
>
7-
>**Source:** [wikipedia.org](http://en.wikipedia.org/wiki/Behavioral_pattern)
2+
行为型模式
3+
========
4+
5+
>在软件工程中, 行为型模式为设计模式的一种类型,用来识别对象之间的常用交流模式并加以实现。如此,可在进行这些交流活动时增强弹性。
6+
>
7+
>**来源:** [维基百科](https://zh.wikipedia.org/wiki/%E8%A1%8C%E7%82%BA%E5%9E%8B%E6%A8%A1%E5%BC%8F)

‎source-cn/behavioral/interpreter.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*:
2-
🎶 Interpreter
3-
--------------
2+
🎶 解释器(Interpreter)
3+
------------------
44

5-
The interpreter pattern is used to evaluate sentences in a language.
5+
给定一种语言,定义他的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中句子。
66

7-
### Example
7+
### 示例:
88
*/
99

1010
protocol IntegerExpression {
@@ -72,7 +72,7 @@ final class AddExpression: IntegerExpression {
7272
}
7373
}
7474
/*:
75-
### Usage
75+
### 用法
7676
*/
7777
var context = IntegerContext()
7878

‎source-cn/behavioral/iterator.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*:
2-
🍫 Iterator
3-
-----------
2+
🍫 迭代器(Iterator)
3+
---------------
44

5-
The iterator pattern is used to provide a standard interface for traversing a collection of items in an aggregate object without the need to understand its underlying structure.
6-
7-
### Example:
5+
迭代器模式可以让用户通过特定的接口巡访容器中的每一个元素而不用了解底层的实现。
6+
7+
### 示例:
88
*/
99
struct Novella {
1010
let name: String
@@ -35,7 +35,7 @@ extension Novellas: Sequence {
3535
}
3636
}
3737
/*:
38-
### Usage
38+
### 用法
3939
*/
4040
let greatNovellas = Novellas(novellas: [Novella(name: "The Mist")] )
4141

‎source-cn/behavioral/mediator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*:
2-
💐 Mediator
3-
-----------
2+
💐 中介者(Mediator)
3+
---------------
44

5-
The mediator pattern is used to reduce coupling between classes that communicate with each other. Instead of classes communicating directly, and thus requiring knowledge of their implementation, the classes send messages via a mediator object.
5+
用一个中介者对象封装一系列的对象交互,中介者使各对象不需要显示地相互作用,从而使耦合松散,而且可以独立地改变它们之间的交互。
66

7-
### Example
7+
### 示例:
88
*/
99
protocol Receiver {
1010
associatedtype MessageType
@@ -47,7 +47,7 @@ final class MessageMediator: Sender {
4747
}
4848

4949
/*:
50-
### Usage
50+
### 用法
5151
*/
5252
func spamMonster(message: String, worker: MessageMediator) {
5353
worker.send(message: message)

‎source-cn/behavioral/memento.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*:
2-
💾 Memento
3-
----------
2+
💾 备忘录(Memento)
3+
--------------
44

5-
The memento pattern is used to capture the current state of an object and store it in such a manner that it can be restored at a later time without breaking the rules of encapsulation.
5+
在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样就可以将该对象恢复到原先保存的状态
66

7-
### Example
7+
### 示例:
88
*/
99
typealias Memento = [String: String]
1010
/*:
11-
Originator
11+
发起人(Originator)
1212
*/
1313
protocol MementoConvertible {
1414
var memento: Memento { get }
@@ -45,7 +45,7 @@ struct GameState: MementoConvertible {
4545
}
4646
}
4747
/*:
48-
Caretaker
48+
管理者(Caretaker)
4949
*/
5050
enum CheckPoint {
5151

@@ -61,7 +61,7 @@ enum CheckPoint {
6161
}
6262
}
6363
/*:
64-
### Usage
64+
### 用法
6565
*/
6666
var gameState = GameState(chapter: "Black Mesa Inbound", weapon: "Crowbar")
6767

‎source-cn/behavioral/observer.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*:
2-
👓 Observer
3-
-----------
2+
👓 观察者(Observer)
3+
---------------
44

5-
The observer pattern is used to allow an object to publish changes to its state.
6-
Other objects subscribe to be immediately notified of any changes.
5+
一个目标对象管理所有相依于它的观察者对象,并且在它本身的状态改变时主动发出通知
76

8-
### Example
7+
### 示例:
98
*/
109
protocol PropertyObserver : class {
1110
func willChange(propertyName: String, newPropertyValue: Any?)
@@ -42,7 +41,7 @@ final class Observer : PropertyObserver {
4241
}
4342
}
4443
/*:
45-
### Usage
44+
### 用法
4645
*/
4746
var observerInstance = Observer()
4847
var testChambers = TestChambers()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /