Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Make your xulrunner app match the system locale

This article is going to assume a lot of knowledge of xpcom and will be written for someone using python, but the ideas should be adaptable. Also, this may not be the proper way to do this and it may not work for you in all cases. Please update if there are more correct ways to do this.

The first step is to get the code we're about to write to run before any of the locale specific resources are loaded. Democracy does this by creating a command line handler called DemocracyCLH, and then creating a new object of our PyBridge component. The code described lives in the PyBridge component's onStartup method which gets called automatically.

The second step is to figure out the system locale. To be finished later.

Then set the locale preference. The following is python code to set this preference.

from xpcom import components
ps_cls = components.classes["@mozilla.org/preferences-service;1"]
ps = ps_cls.getService(components.interfaces.nsIPrefService)
branch = ps.getBranch("general.useragent.")
branch.setCharPref("locale", lang)

I also set the LANGUAGE environment variable to match the system locale so that python's gettext functionality will work (it pulls straight from LANGUAGE instead of using setlocale):

os.environ["LANGUAGE"] = lang

Document Tags and Contributors

Tags: 
 Contributors to this page: teoli, Kohei, Callek, Clahey
 Last updated by: Kohei,