Results 1 to 6 of 6

Thread: How to automatically change the site direction LTR\RTL?

  1. #1
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to automatically change the site direction LTR\RTL?

    Hi all

    I am looking to make my site bilingual (Arabic\English) that's mean 2 different directions

    English => LTR "Left To Right"
    Arabic => RTL "Right To Left"

    so, i need a script "Like facebook" that when the user choose Arabic Language the site will change the whole template+Text to RTL, and the exact opposite when choose English language.

    Thanks & Best Regards,

    P.S I've searched on this forum for this case, but i didn't find a useful info, so if there is a post talk about the same issue and it's [Resolved] kindly put the link below.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There are several ways to approach this. I am working on a similar site.

    The 'dir' attribute can attach to many tags. You can specify it on each if you would like or you can just use it for the whole html tag:
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">

    The way that my site works is that the 'ltr' (and 'en') values are automatically generated using PHP.
    I think you could also do this using Javascript, but it is probably better to do this on the server (PHP, ASP, CGI, etc) because then it won't require Javascript so it will work for all users.


    That is a complete solution, unless you need to mix languages. In that case, use <tag dir="ltr"> (or rtl) as needed.



    That will not actually reverse the layout, just the text. If you want to mirror the entire site (this will be confusing for images), then you can use that and also switch every instance of "left" and instance of "right" in your CSS and html and it will flip it. For example: <div align="left"> vs <div align="right">
    I thought about doing this for my site (decided to not make it this complicated), and here is the idea that I had (and it worked):
    <div align="<?php echo $left; ?>">

    That line outputs a variable called "left".
    If the language is LTR then I set that to 'left' (so it reads: align="left").
    If the language is RTL then I set that to 'right' (so it reads: align="right").
    So I use $left and $right based on the English direction. For arabic, $left would be "right" and $right would be "left".
    You could also name them $startdir and $enddir, but that is a little more confusing. Basically I look at it as designing the site for English then allowing Arabic to switch it. (You could do the opposite).


    In general just changing the direction on the <html> tag should be enough.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot djr33 !

    can you please write the script

    i am not that expert on Java scripts ,but on php i can help

    let's say i want to mirror the entire site

    and the lang variable is "&lang_id=5" thats for Arabic, Eng is "&lang_id=1"

    I appreciate your efforts to help me

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Everything I've described is for PHP, not Javascript.

    Why do you need this for Javascript? Are you changing the language using Javascript?

    Or would you like to use PHP?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Everything I've described is for PHP, not Javascript.

    Why do you need this for Javascript? Are you changing the language using Javascript?

    Or would you like to use PHP?
    i am not that prof in coding

    i am just studying php till now

    i am recently work on Social Engine called SE, but it doesn't support auto swap between RTL\LTR langs ...

    so, can you please write the code...??

    thanks in advance

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    <?php
    $language 
    'arabic'//or 'english' //set the system language
    $rtl = array('arabic','hebrew','urdu'); //make a list of rtl languages
    $textdir 'ltr';
    if (
    in_array($language,$rtl)) { //is this a rtl language?
        
    $textdir 'rtl'//switch the direction
    //end if
    ?>
    <html dir="<?php echo $textdir?>">
    <!--now the HTML tag has the right direction in it, either rtl or ltr-->
    If you don't understand that, then you should read some tutorials. It's not really possible to explain it better. If you'd prefer that someone does this for you (this is a 'help' forum, not a 'do-it-for-you' forum), then you could post this as a paid request and you won't need to do it yourself. But for free, the example above is close enough.

    If you have a specific question about some code you have, please post the code. But without code (just asking for ideas), there's not much more I can do.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •