-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate collection.md #415
Conversation
@@ -19,21 +19,21 @@ The `Illuminate\Support\Collection` class provides a fluent, convenient wrapper | |||
}); | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多一行
// ['FIRST', 'SECOND'] | ||
|
||
Typically, you should declare collection macros in a [service provider](/docs/{{version}}/providers). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多一行
|
||
For the remainder of this documentation, we'll discuss each method available on the `Collection` class. Remember, all of these methods may be chained to fluently manipulating the underlying array. Furthermore, almost every method returns a new `Collection` instance, allowing you to preserve the original copy of the collection when necessary: | ||
在這份文件剩餘的部份,我們將會探討每一個 `Collection` 類別上可用的方法。要先知道的是,以下所有的方法,都可以用串鏈式的方式處理陣列。另外,大部分的方法都會回傳一個新的`Collection`實例,讓你在必要時,還有原始的數組可使用。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
回傳一個新的Collection
實例
英文與中文之間未間隔
@@ -184,7 +185,7 @@ For the remainder of this documentation, we'll discuss each method available on | |||
<a name="method-all"></a> | |||
#### `all()` {#collection-method .first-collection-method} | |||
|
|||
The `all` method returns the underlying array represented by the collection: | |||
`all` 方法單純地回傳該集合所代表的底層陣列: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all
方法回傳該集合所代表的底層陣列:
|
||
<a name="method-avg"></a> | ||
#### `avg()` {#collection-method} | ||
|
||
The `avg` method returns the [average value](https://en.wikipedia.org/wiki/Average) of a given key: | ||
`avg` 方法會回傳指定key所對應數值的 [平均值](https://en.wikipedia.org/wiki/Average): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avg
方法會回傳指定 key 所對應數值的[平均值]
中英文需要間隔。
|
||
<a name="method-containsstrict"></a> | ||
#### `containsStrict()` {#collection-method} | ||
|
||
This method has the same signature as the [`contains`](#method-contains) method; however, all values are compared using "strict" comparisons. | ||
這個方法的用法與[`contains`](#method-contains)相同,但所有數值都會用"嚴格模式"來比較。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這個方法的用法與 contains
相同,但所有數值都會用「嚴格模式」來比較。
�中英文需間隔,雙引號須改用全形的左右引號
@@ -379,12 +380,12 @@ The `dd` method dumps the collection's items and ends execution of the script: | |||
] | |||
*/ | |||
|
|||
If you do not want to stop executing the script, use the [`dump`](#method-dump) method instead. | |||
如果你不想停止執行,可以使用[`dump`](#method-dump)方法替代。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
中英文間隔
|
||
<a name="method-diff"></a> | ||
#### `diff()` {#collection-method} | ||
|
||
The `diff` method compares the collection against another collection or a plain PHP `array` based on its values. This method will return the values in the original collection that are not present in the given collection: | ||
`diff` 方法會比較其他集合或純PHP `array` 裡的值。最後返回有在原始集合裡,但沒有在給定集合內的值。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
中英文間隔
@@ -397,29 +398,29 @@ The `diff` method compares the collection against another collection or a plain | |||
<a name="method-diffassoc"></a> | |||
#### `diffAssoc()` {#collection-method} | |||
|
|||
The `diffAssoc` method compares the collection against another collection or a plain PHP `array` based on its keys and values. This method will return the key / value pairs in the original collection that are not present in the given collection: | |||
`diffAssoc` 方法會比較其他集合或純PHP `array` 的鍵與值。最後返回有在原始集合裡,但沒有在給定集合內的鍵與值: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
中英文間隔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的冒號要改成全形符號
// ['color' => 'orange', 'remain' => 6] | ||
|
||
<a name="method-diffkeys"></a> | ||
#### `diffKeys()` {#collection-method} | ||
|
||
The `diffKeys` method compares the collection against another collection or a plain PHP `array` based on its keys. This method will return the key / value pairs in the original collection that are not present in the given collection: | ||
`diffKeys` 方法會比較其他集合或以純PHP `array` 的鍵為比較標的。最後返回有在原始集合裡,但沒有在給定集合內的鍵與其對應的值: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diffKeys
方法會比較其他集合或純 PHP array
的鍵與值。最後返回有在原始集合裡,但沒有在給定集合內的鍵與其對應的值:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的冒號要改成全形符號
@@ -458,18 +459,18 @@ The `dump` method dumps the collection's items: | |||
} | |||
*/ | |||
|
|||
If you want to stop executing the script after dumping the collection, use the [`dd`](#method-dd) method instead. | |||
如果你想在傾印後停止執行程式,可使用[`dd`](#method-dd)方法代替。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可使用 dd
方法代替。
中英文間隔
@@ -497,18 +498,18 @@ You may stop iterating through the items by returning `false` from the callback: | |||
<a name="method-every"></a> | |||
#### `every()` {#collection-method} | |||
|
|||
The `every` method may be used to verify that all elements of a collection pass a given truth test: | |||
`every` 方法用於檢驗所有元素是否通過所給予的測試: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的冒號要改成全形符號
// ['one' => 10, 'three' => 30, 'five' => 50] | ||
|
||
<a name="method-dump"></a> | ||
#### `dump()` {#collection-method} | ||
|
||
The `dump` method dumps the collection's items: | ||
`dump` 方法會傾印出此集合的所有元素: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的冒號要改成全形符號
@@ -518,45 +519,45 @@ The `except` method returns all items in the collection except for those with th | |||
|
|||
// ['product_id' => 1] | |||
|
|||
For the inverse of `except`, see the [only](#method-only) method. | |||
與 `except` 相反的方法請查看 [only](#method-only). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的句點要改成全形符號
// [3, 4] | ||
|
||
If no callback is supplied, all entries of the collection that are equivalent to `false` will be removed: | ||
如果沒有提供回呼函式,就會移除所有等於 `false` 的元素: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的冒號要改成全形符號
|
||
$collection = collect([1, 2, 3, null, false, '', 0, []]); | ||
|
||
$collection->filter()->all(); | ||
|
||
// [1, 2, 3] | ||
|
||
For the inverse of `filter`, see the [reject](#method-reject) method. | ||
與 `filter` 相對的方法可以檢視 [reject](#method-reject) . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最後的句點要改成全形符號
@@ -565,26 +566,26 @@ You may also call the `first` method with no arguments to get the first element | |||
<a name="method-flatmap"></a> | |||
#### `flatMap()` {#collection-method} | |||
|
|||
The `flatMap` method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items. Then, the array is flattened by a level: | |||
`flatMap` 方法將集合內元素傳入回呼函式中,此回呼函式可對每個元素任意修改並回傳,最後由回傳的元素形成一個新的集合,即是`flattened`一個階層後的結果。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
從而形成一個修改過的新項目集合。該陣列會被扁化成同一個層級
@@ -594,7 +595,7 @@ The `flatten` method flattens a multi-dimensional collection into a single dimen | |||
|
|||
// ['taylor', 'php', 'javascript']; | |||
|
|||
You may optionally pass the function a "depth" argument: | |||
你還可以帶入"深度"參數 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你還可以傳入「深度」參數
/* | ||
[ | ||
['name' => 'iPhone 6S', 'brand' => 'Apple'], | ||
['name' => 'Galaxy S7', 'brand' => 'Samsung'], | ||
] | ||
*/ | ||
|
||
In this example, calling `flatten` without providing the depth would have also flattened the nested arrays, resulting in `['iPhone 6S', 'Apple', 'Galaxy S7', 'Samsung']`. Providing a depth allows you to restrict the levels of nested arrays that will be flattened. | ||
在這例子中,若沒有帶入"深度"參數,將會得到`['iPhone 6S', 'Apple', 'Galaxy S7', 'Samsung']`的結果。提供深度可指定從哪一階層開始。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
若沒有傳入「深度」參數
|
||
<a name="method-flip"></a> | ||
#### `flip()` {#collection-method} | ||
|
||
The `flip` method swaps the collection's keys with their corresponding values: | ||
`flip` 方法將集合中的鍵和對應的數值進行互換: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
將集合中的鍵與相對應的值進行互換
@@ -634,7 +635,7 @@ The `flip` method swaps the collection's keys with their corresponding values: | |||
<a name="method-forget"></a> | |||
#### `forget()` {#collection-method} | |||
|
|||
The `forget` method removes an item from the collection by its key: | |||
`forget` 方法以鍵自集合移除掉一個項目: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法以鍵自集合中移除一個項目
@@ -644,12 +645,12 @@ The `forget` method removes an item from the collection by its key: | |||
|
|||
// ['framework' => 'laravel'] | |||
|
|||
> {note} Unlike most other collection methods, `forget` does not return a new modified collection; it modifies the collection it is called on. | |||
> **注意:**與大多數其他集合的方法不同,`forget` 不會回傳修改過後的新集合;它會直接修改它被呼叫的集合。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{note} 與大多數的集合的方法不同,forget
不會回傳修改過後的新集合,而是會直接修改原先呼叫的集合。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{note} 不用翻,laravel 文件網站會處理這個關鍵字
|
||
<a name="method-forpage"></a> | ||
#### `forPage()` {#collection-method} | ||
|
||
The `forPage` method returns a new collection containing the items that would be present on a given page number. The method accepts the page number as its first argument and the number of items to show per page as its second argument: | ||
`forPage` 方法回傳含有可以用來在給定頁碼顯示的項目的新集合。第一個參數是頁數,第二個則是每頁要顯示的比數。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第二個則是每頁要顯示的項目筆數。
@@ -747,18 +748,20 @@ The `has` method determines if a given key exists in the collection: | |||
<a name="method-implode"></a> | |||
#### `implode()` {#collection-method} | |||
|
|||
The `implode` method joins the items in a collection. Its arguments depend on the type of items in the collection. If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the "glue" string you wish to place between the values: | |||
`implode` 方法連接集合中的項目。它的參數依集合中的項目類型而定。 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多兩行
@@ -777,27 +780,30 @@ The `intersect` method removes any values from the original collection that are | |||
|
|||
// [0 => 'Desk', 2 => 'Chair'] | |||
|
|||
如你所見,最後出來的集合將會保留原始集合的鍵。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原文沒有這句
<a name="method-intersectbykeys"></a> | ||
#### `intersectByKeys()` {#collection-method} | ||
|
||
`intersectByKeys` 方法移除任何給定`陣列`或集合內所沒有的鍵值。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法從原始集合中移除任何給定陣列
或集合內所沒有的鍵值。
<a name="method-intersectbykeys"></a> | ||
#### `intersectByKeys()` {#collection-method} | ||
|
||
`intersectByKeys` 方法移除任何給定`陣列`或集合內所沒有的鍵值。 | ||
The `intersectByKeys` method removes any keys from the original collection that are not present in the given `array` or collection: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原文未刪
// ['type' => 'screen', 'year' => 2009] | ||
|
||
<a name="method-isempty"></a> | ||
#### `isEmpty()` {#collection-method} | ||
|
||
The `isEmpty` method returns `true` if the collection is empty; otherwise, `false` is returned: | ||
假如集合是空的,`isEmpty` 方法會回傳 `true`:否則回傳 `false`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法會回傳 true
�,否則回傳 false
:
@@ -806,7 +812,7 @@ The `isEmpty` method returns `true` if the collection is empty; otherwise, `fals | |||
<a name="method-isnotempty"></a> | |||
#### `isNotEmpty()` {#collection-method} | |||
|
|||
The `isNotEmpty` method returns `true` if the collection is not empty; otherwise, `false` is returned: | |||
假如集合不是空的,`isNotEmpty` 方法會回傳 `true`:否則回傳 `false`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法會回傳 true
,否則回傳 false
:
@@ -884,34 +890,34 @@ You may also call the `last` method with no arguments to get the last element in | |||
<a name="method-macro"></a> | |||
#### `macro()` {#collection-method} | |||
|
|||
The static `macro` method allows you to add methods to the `Collection` class at run time. Refer to the documentation on [extending collections](#extending-collections) for more information. | |||
靜態的 `macro` 方法,允許你在執行期間動態加入 `集合` 類別內。可參考 [extending collections](#extending-collections) 章節獲得更多資訊。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
執行期間動態加入 Collection
類別內
保留原文
|
||
<a name="method-make"></a> | ||
#### `make()` {#collection-method} | ||
|
||
The static `make` method creates a new collection instance. See the [Creating Collections](#creating-collections) section. | ||
靜態的 `make` 方法,可產生新的集合,見 [Creating Collections](#creating-collections) 章節。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
請看建立集合章節。
|
||
<a name="method-map"></a> | ||
#### `map()` {#collection-method} | ||
|
||
The `map` method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items: | ||
`map` 方法遍歷整個集合並將每一個數值傳入給定的回呼函式。回呼函式可以任意修改並回傳項目,於是形成修改過的項目組成的新集合: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
從而形成一個修改過的新項目集合:
// [2, 4, 6, 8, 10] | ||
|
||
> {note} Like most other collection methods, `map` returns a new collection instance; it does not modify the collection it is called on. If you want to transform the original collection, use the [`transform`](#method-transform) method. | ||
> **注意:**正如集合大多數其他的方法一樣,`map` 回傳一個新集合實例;它並沒有修改被呼叫的集合。假如你想改變原始的集合,得使用 [`transform`](#method-transform) 方法。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{note} 保留原文,並與原文間隔一個空格。
如同大多數的集合方法一樣,map
回傳一個新集合實例。它並沒有修改到原本的集合。
|
||
<a name="method-mapinto"></a> | ||
#### `mapInto()` {#collection-method} | ||
|
||
The `mapInto()` method iterates over the collection, creating a new instance of the given class by passing the value into the constructor: | ||
`mapInto()` 方法遍歷整個集合,並將每個數值傳入指定類別實體的建構子中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
數值->值
// [Currency('USD'), Currency('EUR'), Currency('GBP')] | ||
|
||
<a name="method-mapspread"></a> | ||
#### `mapSpread()` {#collection-method} | ||
|
||
The `mapSpread` method iterates over the collection's items, passing each nested item value into the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items: | ||
`mapSpread` 方法遍歷整個集合,並將下一階層的巢狀數值傳入給定的回呼函式,回呼函式可以任意修改並回傳項目,於是形成修改過的項目組成的新集合: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
從而形成一個修改過的新項目集合:
分好幾次終於翻譯完了
但每次翻譯的風格都不太一樣
本來想再找時間修正
但看大家都翻譯完了
我落後太多
就先提交合併了Orz...