Skip to content
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

[amp-story] ♿ Add label for next story and add i18n for pagination buttons #33205

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions extensions/amp-story/1.0/_locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,29 @@
"89": {
"string": "Your response will be sent to",
"description": "Text displayed to users after clicking a button that reveals a disclaimer, telling them more about where their user data will be stored, after they interact with a poll or quiz."
},
"90": {
"string": "Next story",
"description": "Label for a button that advances to the next element in the carousel."
},
"91": {
"string": "Next page",
"description": "Label for a button that advances to the next page of the story."
},
"92": {
"string": "Replay",
"description": "Label for a button that replays the story."
},
"93": {
"string": "Previous page",
"description": "Label for a button that returns the user to the previous page of the story."
},
"94": {
"string": "Close bookend",
"description": "Label for a button that closes a dialog containing related articles and sharing options and returns the user to the article."
},
"95": {
"string": "Show bookend",
"description": "Label for a button that displays a dialog with related articles and sharing options."
}
}
33 changes: 24 additions & 9 deletions extensions/amp-story/1.0/pagination-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import {
import {AdvancementMode} from './story-analytics';
import {CommonSignals} from '../../../src/common-signals';
import {EventType, dispatch} from './events';
import {LocalizedStringId} from '../../../src/localized-strings';
import {Services} from '../../../src/services';
import {dev} from '../../../src/log';
import {pureDevAssert as devAssert} from '../../../src/core/assert';
import {getLocalizationService} from './amp-story-localization-service';
import {htmlFor} from '../../../src/static-template';

/** @struct @typedef {{className: string, triggers: (string|undefined)}} */
Expand All @@ -36,13 +38,13 @@ const BackButtonStates = {
className: 'i-amphtml-story-back-close-bookend',
action: Action.TOGGLE_BOOKEND,
data: false,
label: 'Close bookend',
label: LocalizedStringId.AMP_STORY_CLOSE_BOOKEND,
},
HIDDEN: {className: 'i-amphtml-story-button-hidden'},
PREVIOUS_PAGE: {
className: 'i-amphtml-story-back-prev',
triggers: EventType.PREVIOUS_PAGE,
label: 'Previous page',
label: LocalizedStringId.AMP_STORY_PREVIOUS_PAGE,
},
};

Expand All @@ -52,19 +54,23 @@ const ForwardButtonStates = {
NEXT_PAGE: {
className: 'i-amphtml-story-fwd-next',
triggers: EventType.NEXT_PAGE,
// TODO: Here and other labels: i18n.
label: 'Next page',
label: LocalizedStringId.AMP_STORY_NEXT_PAGE,
},
NEXT_STORY: {
className: 'i-amphtml-story-fwd-next',
triggers: EventType.NEXT_PAGE,
label: LocalizedStringId.AMP_STORY_NEXT_STORY,
},
REPLAY: {
className: 'i-amphtml-story-fwd-replay',
triggers: EventType.REPLAY,
label: 'Replay',
label: LocalizedStringId.AMP_STORY_REPLAY,
},
SHOW_BOOKEND: {
className: 'i-amphtml-story-fwd-more',
action: Action.TOGGLE_BOOKEND,
data: true,
label: 'Show bookend',
label: LocalizedStringId.AMP_STORY_SHOW_BOOKEND,
},
};

Expand Down Expand Up @@ -114,9 +120,15 @@ class PaginationButton {
this.element.querySelector('button')
);

/** @private @const {!../../../src/service/localization.LocalizationService} */
this.localizationService_ = getLocalizationService(doc);
processprocess marked this conversation as resolved.
Show resolved Hide resolved

this.element.classList.add(initialState.className);
initialState.label &&
this.buttonElement_.setAttribute('aria-label', initialState.label);
this.buttonElement_.setAttribute(
'aria-label',
this.localizationService_.getLocalizedString(initialState.label)
);
this.element.addEventListener('click', (e) => this.onClick_(e));

/** @private @const {!./amp-story-store-service.AmpStoryStoreService} */
Expand All @@ -134,7 +146,10 @@ class PaginationButton {
this.element.classList.remove(this.state_.className);
this.element.classList.add(state.className);
state.label
? this.buttonElement_.setAttribute('aria-label', state.label)
? this.buttonElement_.setAttribute(
'aria-label',
this.localizationService_.getLocalizedString(state.label)
Enriqe marked this conversation as resolved.
Show resolved Hide resolved
)
: this.buttonElement_.removeAttribute('aria-label');

this.state_ = state;
Expand Down Expand Up @@ -335,7 +350,7 @@ export class PaginationButtons {
const viewer = Services.viewerForDoc(this.ampStory_.element);
if (!hasBookend) {
if (viewer.hasCapability('swipe')) {
this.forwardButton_.updateState(ForwardButtonStates.NEXT_PAGE);
this.forwardButton_.updateState(ForwardButtonStates.NEXT_STORY);
} else {
this.forwardButton_.updateState(ForwardButtonStates.REPLAY);
}
Expand Down
8 changes: 7 additions & 1 deletion src/localized-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {parseJson} from './json';
* - NOT be reused; to deprecate an ID, comment it out and prefix its key with
* the string "DEPRECATED_"
*
* Next ID: 90
* Next ID: 96
*
* @const @enum {string}
*/
Expand All @@ -39,6 +39,7 @@ export const LocalizedStringId = {
AMP_STORY_BOOKEND_MORE_TO_READ_LABEL: '30',
AMP_STORY_BOOKEND_PRIVACY_SETTINGS_TITLE: '29',
AMP_STORY_BOOKEND_PRIVACY_SETTINGS_BUTTON_LABEL: '28',
AMP_STORY_CLOSE_BOOKEND: '94',
AMP_STORY_CLOSE_BUTTON_LABEL: '87',
AMP_STORY_CONSENT_ACCEPT_BUTTON_LABEL: '22',
AMP_STORY_CONSENT_DECLINE_BUTTON_LABEL: '23',
Expand All @@ -56,12 +57,16 @@ export const LocalizedStringId = {
AMP_STORY_HINT_UI_NEXT_LABEL: '2',
AMP_STORY_HINT_UI_PREVIOUS_LABEL: '3',
AMP_STORY_INFO_BUTTON_LABEL: '68',
AMP_STORY_NEXT_PAGE: '91',
AMP_STORY_NEXT_STORY: '90',
AMP_STORY_PAGE_ATTACHMENT_OPEN_LABEL: '35',
AMP_STORY_PAGINATION_BUTTON_PREVIOUS_PAGE_LABEL: '82',
AMP_STORY_PAGE_ERROR_VIDEO: '65',
AMP_STORY_PAGE_PLAY_VIDEO: '34',
AMP_STORY_PAUSE_BUTTON_LABEL: '85',
AMP_STORY_PLAY_BUTTON_LABEL: '86',
AMP_STORY_PREVIOUS_PAGE: '93',
AMP_STORY_REPLAY: '92',
AMP_STORY_SHARE_BUTTON_LABEL: '69',
AMP_STORY_SHARING_CLIPBOARD_FAILURE_TEXT: '4',
AMP_STORY_SHARING_CLIPBOARD_SUCCESS_TEXT: '5',
Expand All @@ -78,6 +83,7 @@ export const LocalizedStringId = {
AMP_STORY_SHARING_PROVIDER_NAME_TUMBLR: '14',
AMP_STORY_SHARING_PROVIDER_NAME_TWITTER: '15',
AMP_STORY_SHARING_PROVIDER_NAME_WHATSAPP: '16',
AMP_STORY_SHOW_BOOKEND: '95',
AMP_STORY_SIDEBAR_BUTTON_LABEL: '70',
AMP_STORY_SKIP_NEXT_BUTTON_LABEL: '88',
AMP_STORY_TOOLTIP_EXPAND_TWEET: '36',
Expand Down