Firebug 1.6 is slowly approaching a beta phase and one of the last features we have put in a18 is related to localization. Note that Firebug is currently using more than 500 strings in its UI and these are translated into approximately 40 languages.
Even if we are always planning a string freeze in order to give Firebug translators some time to process new strings, we often end up with a few unfinished locales.
From these reasons we decided to do following:
- Don't use DTD entities
- Use en-US as fallback locale (for missing strings)
And as a bonus (!), these changes allowed to fix Issue 907: Option to use en-US locale instead of fx default locale
So, all you need to do to always use Firebug with en-US locale, is to set
preference to true. There is no UI in Firebug for this option and so, you need to use about:config (see all prefs in Firebug).
Do you think this should be available in Firebug->Options menu?
Read further, if you interested how we implemented that.
Don't use DTD entities
The trick in this this task was to move all strings from firebug.dtd file into firebug.properties file and do it for all existing translations (while encoding of all files is preserved). I used sed and the following script (thanks to Hector for his help!).
ls */firebug.dtd | sed "s/\(.*\).dtd/sed 's\/<\!ENTITY \\\(.*\\\) \"\\\(.*\\\)\">\/\\\1=\\\2\/g' \1.dtd >> \1.properties/g" | sh
The script transforms strings from */firebug.dtd files from this format:
<!ENTITY firebug.Help "Help">
into firebug.properties file format:
...and appends all at the end of the */firebug.properties file (encodings preserved). If it's executed in the locale directory of your extension, it's done for all locales at once.
I am not a sed expert neither a shell expert, so take this script as it is and in case of questions use FAQ.
Use en-US as fallback locale
The trick in this case was to get the default (en-US) locale file even though Firefox uses different locale. You can quickly find out that URL of the locale is always the same and resolved dynamically using the default Firefox locale.
So for example:
...is using firebug.properties file from locale/en-US directory if Firefox is set to use en-US locale. In case of e.g. da-DK, the file is loaded from locale/da-DK directory.
Also, you can't use just:
chrome://firebug/locale/en-US/firebug.properties // WRONG
This wouldn't be resolved to a file.
The correct way is to transform the chrome URL into file URL and replace the locale dir name with en-US (thanks John J. Barton for the idea!).
Here is an example how to do it.
var cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
var sbs = Cc["@mozilla.org/intl/stringbundle;1"]
var uri = ioService.newURI(
"chrome://firebug/locale/firebug.properties", "UTF-8", null);
var fileURI = cr.convertChromeURL(uri).spec;
var parts = fileURI.split("/");
parts[parts.length - 2] = "en-US";
var bundle = sbs.createBundle(parts.join("/"));
Now bundle implements nsIStringBundle and so, you can load strings from it using e.g. GetStringFromID().