1

I need to reverse a text by lines on a webpage to switch from the RTL writing mode to a LTR writing mode. In the source code it's need to remain the original RTL latin alphabets text, but on the page I need to visualize a LTR text with a non-latin font-family (the text will remain in latin characters, only the font-family change). My question is how can I do that? How can I know, when the browser where will break the lines?

(It's simpler to understand if you heard about the hungarian runic alphabet. I want to make a script what convert the latin text into runic text, but I want to the search engines see the original text.) Thanks for your help.

lw_lewy
  • 15
  • 4
  • http://stackoverflow.com/questions/958908/how-do-you-reverse-a-string-in-place-in-javascript might help – sottenad Nov 15 '11 at 16:45
  • My problem not the reversing itself. My problem is how can I find the intervals where I need to reverse the string. So the long text needed to be from right to left, but it' need to remain from top to bottom. – lw_lewy Nov 15 '11 at 16:55

2 Answers2

1

I believe that even if you set the direction to "rtl" (dir attribute is recommended) the words will stay in the same order unless you have hebrew or arabic characters in your string.

If you wrap your content in bdo tags e.g. <bdo dir="rtl">text</bdo> then the text will be reversed letter by letter.

If you just want word by word then you can add some tricky Javascript like

"some content".split(' ').reverse().join(' ');
Ernest
  • 570
  • 3
  • 6
0

What if you change the direction css property on your body tag from "ltr" to "rtl"?

With jQuery you could do :

$('body').css('direction', 'rtl');

or in plain javascript, something like :

document.getElementsByTagName('body')[0].style.direction = 'rtl';
Leo
  • 5,069
  • 2
  • 20
  • 27
  • I tried this before my question, but this not resolved my problem. It's just do this: http://www.w3schools.com/cssref/tryit.asp?filename=trycss_text_direction – lw_lewy Nov 15 '11 at 16:56