Page 1 of 1
Convert to Right-to-Left
Posted: Mon Dec 22, 2008 8:30 pm
by maximoox
Hello everyone,
I am working on a PHP script site that was originally written in English so all characters, words, images are set to appear from Left-to-Right by default.
I am trying to use this script in Persian Language where everything should appear in the opposite direction as in Persian Script writing starts from Right-to-Left.
Is there an easy way of doing this change in PHP? I am not sure if this is something that needs to be done on every single .php page or I can just add a line of code in the style.css file and be done.
Any help or feedback would be appreciated.
Re: Convert to Right-to-Left
Posted: Tue Dec 23, 2008 2:36 am
by Mark Baker
It's not determined by PHP, but by the HTML and the browser:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-gb" />
Change dir="ltr" and the charset and lang settings as appropriate
Re: Convert to Right-to-Left
Posted: Tue Dec 23, 2008 9:52 pm
by maximoox
Mark Baker wrote:It's not determined by PHP, but by the HTML and the browser:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-gb" />
Change dir="ltr" and the charset and lang settings as appropriate
Thanks for your reply.
Do I need to add the above codes into every php page? or just in the index.php will do?
Re: Convert to Right-to-Left
Posted: Tue Dec 23, 2008 11:38 pm
by Chris Corbyn
You need the code to be *output* to the browser for every page. As to whether that means you need it in every .php page we don't know without seeing your code.
Wherever your <html> tags are output, that's where it needs to be.
Re: Convert to Right-to-Left
Posted: Sun Dec 28, 2008 1:01 pm
by maximoox
Chris Corbyn wrote:You need the code to be *output* to the browser for every page. As to whether that means you need it in every .php page we don't know without seeing your code.
Wherever your <html> tags are output, that's where it needs to be.
Okay, I was able to move all contents to RTL. Now everything appears from Right to Left except for my Category Titles that is still LTR.
I noticed that in mysql database "Collation" shows "latin1_swedish_ci" in my phpmyadmin, I am not sure if this has anything to do with my issue or not. Should I change this setting to "utf8_general_ci"? is it risky to modify this setting in MySQL?
Right now my index.php page is set to output everything from Right to Left... any idea why the Category Lines are still LTR?
Thank You
Re: Convert to Right-to-Left
Posted: Sun Dec 28, 2008 2:38 pm
by Mark Baker
maximoox wrote:I noticed that in mysql database "Collation" shows "latin1_swedish_ci" in my phpmyadmin, I am not sure if this has anything to do with my issue or not. Should I change this setting to "utf8_general_ci"? is it risky to modify this setting in MySQL?
Unlikely to be the cause of the problem with categories, but will affect sorting on text fields. I'd recommend changing the to utf-8. I don't thinks it's risky simply changing the collation, but can't guarantee it as I rarely use mySql.
maximoox wrote:
Right now my index.php page is set to output everything from Right to Left... any idea why the Category Lines are still LTR?
It's possible for style classes to override the language settings for the page, and these would apply to individual items on the page. I'd check the styles that you're using for your categories.
Alternatively, if the page is using tables for layout, look for align="left" in the generated HTML
Re: Convert to Right-to-Left
Posted: Sun Dec 28, 2008 7:29 pm
by maximoox
Mark Baker wrote:maximoox wrote:I noticed that in mysql database "Collation" shows "latin1_swedish_ci" in my phpmyadmin, I am not sure if this has anything to do with my issue or not. Should I change this setting to "utf8_general_ci"? is it risky to modify this setting in MySQL?
Unlikely to be the cause of the problem with categories, but will affect sorting on text fields. I'd recommend changing the to utf-8. I don't thinks it's risky simply changing the collation, but can't guarantee it as I rarely use mySql.
maximoox wrote:
Right now my index.php page is set to output everything from Right to Left... any idea why the Category Lines are still LTR?
It's possible for style classes to override the language settings for the page, and these would apply to individual items on the page. I'd check the styles that you're using for your categories.
Alternatively, if the page is using tables for layout, look for align="left" in the generated HTML
Mark,
You are a genius!!! It was the CSS that was overriding my RTL settings. I set the
text-align to "right" and that fixed it.
Thanks a million and happy new year

Re: Convert to Right-to-Left
Posted: Sun Dec 28, 2008 8:19 pm
by Mark Baker
maximoox wrote:You are a genius!!! It was the CSS that was overriding my RTL settings. I set the
text-align to "right" and that fixed it.
Thanks a million and happy new year

Glad to be of help
Been there myself when there was nobody around to help.... and spent days looking straight at the problem, but only seeing what I expected to see, so I missed it completely.
It can be a real pain working on a multilingual site, even when it's a standard western (ISO-8859-1) language. Non-Roman characters cause enough problems to those unfamiliar with languages, and rtl can cause even more problems.