[SOLVED] aligning text in right-to-left languages

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

aligning text in right-to-left languages

Post by newmember »

i have a div where i dynamicly(with php) load text.
the thing is that this text might be hebrew and it will be displayed aligned to left.
what i mean is that it is pointless to set text direction for div because sometimes it will be left-to-right text and sometimes right-to-left text...

i don't really know what to do :?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Am I right in saying that you wish for text to be aligned in the position you wish?. If so try the good old pre tags.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you know the content needs left-to-right then set that direction, same for right-to-left... what's the big deal?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Why not justify you text? Will look the same then whatever direction the text reads in.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

feyd:
i don't know whether the content is hebrew or english
Why not justify you text?
i tried it with no luck...in css docs it is said:
Conforming user agents may interpret the value 'justify' as 'left' or 'right', depending on whether the element's default writing direction is left-to-right or right-to-left, respectively.
- so it depends on what ua decides
Am I right in saying that you wish for text to be aligned in the position you wish?.
no i'm not forcing text to align to some specific position...
the text is inside <p>. that's all.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Are you talking about visual align or text direction?
By 'visual align' I mean:
RTL hebrew aligned to the left:

Code: Select all

Margins   
                  |< -------------------->|
                  |WERBEH WERBEH          |
                  |WERBEH                 |
                  |WERBEH WERBEH          |
RTL hebrew aligned to the right

Code: Select all

Margins   
                  |< -------------------->|
                  |          WERBEH WERBEH|
                  |                 WERBEH|
                  |          WERBEH WERBEH|
and by 'direction' I mean:
LTR hebrew aligned to the left:

Code: Select all

Margins   
                  |< -------------------->|
                  |HEBREW HEBREW          |
                  |HEBREW                 |
                  |HEBREW HEBREW          |
LTR hebrew aligned to the right

Code: Select all

Margins   
                  |< -------------------->|
                  |          HEBREW HEBREW|
                  |                 HEBREW|
                  |          HEBREW HEBREW|
Please clarify.
Last edited by Weirdan on Tue Sep 21, 2004 2:24 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you analyzed the utf-8 byte stream, you would know what's in it.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

analyzed statistically, I'd say. Because languages do share some characters, for example both Russian and English use Arabic digits
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

Weirdan:
third picture(from top) is what i have but i want it to be like in the last picture

and about two first pictures...i hope this won't happen to me:)


feyd:
i can take a few characters,convert them to unicode and check whether they fall into hebrew range?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

newmember wrote:Weirdan:
third picture(from top) is what i have but i want it to be like in the last picture
I believe you're talking about first and second pictures respectively (try to read them right to left, from what I know it's how hebrew texts should be read).

newmember wrote: i can take a few characters,convert them to unicode and check whether they fall into hebrew range?
well, isn't them in unicode already?
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

about pictures...
i wrote 3 and 4 picture....because i assumed that each english character is a hebrew letter...so in pictures 1 and 2 hebrew letters are mirrored...but forget it...
basicly what i have is that hebrew direction is ok but the text itself is aligned to left instead to right...so
Are you talking about visual align or text direction?
now i see that i'm talking about visual align
isn't them in unicode already?
mmm... sort of...
the strings are in UTF-8 and it is multibyte encoding for unicode codepoints.
so i need to take part from each byte of utf-8 character and convert/transform them to unicode 2 byte codepoint...
right?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unicode can be 8, 16, 24, and 32 bit values... so it may be better to check what codepage the utf-8 controls are switching to..
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

how do i do that?
to check what codepage the utf-8 controls are switching to
i'm not completly understand what you're saying here
i think i ssaw somewhere that php support 16 bit unicode
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

either find or build a utf-8 analyzer that looks at the code pages the stream switches to.. count the number of characters in the pooled languages.. use that count to base your switch between left-to-right to right-to-left.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

i guess i'll do it later...
anyway if there is no more simple solution then it will wait until i have nothing to do more...
Post Reply