Neil’s Place

July 30, 2009

Removing chromedir for right-to-left UI

Filed under: Mozilla — enndeakin @ 9:20 am

I just checked in a patch which eliminates uses of the chromedir attribute in Firefox. This was previously a way in which right-to-left user interfaces were handled. Essentially, various elements and parts of the UI had a chromedir attribute set which retrieved either the value ‘ltr’ or ‘rtl’ from a localized DTD file. Stylesheets could then be modified based on the value. Since it was effectively a global state, it wasn’t very flexible, and required the use of hundreds of extra attributes. This was a very ineffective way to handle this.

Instead, I have replaced this with a pseudoclass:

:-moz-locale-dir(ltr) { ... }
:-moz-locale-dir(rtl) { ... }

The former matches when the user interface is using a locale displayed left-to-right, and the latter matches when the user interface is in a locale displayed right-to-left.

Locales which are right-to-left are controlled by a preference of the form ‘intl.uidirection.<locale>’, where <locale> is a language code such as ‘en’ or ‘ar-QA’. The value of the preference should be either ‘ltr’ or ‘rtl’.

This means that someone can transform their user interface into a right-to-left mode simply by changing the preference. The user interface will  redisplay immediately without having to restart. For instance, I might set ‘intl.uidirection.en’ to ‘rtl’. This means that the ForceRTL extension is no longer needed for this purpose.

Those creating localizations in left-to-right languages, or localizations in right-to-left localizations of Arabic, Farsi or Herbew need do nothing special. The preferences are set accordingly already (even in browsers using other locales). Extra style rules in intl.css for Firefox are no longer needed as these are already handled automatically

Also, the direction can be different for each window. For instance an Ararbic browser user can install an English-only extension and have a window with English-only UI displayed left-to-right. Naturally, this is only window specific, so wouldn’t apply to overlaid UI.

An author can override the UI direction for a window by setting the localedir attribute on a <window> or <dialog>, and other toplevel elements.

1 Comment »

  1. We have the following webpage to describe how to make themes RTL-compatible.

    We should update it to reflect the changes and tell extension authors how to make their extensions compatible in RTL more, but keep the current content as-is in order to support current versions of Firefox and Thunderbird.

    Comment by Tomer — July 30, 2009 @ 1:08 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.