-
-
Notifications
You must be signed in to change notification settings - Fork 792
Fix: Set lang and dir attributes for RTL languages in non-multilingual sites (#6851) #6855
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
base: main
Are you sure you want to change the base?
Conversation
Caution The Volto Team has suspended its review of new pull requests from first-time contributors until the release of Plone 7, which is preliminarily scheduled for the second quarter of 2026. Thanks for submitting your first pull request! You are awesome! 🤗 If you haven't done so already, read Welcome to the Plone community! 🎉 |
@superAman07 you need to sign the Plone Contributor Agreement to merge this pull request. Learn about the Plone Contributor Agreement: https://plone.org/foundation/contributors-agreement If you have already signed the agreement, please allow a week for your agreement to be processed. If after a week you have not received an invitation, then please contact [email protected]. |
✅ Deploy Preview for plone-components canceled.
|
Some comments:
|
@erral BTW, about 80 years ago, Japanese horizontal shown was RTL, and Japanese has vertical shown without Internet. newspapers and books. |
Thanks @terapyon |
@@ -51,6 +51,31 @@ import RouteAnnouncer from '@plone/volto/components/theme/RouteAnnouncer/RouteAn | |||
* @class App | |||
* @extends {Component} | |||
*/ | |||
//added more languages | |||
const RTL_LANGUAGES = [ |
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.
This should not be here but in constants
'zh', | ||
'ja', | ||
'ko', | ||
]; |
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 list of languages should be reviewed, not all listed here are RTL (for instance ja, see @terapyon's comment). As a reference this is the list of RTL languages in Classic: https://github.com/plone/plone.app.layout/blob/master/plone/app/layout/globals/portal.py#L21
i18next has the following language codes listed as RTL:
@erral Any thoughts on if it's worth fetching the list of languages from the backend so it's consistent across all of Plone? |
The list is fixed, so it will never change, so I see no problem on duplicating them on the frontend and the backend. |
Description
This pull request addresses issue #6851, which highlights a problem where the tag's lang attribute remains in English (en) and the dir attribute is missing when a page is set to a Right-to-Left (RTL) language in a non-multilingual site.
Changes Made
Dynamic lang Attribute:
The tag now dynamically sets the lang attribute based on the page's language.
If the page's language is not explicitly set, it falls back to the default locale.
Dynamic dir Attribute:
Added a dir attribute to the tag to handle text direction.
The direction is determined based on a predefined list of RTL languages (RTL_LANGUAGES).
Code Updates:
Modified the App.jsx file to include logic for determining the lang and dir attributes.
Used the Helmet component to inject these attributes into the tag.
Expected Behavior
When a page is set to an RTL language (e.g., Arabic, Hebrew), the tag will have:
lang="ar" (or the appropriate language code).
dir="rtl" for correct text alignment.
For Left-to-Right (LTR) languages, the dir attribute will default to ltr.
Testing
Since the full setup (including Docker) was not available, the changes were implemented based on the issue description and expected behavior. The logic for dynamically setting the lang and dir attributes has been added and should work as intended. However, the UI for changing the language was not tested directly.
Linked Issue
Fixes #6851.
Screenshots
N/A
Checklist
Code changes are implemented based on the issue description.
Changes are tested locally (UI testing was not performed due to setup limitations).
The issue is resolved as described.
No breaking changes introduced