Skip to content

doc: translate error boundaries to zh-hant #104

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

Merged
merged 5 commits into from
Nov 12, 2019

Conversation

eyeccc
Copy link
Contributor

@eyeccc eyeccc commented Oct 26, 2019

translate error boundaries doc to zh-hant

@netlify
Copy link

netlify bot commented Oct 26, 2019

Deploy preview for zh-hant-reactjs-org ready!

Built with commit 17af1e6

https://deploy-preview-104--zh-hant-reactjs-org.netlify.com

Copy link
Member

@chloewlin chloewlin left a comment

Choose a reason for hiding this comment

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

Hi @eyeccc, very thoughtful translation. :) I left some comments on the tricky parts. Feel free to ping me again if you want a second review.


A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for React users, React 16 introduces a new concept of an “error boundary”.
一個介面裡 JavaScript 的錯誤不應該毀了整個應用。為了替 React 使用者解決這個問題,React 16 引入了一個新的概念:「錯誤邊界」。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
一個介面裡 JavaScript 的錯誤不應該毀了整個應用。為了替 React 使用者解決這個問題,React 16 引入了一個新的概念:「錯誤邊界」。
一個介面裡的某一個 JavaScript 的錯誤不應該毀了整個應用程式。為了替 React 使用者解決這個問題,React 16 引入了一個新的概念:「錯誤邊界」。


Error boundaries are React components that **catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI** instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,紀錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界在整個底下的 component tree 在 render 的時候、生命週期函式、以及 constructors 裡捕捉錯誤。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,紀錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界在整個底下的 component tree 在 render 的時候、生命週期函式、以及 constructors 裡捕捉錯誤
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,記錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界會在 render 的時候、在生命週期函式內、以及底下一整個 component tree 裡的 constructor 內捕捉錯誤


## Where to Place Error Boundaries {#where-to-place-error-boundaries}
錯誤邊界的顆粒度取決於你自己。你可以把它包在最上層的 route component 藉以顯示「發生了一些錯誤」的訊息給使用者,就如同 server-side frameworks 裡常常處理錯誤的方式。你也可以把它包在個別的小工具外,藉以保護它們不受應用程式裡發生的其他錯誤的影響。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
錯誤邊界的顆粒度取決於你自己。你可以把它包在最上層的 route component 藉以顯示「發生了一些錯誤」的訊息給使用者,就如同 server-side frameworks 裡常常處理錯誤的方式。你也可以把它包在個別的小工具外,藉以保護它們不受應用程式裡發生的其他錯誤的影響。
錯誤邊界的精確度取決於你自己。你可以把它包在最上層的 route component 藉以顯示「發生了一些錯誤」的訊息給使用者,就如同 server-side framework 裡常常處理錯誤的方式。你也可以把它包在個別的小工具外,藉以保護它們不受應用程式裡發生的其他錯誤的影響。

Granularity here is synonymous with precision (not the size of grains): you can display a generic message from top-level route components, but you could also display a precise message from one specific component.


這個改變有重要的意義。**在 React 16,沒有被錯誤邊界所捕捉到的錯誤會導致 unmount 整個 React component tree。**
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
這個改變有重要的意義。**在 React 16,沒有被錯誤邊界所捕捉到的錯誤會導致 unmount 整個 React component tree。**
這個改變有重要的意義。**在 React 16,沒有被錯誤邊界所捕捉到的錯誤會 unmount 整個 React component tree。**

I would skip result in here. If you want to keep it, this sentence could be 導致整個 React component tree 的 unmounting. But this sounds less elegant to me.


## New Behavior for Uncaught Errors {#new-behavior-for-uncaught-errors}
我們為了這個決定辯論過,但在我們的經驗裡,留下被敗壞的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
我們為了這個決定辯論過,但在我們的經驗裡,留下被敗壞的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。
我們為了這個決定辯論過,但在我們的經驗裡,留下壞掉的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。

Corrupted here just means broken.

@chloewlin chloewlin added In Review Currently under review and removed Review Needed labels Nov 8, 2019
@chloewlin chloewlin self-assigned this Nov 8, 2019
@eyeccc
Copy link
Contributor Author

eyeccc commented Nov 11, 2019

@chloewlin Just updated based on suggestion. Thanks

Copy link
Member

@neighborhood999 neighborhood999 left a comment

Choose a reason for hiding this comment

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

I left some suggestions.


Error boundaries are React components that **catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI** instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,記錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界會在 render 的時候、在生命週期函式內、以及底下一整個 component tree 裡的 constructor 內捕捉錯誤。
Copy link
Member

Choose a reason for hiding this comment

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

I prefer fallback:

Suggested change
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,記錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界會在 render 的時候、在生命週期函式內、以及底下一整個 component tree 裡的 constructor 內捕捉錯誤。
錯誤邊界是一個 React component,它**捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,記錄那些錯誤,然後顯示在一個 fallback 的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界會在 render 的時候、在生命週期函式內、以及底下一整個 component tree 裡的 constructor 內捕捉錯誤。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then maybe we should also add fallback in glossary 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I added it!

@eyeccc
Copy link
Contributor Author

eyeccc commented Nov 12, 2019

@neighborhood999 Updated based on suggestion just now! Thanks.

@@ -32,18 +32,18 @@ class ErrorBoundary extends React.Component {
}

static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
// 更新 state 以至於下一個 render 會顯示備用的 UI
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 更新 state 以至於下一個 render 會顯示備用的 UI
// 更新 state 以至於下一個 render 會顯示 fallback UI

logErrorToMyService(error, errorInfo);
}

render() {
if (this.state.hasError) {
// You can render any custom fallback UI
// 你可以 render 任何客製化的備用 UI
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 你可以 render 任何客製化的備用 UI
// 你可以 render 任何客製化的 fallback UI


Note that **error boundaries only catch errors in the components below them in the tree**. An error boundary can’t catch an error within itself. If an error boundary fails trying to render the error message, the error will propagate to the closest error boundary above it. This, too, is similar to how catch {} block works in JavaScript.
要注意 **錯誤邊界只會捕捉它底下 component tree 裡的 component 的錯誤**。錯誤邊界無法捕捉它自己本身的錯誤。如果一個錯誤邊界在 render 錯誤訊息的時候失敗了,這個錯誤會被傳遞到在它之上最近的錯誤邊界。這個也與 JavaScript 的 catch {} 的運作方式類似。
Copy link
Member

Choose a reason for hiding this comment

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

Forget to fix this. :)


## 對於未捕捉到的錯誤的新行為 {#new-behavior-for-uncaught-errors}
Copy link
Member

Choose a reason for hiding this comment

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

The correct is line 77.

@@ -142,7 +141,7 @@ class MyComponent extends React.Component {

handleClick() {
try {
// Do something that could throw
// 做某些可以丟出錯誤的事情
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 做某些可以丟出錯誤的事情
// 做某些可以拋出錯誤的事情

Copy link
Member

@neighborhood999 neighborhood999 left a comment

Choose a reason for hiding this comment

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

Thank you for helping, @eyeccc!

@neighborhood999 neighborhood999 merged commit a846289 into reactjs:master Nov 12, 2019
@neighborhood999 neighborhood999 added Completed and removed In Review Currently under review labels Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants