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

Improve text direction detection by adding the lang and dir attributes #8335

Closed
SamMousa opened this issue May 30, 2024 · 1 comment · Fixed by #8468
Closed

Improve text direction detection by adding the lang and dir attributes #8335

SamMousa opened this issue May 30, 2024 · 1 comment · Fixed by #8468
Assignees
Labels
enhancement user issue An issue or bug reported by users
Milestone

Comments

@SamMousa
Copy link
Contributor

Are you requesting a feature, reporting a bug or asking a question?

Bug / feature

What is the current behavior?

SurveyJS doesn't support RTL languages automatically.

What is the expected behavior?

It should be supported automatically (and dynamically)

How would you reproduce the current behavior (if this is a bug)?

Solution

I realize this is quite a complex topic. I've been researching solutions for a bit.
First of all we need to note a few things:

  1. SurveyJS does not control full page HTML (the survey may be in a different language from the page) -- This means we should set a lang attribute on the proper element.
  2. SurveyJS renders localized texts, but if not available falls back to the default locale. These need not have the same text direction.

If we ignore 2 for now, we could:

  1. Add lang={survey.language} to the survey root element dynamically. (So it updates when survey language changes)
  2. Add css like this to force a text direction, setting the text direction will also automatically adjust the default direction of flex:row, which is what we need for navigation buttons.

My working code to fix this looks like this:

combineLatest([locale$, rootElement$]).subscribe(([locale, rootElement]) => {
		rootElement.setAttribute('lang', locale ?? 'en')
		/**
		 * When getTextInfo becomes available in FF we can drop this library
		 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
		 */
		rootElement.setAttribute('dir', rtlDetect.isRtlLang(locale ?? 'en') ? 'rtl' : 'ltr');
		console.log(rootElement);
	});

Note that rootElement$ and locale$ are observables linked to the survey.

@SamMousa SamMousa changed the title Improve text direction detection by adding dir="auto" Improve text direction detection by adding lang and dir attributes May 30, 2024
@JaneSjs JaneSjs added enhancement user issue An issue or bug reported by users labels May 31, 2024
@JaneSjs JaneSjs assigned JaneSjs and tsv2013 and unassigned JaneSjs May 31, 2024
tsv2013 pushed a commit that referenced this issue Jun 25, 2024
tsv2013 pushed a commit that referenced this issue Jun 26, 2024
…dir attributes - try to fix maskup tests
tsv2013 pushed a commit that referenced this issue Jun 26, 2024
…dir attributes - try to fix markup tests
OlgaLarina added a commit that referenced this issue Jun 26, 2024
Implemented #8335 - Improve text direction detection by adding lang and dir attributes
@RomanTsukanov RomanTsukanov changed the title Improve text direction detection by adding lang and dir attributes Improve text direction detection by adding the lang and dir attributes Jul 2, 2024
@OlgaLarina OlgaLarina added this to the v1.11.5 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement user issue An issue or bug reported by users
Projects
None yet
4 participants