28.12.07

Convert CSS layout to RTL - cssrtl.py

Posted in Projects, Python at 11:28 am by Guy

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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • bodytext
  • Sphinn
  • Facebook
  • Mixx
  • Google

4 Comments »

  1. mathieu said,

    January 4, 2008 at 5:13 pm

    what is RTL?
    http://en.wikipedia.org/wiki/RTL doesn’t help me.

  2. Guy said,

    January 4, 2008 at 6:32 pm

    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.

  3. ben said,

    January 14, 2008 at 1:02 pm

    you have the wrong description under “–help”

  4. Guy said,

    January 15, 2008 at 2:18 pm

    You are right. It got mixed up with my css compactor script, which I also intend to re-release soon.

Leave a Comment