-
Notifications
You must be signed in to change notification settings - Fork 4.7k
api-fetch: Check navigator.onLine to improve failure notices #71438
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,17 +89,34 @@ export function getNotificationArgumentsForSaveFail( data ) { | |
|
|
||
| const publishStatus = [ 'publish', 'private', 'future' ]; | ||
| const isPublished = publishStatus.indexOf( post.status ) !== -1; | ||
| // If the post was being published, we show the corresponding publish error message | ||
| // Unless we publish an "updating failed" message. | ||
|
|
||
| if ( error.code === 'offline_error' ) { | ||
| const messages = { | ||
| publish: __( 'Publishing failed because you were offline.' ), | ||
| private: __( 'Publishing failed because you were offline.' ), | ||
| future: __( 'Scheduling failed because you were offline.' ), | ||
| default: __( 'Updating failed because you were offline.' ), | ||
|
Comment on lines
+95
to
+98
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can move "You were offline." to a separate string that we concat with the existing "publishing/updating/scheduling failed" string. That way translators will have less to translate. WDYT?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concatenating two separately translated strings isn't recommended, as far as I can remember. Based on the language, you may receive an odd complete translation.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree in general if we were separating a single sentence, but perhaps it should be fine if they are 2 separate sentences?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @swissspidy or @SergeyBiryukov might have a more definitive answer. I don't remember any exceptions to the rule, but they usually have a couple 😄
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, I intentionally inlined all possible sentences, the same way that we need to define all possible CPT labels one by one.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. If there's a rule, sacrificing some extra work to add a few extra strings sounds like it's worth it. I'm just mindful about the translation efforts since every core string change requires hundreds of people's attention.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wanna concatenate two sentences "Publishing failed." and "You are offline", that should be OK. But it's only 4 extra strings here which is also fine. Alternatives would be to have a generic text only (e.g. "Action failed because you are probably offline"), or WP adding support for custom labels per post status. |
||
| }; | ||
|
|
||
| const noticeMessage = | ||
| ! isPublished && edits.status in messages | ||
| ? messages[ edits.status ] | ||
| : messages.default; | ||
|
|
||
| return [ noticeMessage, { id: 'editor-save' } ]; | ||
| } | ||
|
|
||
| const messages = { | ||
| publish: __( 'Publishing failed.' ), | ||
| private: __( 'Publishing failed.' ), | ||
| future: __( 'Scheduling failed.' ), | ||
| default: __( 'Updating failed.' ), | ||
| }; | ||
|
|
||
| let noticeMessage = | ||
| ! isPublished && publishStatus.indexOf( edits.status ) !== -1 | ||
| ! isPublished && edits.status in messages | ||
| ? messages[ edits.status ] | ||
| : __( 'Updating failed.' ); | ||
| : messages.default; | ||
|
|
||
| // Check if message string contains HTML. Notice text is currently only | ||
| // supported as plaintext, and stripping the tags may muddle the meaning. | ||
|
|
||
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 was unsure about the capitalization of "Internet" but I guess there's data behind it, as close to a tie as that might be 😅 .
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.
On the other hand, Core uses lower-case "internet". Although the sample is very small, there are just two messages that use the word:
Capital I is used only when talking about Internet Explorer.
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 also checked the WP Glossary, and both are found throughout. :) Capitalised is how I personally write it, but I can go either way here. @jsnajdr, are you invested in the non-capitalised form?
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'm not invested at all, was just curious about which convention is actually used in WordPress. 🙂 The Gutenberg repo also leans heavily towards lowercase, although it's all comments and docs, there's zero usage in code.