@@bidi_dir issue

25 views
Skip to first unread message

Chrome786

unread,
Jan 14, 2011, 3:02:07 AM1/14/11
to Chromium-extensions
Hi,
 
I am trying to find the layout of the chrome browser in my extension e.g. English or Arabic version Chrome has been installed on a machine?
 
I want to change the layout of my extension LTR or RTL depending upon the Chrome layout.
 
Fot initial testing purpose, I wrote following code but seems like it doesn't work.
 
chrome.browserAction.onClicked.addListener(function(tab) {
            if(chrome.i18n.getMessage("@@bidi_dir") == "ltr")
                alert("ltr");
            else if(chrome.i18n.getMessage("@@bidi_dir") == "rtl")
                alert("rtl");
        });
 
I don't see any alert when I click on the browser action button.
 
Thanks,
-Syed

Mohamed Mansour

unread,
Jan 14, 2011, 2:42:57 PM1/14/11
to Chrome786, Chromium-extensions
Hi Chrome0786,

That code snippet seems right, but here are some comments:
  1. Make sure you place that code in your background page.
  2. Make sure you don't define a popup.html in your manifest file, because you cannot use onClick and popup at the same time.

Kind regards,
Mohamed Mansour



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

PhistucK

unread,
Jan 14, 2011, 2:47:49 PM1/14/11
to Mohamed Mansour, Chrome786, Chromium-extensions
I went to some extension that has a background page and executed that code within the console of the background page - it returns an empty string.

PhistucK

Chrome786

unread,
Jan 14, 2011, 2:58:57 PM1/14/11
to PhistucK, Mohamed Mansour, Chromium-extensions
@Mohamed: Yes, Its in background.html and there is no popup.html in manifest file.
@PhistucK: Yes, it returns an empty string.
 
is there any other way to get the LTR or RTL layout of the browser?
 
Thanks,
-Syed

Abraham Williams

unread,
Jan 14, 2011, 2:56:48 PM1/14/11
to PhistucK, Mohamed Mansour, Chrome786, Chromium-extensions
chrome.i18n.getMessage("@@bidi_dir") only seems to be available if you have "default_locale" set in your manifest.

Abraham
-------------
Abraham Williams | Hacker Advocate | abrah.am
@abraham | github.com/abraham | blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.

Mohamed Mansour

unread,
Jan 14, 2011, 3:02:38 PM1/14/11
to PhistucK, Chrome786, Chromium-extensions
Weird, I did the same thing but within a Popup page Inspector (when I replied) and it returned the correct string. 

Must be a bug for background pages then because I just did it from the background page and it was indeed an empty string. I have filled the following bug:

Thank you, star that issue if you would like to get updates!

Another way to do LTR and RTL layout, is directly within the CSS:

body {
 direction: __MSG_@@bidi_dir__;
}

The bidi messages work on other extension pages like popup, and custom ones. So you can still use that approach.

Kind regards,
Mohamed Mansour

Mohamed Mansour

unread,
Jan 14, 2011, 3:31:08 PM1/14/11
to Abraham Williams, PhistucK, Chrome786, Chromium-extensions
Abraham is correct. The docs even specify:

Important: If an extension has a _locales directory, the manifest must define "default_locale".

But it worth noting in the documentation side. Maybe we will add more docs regarding the usage of those predefined messages.

Kind regards,
Mohamed Mansour

Chrome786

unread,
Jan 14, 2011, 4:59:44 PM1/14/11
to Mohamed Mansour, Abraham Williams, PhistucK, Chromium-extensions
Thank you!!!
 
But my extension doesn't have a "_locales" directory right now and I want to find out the layout LTR/RTL?
if I add "default_locale": "en" in my extesnion, I still get empty string.
 
Thanks again!
Reply all
Reply to author
Forward
0 new messages