Convert CSS layout to RTL – cssrtl.py

This is a re-release of a script of mine that helps convert CSS layouts to RTL. I originally released it about a year ago but it was lost when I moved to the new blog. The script, cssrtl.py, utilizes a bunch of regular expressions to translate a given CSS layout to RTL.

Download

You can download the script from here: cssrtl.py.

Usage

Using the script is pretty simple. Just pass the name of the script to cssrtl.py and he will automatically translate it for you.

Example:
python cssrt.py main.css

You can use the -o flag to specify a different output file instead of overwriting the existing file.

If the CSS style for the body tag is missing a direction statement, you should add the -d flag to the list of command line arguments. This will cause the script to add one for you when translating the layout.

See python cssrtl.py --help for more information.

Limitations

While this script is pretty useful as it is, it still isn’t perfect. The major limitation, is that the script doesn’t automatically mirrors images used in the layout. So if your layout contains images you will need to flip them manually (however the script will position them in right place by automatically). Another limitation is that the script doesn’t alway handle correctly scripts with IE hacks, so it always good to keep a backup and manually check the result on IE.

Overall, despite some (minor) limitations, the script is very useful, and it helped me a lot when having to translate CSS layouts to RTL. I’ve successfully used it to translate WordPress, Joomla, Druple and MediaWiki themes with minimal intervention on my side, thus saving a lot of my time. If you find the script useful, it will be nice of your to send a word. Also the script is released under the GPL so if you have any patches/improvements, please send them.

18 thoughts on “Convert CSS layout to RTL – cssrtl.py

  1. RTL is abbreviation for “Right to Left”. This is used in context of the direction of writing. In languages such as Hebrew and Arabic text is written from right to left, opposed to languages such as English that are written from left to right (LTR). Websites whose language is RTL require their layout to have the same direction too.

  2. Hi Guy

    First of all, thanks very much for great effort and excellent script that solve a wide problem with multi languages…

    I have tried your script as following:

    1. I have installed Python 3.0rc1 (r30rc1:66507, Sep 18 2008, 14:47:08) [MSC v.1500 32 bit (Intel)] on win32
    2. I have copied cssrtl.py file and css files to the main path
    3. run dos command line C:\Python30\python cssrtl.py template.css

    but nothing happended!

    please help and advise how to run python and cssrtl.py

  3. Khalid,

    By default cssrtl.py doesn’t generate any output, it rewrites the given css file (so check your teplate.css for changes).

    I’m not sure that cssrtl.py works on Python 3.0. Version 3.0 broke back-compatibility with older version and cssrtl.py wasn’t written at the time ti was available (but if this is the case you should have received some errors from Python when trying to run the script).

  4. Hi guy,

    thanks for this amazing script. it’s working almost perfectly with all the css files i need.

    i’m using Joomla 1.5 and I applied the script on all the template .css files, and the site completly shift to rtl. but…

    only i have the problem with artical name, author , date submition fields are still on the left! and the print/pdf/e-mail icons are still on the right…

    I don’t know where I could find their alignment in the css files. are they somewhere else ? i read the whole css files and studied them but yet i’m clueless.

    is there a .css file i forgot to patch? (i doubt that –cuz i patched everything in the template folder, I didn’t find .css outside the template folder.) or is there another solution ?

  5. Hi Ahmed,

    Maybe the template that you are using doesn’t put all the styling info inside separate CSS files. E.g. maybe it has inline styling for some of the elements. You should check the main php file of the template and see if it has any inline styling in it, and maybe tweak those manually (because the script can’t handle inline styling).

    N.B. It’s been a while since the last time I’ve worked with Joomla (I think back then 1.5 was still the development version), so I might have missed something.

  6. Also, it will be usefull to generate css-fix file, just with fixes. So in future you will need to change original css file for makeing some changes in design.

  7. Making an online version sounds interesting, maybe I’ll create it if I’ll find a way to easily integrate it into the current site (without creating too much load). Anyway it really worth to be considered, thanks for the suggestion.

    Creating a css-fix file, will require much deeper understanding of css rules by the parser than it currently have. So I’m not sure it can be implemented in the current scope of the script, but I’ll add it to the wish list.

  8. תודה רבה. השתמשתי בסקריפט והרוב עבד יפה, בכל זאת הייתי צריך לעשות כמה התאמות לפי עבודה שעשה בעבר מתרגם אחר.

  9. Hi,

    I saw a later post of your concerning the LTR conversion to RTL from SEP 2009. You mentioned the script doesn’t work. Does this script for 2007 works? I am bit confused.
    Thanks for your help
    Tamir

  10. Hello,

    can you tell me please where i have to upload this file?

    Iam using Dolpohin Boonex.

    Best Regards

    Mamo

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.