How to develop addons for rtl locales by bahramm, Translator for Persian (fa-IR) Persian is a right to left direction language, it is not enough to just fill the locale files, the user interface rendering is different.
Normally an English html page is rendered left to right as default, because the default values for the universal attributes "dir" and "text-align" are left to right. If there is a right to left text or image, then you should align it to right, example :
<div style="direction:rtl; text-align: right;"> a Persian text </div> you could set this attributes globally, but if you are sure that there will be no English text in between. If you have English text mixed with the Persian text, then you should align the English parts to left explicitly, example:
<body style="direction: rtl; text-align: right;"> some Persian texts <div style="direction: ltr; text-align: left;">
some English texts </div> again Persian texts!!
</body>
The question is how to know the current user locale, or better how to know its direction? the answer is in the global.dtd:
chrome://global/locale/global.dtd
you could read the following entity in the initialization part of your extension, example
MyOverlay.js
function getDirection() { var myLocalBundleService = Components.classes ["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService); var myLocalStrings = myLocalBundleService .createBundle("chrome://global/locale/global.dtd");Here there is something wrong, since you cannot call create a bundle from a chrome path inside a js codereturn myLocalStrings.GetStringFromName("locale.dir"); }
For English locale en-US, getDirection will return "ltr", for Persian locale fa-IR, it returns "rtl".
All you need to do is to define two classes like below, and use them for your texts:
style.css
.r2l {direction: rtl; text-align: right; } .l2r {
direction: ltr; text-align: left; } --------- Learn more here http://www.i18nguy.com/temp/rtl.html
|