PHP switch writing mode based on selected language?

733 Views Asked by At

I'm not a php expert so I'm having some trouble trying to write a code that will detect if the page is in Chinese and if so make the writing mode vertical right to left. I'm using qtranslate to switch between english and chinese.

Heres a sample page: http://occa-art.com/cai-yuan/biography/

My first attempt was to put this in the header:

<?php if(qtrans_getLanguage()=='zh'): ?>
<style type="text/css">
#content, #nav {
writing-mode: tb-rl;}
</style>
<?php endif; ?>

I then took that out and tried the following code in an external php/css stylesheet based on this tutorial: http://www.blog.hemminga.net/index.php/conditional-css-through-php?blog=6:

<?php header("Content-type: text/css"); ?>

<?php
if (qtrans_getLanguage()=='zh')
{
    $chinese = 1;
}
if (qtrans_getLanguage()=='en')
{
    $chinese = 0;
}
?>

#content, #nav {
    <?php
    if ( $chinese )
    {
        echo ( "writing-mode: tb-rl; \n" );
    }
    else
    {
        echo ( "writing-mode: lr-tb; \n" );
    }
    ?>
<?php endif; ?>`

Neither have had any effect. Any help would be very much appreciated!

2

There are 2 best solutions below

1
On BEST ANSWER

In the end I had to go a different route and simply change the width to force the chinese text to be vertical. Writing-mode just would not work for me.

Heres what I used:

<!-- Nav layout based on language -->
<?php
if ( qtrans_getLanguage() == 'zh' ) { ?>
<style type="text/css" media="screen">
#page_nav li, #nav li {
    width: 1em;
    float: left;
    margin-right: 5px;
    margin-left: 0px;
    margin-top: 0px;
    font-size: 15px;
}
#page_nav {
    height: 86px;
}
</style>
<?php } else { ?>
<style type="text/css" media="screen">
#page_nav li {
    margin-right: 10px;
    margin-left: 0px;
    display: inline;
}
#page_nav ul {
    margin-top: 10px;
}
#page_nav {
    height: 78px;
}
</style>
<?php } ?>
<!--END-->
2
On

You probably get a syntax error.

As you use {} You should remove this piece of code:

<?php endif; ?>

and close your CSS statement. Here is a shorter way to do it:

<?php header("Content-type: text/css"); ?>

#content, #nav {
    <?php
        if ( qtrans_getLanguage() == 'zh' ) {
               echo ( "writing-mode: tb-rl; \n" );
        }
        else {
            echo ( "writing-mode: lr-tb; \n" );
        }
    ?>
}