-
Notifications
You must be signed in to change notification settings - Fork 88
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
doc: translate error boundaries to zh-hant #104
Conversation
Deploy preview for zh-hant-reactjs-org ready! Built with commit 17af1e6 |
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.
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.
content/docs/error-boundaries.md
Outdated
|
||
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 引入了一個新的概念:「錯誤邊界」。 |
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.
一個介面裡 JavaScript 的錯誤不應該毀了整個應用。為了替 React 使用者解決這個問題,React 16 引入了一個新的概念:「錯誤邊界」。 | |
一個介面裡的某一個 JavaScript 的錯誤不應該毀了整個應用程式。為了替 React 使用者解決這個問題,React 16 引入了一個新的概念:「錯誤邊界」。 |
content/docs/error-boundaries.md
Outdated
|
||
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 裡捕捉錯誤。 |
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.
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,紀錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界在整個底下的 component tree 在 render 的時候、生命週期函式、以及 constructors 裡捕捉錯誤。 | |
錯誤邊界是一個 React component,它 **捕捉了任何在它的 child component tree 裡發生的 JavaScript 的錯誤,記錄那些錯誤,然後顯示在一個備用的使用介面**,而非讓整個 component tree 崩壞。錯誤邊界會在 render 的時候、在生命週期函式內、以及底下一整個 component tree 裡的 constructor 內捕捉錯誤。 |
content/docs/error-boundaries.md
Outdated
|
||
## Where to Place Error Boundaries {#where-to-place-error-boundaries} | ||
錯誤邊界的顆粒度取決於你自己。你可以把它包在最上層的 route component 藉以顯示「發生了一些錯誤」的訊息給使用者,就如同 server-side frameworks 裡常常處理錯誤的方式。你也可以把它包在個別的小工具外,藉以保護它們不受應用程式裡發生的其他錯誤的影響。 |
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.
錯誤邊界的顆粒度取決於你自己。你可以把它包在最上層的 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.
content/docs/error-boundaries.md
Outdated
|
||
這個改變有重要的意義。**在 React 16,沒有被錯誤邊界所捕捉到的錯誤會導致 unmount 整個 React component tree。** |
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.
這個改變有重要的意義。**在 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.
content/docs/error-boundaries.md
Outdated
|
||
## New Behavior for Uncaught Errors {#new-behavior-for-uncaught-errors} | ||
我們為了這個決定辯論過,但在我們的經驗裡,留下被敗壞的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。 |
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.
我們為了這個決定辯論過,但在我們的經驗裡,留下被敗壞的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。 | |
我們為了這個決定辯論過,但在我們的經驗裡,留下壞掉的 UI 比完全移除它更糟。舉例來說,在像 Messenger 一樣的產品裡,留下壞掉的 UI 可能會導致某人傳送訊息給錯誤的對象。相似地,在支付軟體裡,顯示錯誤的金額比 render 空白畫面來得更糟。 |
Corrupted here just means broken.
@chloewlin Just updated based on suggestion. Thanks |
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.
I left some suggestions.
content/docs/error-boundaries.md
Outdated
|
||
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 內捕捉錯誤。 |
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.
I prefer fallback
:
錯誤邊界是一個 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 內捕捉錯誤。 |
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.
Then maybe we should also add fallback
in glossary 🤔
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.
Sure, I added it!
@neighborhood999 Updated based on suggestion just now! Thanks. |
content/docs/error-boundaries.md
Outdated
@@ -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 |
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.
// 更新 state 以至於下一個 render 會顯示備用的 UI | |
// 更新 state 以至於下一個 render 會顯示 fallback UI |
content/docs/error-boundaries.md
Outdated
logErrorToMyService(error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
// You can render any custom fallback UI | ||
// 你可以 render 任何客製化的備用 UI |
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.
// 你可以 render 任何客製化的備用 UI | |
// 你可以 render 任何客製化的 fallback UI |
content/docs/error-boundaries.md
Outdated
|
||
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 {} 的運作方式類似。 |
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.
Forget to fix this. :)
|
||
## 對於未捕捉到的錯誤的新行為 {#new-behavior-for-uncaught-errors} |
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.
The correct is line 77.
content/docs/error-boundaries.md
Outdated
@@ -142,7 +141,7 @@ class MyComponent extends React.Component { | |||
|
|||
handleClick() { | |||
try { | |||
// Do something that could throw | |||
// 做某些可以丟出錯誤的事情 |
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.
Thank you for helping, @eyeccc!
translate error boundaries doc to zh-hant