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

Font size picker: Fix i10n and a11y for HeaderLabel #68826

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

im3dabasia
Copy link
Contributor

@im3dabasia im3dabasia commented Jan 22, 2025

Closes: #63810

What?

  • This PR refactors the font-size-picker component to improve the translation in the HeaderLabel. It ensures that text concatenation issues are resolved for gendered languages (e.g., Italian).
  • There is an aria-label in the HeaderLabel component, which renders a <span>. Since this element is non-interactive and purely for display purposes, having an aria-label here does not make sense, as it would be ignored by screen readers.

Why?

Currently, the font-size-picker renders text by concatenating strings (e.g., "Size " + headerHint), which makes translation inaccurate for languages with gendered nouns. For example, in Italian, the noun 'Size' is translated to the feminine form "Dimensione," but concatenating it with size adjectives (which are masculine) results in incorrect translations like "Dimensione piccolo" (incorrect).

How?

  • Refactored the HeaderLabel component to use createInterpolateElement for proper translation of Size and headerHint.
  • Removed the aria-label in the HeaderLabel.

@im3dabasia im3dabasia marked this pull request as ready for review January 22, 2025 11:05
@im3dabasia im3dabasia requested a review from ajitbohra as a code owner January 22, 2025 11:05
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia changed the title Font size picker: Fix i10n for HeaderLabel Font size picker: Fix i10n and a11y for HeaderLabel Jan 22, 2025
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Feature] UI Components Impacts or related to the UI component system labels Jan 22, 2025
@im3dabasia
Copy link
Contributor Author

@afercia , Thank you for creating the issue #63810

I have drafted a possible solution and would appreciate any feedback. I took inspiration from here. Let me know if this works for our case.

Code

{ isCustom && (
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Custom format' ) }
hideLabelFromVision
help={ createInterpolateElement(
__(
'Enter a date or time <Link>format string</Link>.'
),
{
Link: (
<ExternalLink
href={ __(
'https://wordpress.org/documentation/article/customize-date-and-time-format/'
) }
/>
),
}
) }
value={ format }
onChange={ ( value ) => onChange( value ) }
/>
) }

) : (
<></>
),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using createInterpolateElement is certainly better than concatenation but it still doesn't solve the translation problem. headerHint retunrs the 't-shirt names' that are just appended to the first part of the string Size.

https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/font-size-picker/constants.ts/#L31-L37

As the t-shirt names are translated separately they can't be conjugate correctly with the gender of the noun Size. The only way to solve this for all languages is by providing fully translatable strings. e.g.:

__( 'Size Small' ),
__( 'Size Medium' ),
__( 'Size Large' ),
__( 'Size Extra Large' ),
__( 'Size Extra Extra Large' ),

The strings may contain HTML or placeholder for some HTML to preserve the intende design but I'd consider that minor. The implementation should be changed accordingly in order to use the full strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

The headerHint text may be changed by theme.json. Example:

Details
{
	"version": 3,
	"settings": {
		"typography": {
			"defaultFontSizes": false,
			"fontSizes": [
				{
					"name": "Custom small",
					"size": "14px",
					"slug": "small"
				},
				{
					"name": "Custom medium",
					"size": "16px",
					"slug": "medium"
				}
			]
		}
	}
}

Therefore, I think it is impossible to provide fully translatable text with the current implementation. In this PR, I would like to avoid making major changes to the design and implementation and propose an approach using createInterpolateElement.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure refraining from reconsidering design and implementation helps building a better UI. Design should prioritize functionality and follow the best practices established in WordPress. Otherwise it's not design. The implementation is unnecessary comples and inconsistent at the point I'm considering to propose to entirely remove the headerHint. Will detail on the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the fact headerHint displays the font size names provided by the theme may potentially make it display inappropriate strings as the names quality and length is unpredictable. It could really be anything, totally uncontrolled. Screenshot:

Screenshot 2025-01-27 at 09 11 45

Copy link
Contributor

Choose a reason for hiding this comment

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

Design should prioritize functionality and follow the best practices established in WordPress.

Can you tell us what you think is the best approach to take with this PR?

the fact headerHint displays the font size names provided by the theme may potentially make it display inappropriate strings as the names quality and length is unpredictable. It could really be anything, totally uncontrolled.

This issue is discussed here: #68344

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell us what you think is the best approach to take with this PR?

I'm considering to propose to entirely remove headerHint. See #63810 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we delete headerHint, how will users know about the custom labels? Without custom labels, users may not understand the meaning of the font sizes the theme provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font size picker: fix translatable strings and accessibility
4 participants