Text Cursor Indicator by language direction

62 views Asked by At

i am making a task management system and i am having trouble with a RTL configration that isn't talked about much in other forums...
The app will use mainly hebrew but english aswell. I would like the text cursor indicator that usually starts on the left (because the default setting for it is LTR) to start on the direction of the language that is currently selected.
For example, if my computer is currently on hebrew, the text cursor indicator will start on the right.
If i suddenly change the language to english, it will move to the left.
I want the Text Cursor Indicator to be rtl or ltr according to the selected language on my PC.

This is the "Text Cursor Indicator" for anyone that doesn't understand what I'm talking about:
Text-Cursor-Indicator.img

i have changed my default direction into rtl as a compromise for now, like so:

<html dir="rtl">

But this isn't the solution i want.
Thank you!

1

There are 1 answers

0
Fred On

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo but it doesn't work in all web browsers yet.

const locale = new Intl.Locale(navigator.language);
const dir = locale.getTextInfo().direction;
const input = document.getElementById('my-input');
input.dir = dir;