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

Add lang and dir attributes to text-formatting tools #49985

Merged
merged 34 commits into from
May 11, 2023
Merged

Conversation

aristath
Copy link
Member

@aristath aristath commented Apr 21, 2023

What?

This PR adds the ability to select the lang and dir attributes, So that users can make parts of their text in a different language. This helps assistive technologies like screen-readers to properly understand what language the text is in, and use the proper pronunciation when reading the text.

Why?

Because not all text is in English and there are lots of sites that use more than one languages. This addition will help content writers to produce more accessible content.

How?

We started exploring ways to do that with @afercia, @carolinan and @SergeyBiryukov, but we later found that @audrasjb already built a plugin for that in https://github.com/audrasjb/language-attribute-for-gutenberg
This PR is a port of that plugin to Gutenberg, huge props to @audrasjb for all the work there! ❤️
We fixed some deprecation notices, and adapted the code a bit for use in Gutenberg, but other than that it's an almost verbatim copy of that code.

Testing Instructions

  1. Add some text and then select it.
  2. Go to the text tools, and click on the language icon
  3. Add a language like fr, it etc, and select if the language is LTR or RTL
  4. Verify that the markup (both in the editor and the frontend has the right lang and dir attributes
  5. Verify that you can remove the attributes by clicking on the language selector again

Screenshots or screencast

The screencast below shows selecting and deselecting the language, and how that applies to the markup.

Screen.Recording.2023-04-21.at.11.38.25.AM.mov

Props @audrasjb, @afercia, @carolinan, @SergeyBiryukov, @aristath

@github-actions
Copy link

github-actions bot commented Apr 21, 2023

Size Change: +581 B (0%)

Total Size: 1.39 MB

Filename Size Change
build/format-library/index.min.js 7.8 kB +540 B (+7%) 🔍
build/format-library/style-rtl.css 577 B +20 B (+4%)
build/format-library/style.css 577 B +21 B (+4%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.33 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 483 B
build/block-directory/index.min.js 7.2 kB
build/block-directory/style-rtl.css 1.05 kB
build/block-directory/style.css 1.05 kB
build/block-editor/content-rtl.css 4.17 kB
build/block-editor/content.css 4.16 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
build/block-editor/index.min.js 205 kB
build/block-editor/style-rtl.css 15.3 kB
build/block-editor/style.css 15.3 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 138 B
build/block-library/blocks/audio/theme.css 138 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 91 B
build/block-library/blocks/avatar/style.css 91 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 587 B
build/block-library/blocks/button/editor.css 587 B
build/block-library/blocks/button/style-rtl.css 628 B
build/block-library/blocks/button/style.css 627 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 409 B
build/block-library/blocks/columns/style.css 409 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.62 kB
build/block-library/blocks/cover/style.css 1.61 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 159 B
build/block-library/blocks/details/style.css 159 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 138 B
build/block-library/blocks/embed/theme.css 138 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 269 B
build/block-library/blocks/file/style.css 270 B
build/block-library/blocks/file/view.min.js 379 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 957 B
build/block-library/blocks/gallery/editor.css 962 B
build/block-library/blocks/gallery/style-rtl.css 1.55 kB
build/block-library/blocks/gallery/style.css 1.55 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 340 B
build/block-library/blocks/html/editor.css 341 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 652 B
build/block-library/blocks/image/style.css 652 B
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 507 B
build/block-library/blocks/media-text/style.css 505 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 716 B
build/block-library/blocks/navigation-link/editor.css 715 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation/editor-rtl.css 2.13 kB
build/block-library/blocks/navigation/editor.css 2.14 kB
build/block-library/blocks/navigation/style-rtl.css 2.22 kB
build/block-library/blocks/navigation/style.css 2.21 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 501 B
build/block-library/blocks/post-comments-form/style.css 501 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 322 B
build/block-library/blocks/post-featured-image/style.css 322 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 281 B
build/block-library/blocks/post-template/style.css 281 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 434 B
build/block-library/blocks/search/style.css 432 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 329 B
build/block-library/blocks/shortcode/editor.css 329 B
build/block-library/blocks/site-logo/editor-rtl.css 760 B
build/block-library/blocks/site-logo/editor.css 760 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.4 kB
build/block-library/blocks/social-links/style.css 1.39 kB
build/block-library/blocks/spacer/editor-rtl.css 359 B
build/block-library/blocks/spacer/editor.css 359 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 651 B
build/block-library/blocks/table/style.css 650 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 179 B
build/block-library/blocks/video/style.css 179 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.12 kB
build/block-library/common.css 1.12 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 11.8 kB
build/block-library/editor.css 11.8 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 204 kB
build/block-library/interactive-blocks/interactivity.min.js 2.19 kB
build/block-library/interactive-blocks/navigation.min.js 841 B
build/block-library/interactive-blocks/vendors.min.js 8.15 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 12.8 kB
build/block-library/style.css 12.8 kB
build/block-library/theme-rtl.css 698 B
build/block-library/theme.css 703 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 51.1 kB
build/commands/index.min.js 15 kB
build/commands/style-rtl.css 807 B
build/commands/style.css 804 B
build/components/index.min.js 210 kB
build/components/style-rtl.css 11.8 kB
build/components/style.css 11.8 kB
build/compose/index.min.js 12.4 kB
build/core-commands/index.min.js 1.84 kB
build/core-data/index.min.js 16.7 kB
build/customize-widgets/index.min.js 12.2 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 718 B
build/data/index.min.js 8.73 kB
build/date/index.min.js 40.5 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.76 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/index.min.js 35.4 kB
build/edit-post/style-rtl.css 7.84 kB
build/edit-post/style.css 7.83 kB
build/edit-site/index.min.js 64.7 kB
build/edit-site/style-rtl.css 10.6 kB
build/edit-site/style.css 10.6 kB
build/edit-widgets/index.min.js 17.3 kB
build/edit-widgets/style-rtl.css 4.58 kB
build/edit-widgets/style.css 4.58 kB
build/editor/index.min.js 46 kB
build/editor/style-rtl.css 3.59 kB
build/editor/style.css 3.59 kB
build/element/index.min.js 4.95 kB
build/escape-html/index.min.js 548 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.79 kB
build/keycodes/index.min.js 1.94 kB
build/list-reusable-blocks/index.min.js 2.14 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.99 kB
build/notices/index.min.js 977 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 952 B
build/react-i18n/index.min.js 702 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.75 kB
build/reusable-blocks/index.min.js 2.26 kB
build/reusable-blocks/style-rtl.css 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 11.1 kB
build/router/index.min.js 1.77 kB
build/server-side-render/index.min.js 2.09 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.55 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.74 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.3 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@github-actions
Copy link

github-actions bot commented Apr 21, 2023

Flaky tests detected in c17d58a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4858789910
📝 Reported issues:

@alexstine alexstine self-requested a review April 21, 2023 12:46
Copy link
Contributor

@alexstine alexstine left a comment

Choose a reason for hiding this comment

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

@aristath Thanks. A couple accessibility notes below.

packages/format-library/src/language/index.js Outdated Show resolved Hide resolved
packages/format-library/src/language/index.js Show resolved Hide resolved
Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

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

This looks great to me, thank you Ari!
This changeset would be a great enhancement for better accessibility of the Gutenberg project.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

@aristath, maybe we should wrap popover controls inside the form? Then, the button will become a submit button, and the onClick logic will migrate to the form's onSubmit callback.

The form actions in popovers are usually right-aligned. There might be other design details that I'm missing, so let's request design feedback.

@alexstine
Copy link
Contributor

@aristath Thanks, accessibility issues fixed.

One last issue I noticed and I am not sure if you can do anything about it or not. To replicate:

  1. Apply a language tag such as fr.
  2. Remove the language tag by unchecking More > Language option.
  3. Notice how you must select the block again to make the text revert to English. Press escape then enter to make the block re-render.

Not sure if this is an accessibility-specific issue or something you can notice visually as well. NVDA sometimes struggles with languages so it may not be anything you can fix here.

Thanks.

@Mamaduka Mamaduka added Needs Design Feedback Needs general design feedback. [Package] Format library /packages/format-library [Type] Feature New feature to highlight in changelogs. labels Apr 25, 2023
@aristath
Copy link
Member Author

aristath commented May 2, 2023

@aristath, maybe we should wrap popover controls inside the form? Then, the button will become a submit button, and the onClick logic will migrate to the form's onSubmit callback.

Thank you for the suggestion @Mamaduka!
I pushed the change, and the code looks better now 👍

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks for the follow-up work, @aristath! I think we're almost there, codewise.

The design feedback would be appreciated before merging. Maybe @jasmussen could help us here 🙇

a11y question: Should the focus remain on the text after selecting the language?

packages/format-library/src/language/index.js Outdated Show resolved Hide resolved
packages/format-library/src/language/index.js Outdated Show resolved Hide resolved
packages/format-library/src/language/index.js Show resolved Hide resolved
@jasmussen
Copy link
Contributor

A question: is this advanced enough that it should live, literally, in the "advanced" section? I've never once had a need to use this attribute, and giving it block toolbar prominence may be overdoing it.

I understand this adds a span and is inline formatting:
Screenshot 2023-05-03 at 10 47 23

That makes it less appropriate to put it in the advanced section. But still: should it be inline level? Shouldn't it be block level for the whole paragraph? Is there a common use case of using the language attribute on only a selection of text? Asking genuinely here as I have little experience with using this attribute.

If we do keep it in the block toolbar as an inline element, and unless the list of inline tools are sorted alphabetically, let's sort it at the bottom. And let's update the icon as well. Perhaps something like this:

<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="enable-background:new 0 0 24 24" viewBox="0 0 24 24"><path d="M17.5 10h-1.7l-3.7 10.5h1.7l.9-2.6h3.9l.9 2.6h1.7L17.5 10zm-2.2 6.3 1.4-4 1.4 4h-2.8zm-4.8-3.8c1.6-1.8 2.9-3.6 3.7-5.7H16V5.2h-5.8V3H8.8v2.2H3v1.5h9.6c-.7 1.6-1.8 3.1-3.1 4.6C8.6 10.2 7.8 9 7.2 8H5.6c.6 1.4 1.7 2.9 2.9 4.4l-2.4 2.4c-.3.4-.7.8-1.1 1.2l1 1 1.2-1.2c.8-.8 1.6-1.5 2.3-2.3.8.9 1.7 1.7 2.5 2.5l.6-1.5c-.7-.6-1.4-1.3-2.1-2z" /></svg>

@aristath
Copy link
Member Author

aristath commented May 3, 2023

Thank you for the feedback @jasmussen!

A question: is this advanced enough that it should live, literally, in the "advanced" section? I've never once had a need to use this attribute, and giving it block toolbar prominence may be overdoing it.

It's true that we don't necessarily see it used that often, however, we should. If I write on my food blog "every bite takes you home. Bon appétit!", then optimally, "Bon appétit" should be in French so that the screen-reader can use the correct pronunciation of the phrase. In comparison to the other tools we have in that toolbar (subscript, superscript, keyboard-input), I'd argue that language would be far more useful

Shouldn't it be block level for the whole paragraph?

It should be at the block level as well, yes... But I left that for a follow-up PR.

Is there a common use case of using the language attribute on only a selection of text? Asking genuinely here as I have little experience with using this attribute.

One common use case would be the "Bon appétit" example above. Another scenario would be a site in Arabic, with a quote in French, by an Italian. In this case, the ar language of the page is set globally by WP, then we'd need a block-level attribute to set the whole quote to be fr, and inline to set the citation to it.
We can use the inline attribute to set the text of the quote to fr, and we can use it to select a whole paragraph and make it a different language (in lieu of a block-level attribute), but we can't use the block-level attribute to target words, which is why this PR started with the inline implementation.

If we do keep it in the block toolbar as an inline element, and unless the list of inline tools are sorted alphabetically, let's sort it at the bottom.

They are sorted alphabetically 👍

And let's update the icon as well

Thank you! That icon does look a lot better than the one I copy-pasted from dashicons 🎉

@jasmussen
Copy link
Contributor

I'd love a quick glance by @WordPress/gutenberg-design as well, but the use case seens valid enough. That said, I'm a little concerned about ballooning UI for such a rarely used feature, especially if we need to have both an inline and a block level button both. To an extent, I wish this was something that could be entirely automated, something where the parser could apply the appropriate attributes based on a detected language entirely invisibly. Definitely not trivial to implement, but it would ensure always semantic output, at no headspace cost of possible.

If we do move forward, be sure to add the icon to the main icon library component, I'm sure we'll be able to use it elsewhere as well.

@audrasjb
Copy link
Contributor

audrasjb commented May 3, 2023

That said, I'm a little concerned about ballooning UI for such a rarely used feature, especially if we need to have both an inline and a block level button both.

This is not rarely used at all, it is just mandatory for accessibility (and accessibility compliance is a thing for a lot of website owners) :)
While the block-level feature is helpful to avoid having to select all the text in a block that is entirely in another language than the rest of the page, the inline level is mandatory to indicate language changes inside a sentence (which is not an option but mandatory for accessibility compliance).

To an extent, I wish this was something that could be entirely automated, something where the parser could apply the appropriate attributes based on a detected language entirely invisibly. Definitely not trivial to implement, but it would ensure always semantic output, at no headspace cost of possible.

I'm afraid this won't work until many years as we'd need an implementation of language detection in the editor. I'm not aware of any language detection tool capable of isolating specific terms in a portion of a non english text, and to expose them so we can wrap it with the correct markup :)

@paaljoachim
Copy link
Contributor

How interesting!
At first I thought why, but as I began reading I understood the point of using a phrase from another language and having the correct language formatting and accessibility for the specific text. It could be used in a quote or really anything.
Adding the icon/option into the More drop down seems like a good way of adding this option (even though the More drop down is gradually becoming longer). Adding it into the UI makes it possible for even more users to actually go ahead and use this feature when it is needed.

Screenshot 2023-05-03 at 16 08 54

@afercia
Copy link
Contributor

afercia commented May 3, 2023

ballooning UI for such a rarely used feature

Honestly, I think it would be way more used than the subscript or superscript inline formatting. The fact you personally have little knowledge about the lang attribute shouldn't lead you to the conclusion it is not that important. Rather, I'd consider ways for WordPress to actually educate users on its importance instead of burying this feature down in a place where it would be basically not discoverable.

I'm afraid this won't work until many years

Right. On top of that, we shouldn't assume words in another language have to be always marked with the lang attribute. There are legitimate cases where some content would need to be intentionally marked with a language that doesn't match the actual content language, e.g. to emulate the accent of a Spanish person speaking French.

@jameskoster
Copy link
Contributor

Seems like a nice enhancement to me 👍

A couple of questions on the UI though:

Do we need to validate to ensure the user input a recognised country code? Alternatively could we use a search input with suggestions and extract the code from that? Kind of like the tag UI:

Screenshot 2023-05-03 at 15 18 00

Similarly, can the text direction be determined automatically based on the chosen language?

@aristath
Copy link
Member Author

One last thing - should we match the actions buttons to other editor modals? I was reminded of this after reading @afercia's latest issue - #50518

Good point. Pushed a fix for that and rebased the PR 👍

@Mamaduka
Copy link
Member

Thank you, Ari. Feel free to merge this after all checks are green 🚢

@aristath aristath merged commit 37d9839 into trunk May 11, 2023
@aristath aristath deleted the try/lang-attr branch May 11, 2023 12:44
@github-actions github-actions bot added this to the Gutenberg 15.9 milestone May 11, 2023
@audrasjb
Copy link
Contributor

Awesome! Thanks all and especially @aristath for making this real!
I will be more than happy to close my little plugin once this gets merged into Core 🙏 😄

@ellatrix
Copy link
Member

Hi! Shouldn't we use the bdo element? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdo
I think it's fine to use it even if the direction is not changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Design Feedback Needs general design feedback. [Package] Format library /packages/format-library [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Language and text direction are not editable in the visual editor
9 participants