How to localize the strings of a Firefox extension  bandiera francese bandiera italiana german flag spanish flag

Sometimes the extensions we translate have  no locale folder, so we have to fumble here and there looking for strings...
But we can all the same create a "locale" folder which will be useful to translators and to spread the extension worldwide...
Let us take the extension anidisable by Harry Patsis as an example
 1 

Open anidisable.xpi 
ouverture xpi
with Izarc or 7-Zip ...
 2

The chrome folder includes another zipped file that we open too...
ouverture du chrome
 3 

Bad luck ! There is no locale folder in ...
ouverture jar
 4

Well then...
we just create one !
créer un dossier locale
right-click on "New folder" then rename
 5

And  we insert the following contents :
one en-US  subfolder (supposing we are making an english locale of course) with these two files inside :
- anidisable.dtd
- contents.rdf
contenu locale
right-click on "New text file" then rename

 6

Now let us have a look in the file content/anidisable.xul, we are discovering strings to localize. These are words that will be displayed  to the final user.
 Notice : we shall leave the word "Anidisable"  untranslated, because it is recommended to leave the extension name as it is.
Open with a text-editor such as Pspad or Jedit

chaînes à localiser

... Which text strings can we localize ? Click here for tips

 7

This is the important step !
Now we are about to replace messages between brackets by :
  followed by a sufficiently explicit variable name, ending with a  ; 
chaînes localisées

 8

Now let us go in the en-US locale, in the anidisable.dtd  file.

With much care for the syntax (see example on the right), here we put variables names and their english "equivalent" .
transfert dans la locale

 9

Let's go back to the anidisable.xul file, and right on the second line we add this line  that tells the extension the precise address where to find localized elements...
ligne de doctype

 10

We make the same operation again - variables substitutions- for the strings in the file :
 anidisablesettings.xul
following the steps
 7   8   9
encoder en utf8
...and do not forget UTF-8 encoding !

 11

See below what is to write in the locale/ contents.rdf file.
It is the same for every extension, except of course for the extension name itself.
To spare you the pain of writing down the whole thing, you can just copy/paste from this plain text file....
contents
 12

Another important point : if we want the extension to take our locale folders into account, you must indicate the address right from the beginning and add this yellow line in  the
 install.rdf file.
ligne de locale
It is done ! All you've got to do now is :

  • re-zip and get a new .xpi
  • test how your extension works
  • send the author your  proposed localized version.
* If you want to train and compare, see  anidisable extension original version localized version
In this last version, the initial description is localized too : see how to do it  here .
And if you wish to localize strings included in a javascript (*.js) file, it is there.


Which text strings can we localize ?
Those which follow these tags :
  • "label"
  • "title"
  • "tooltip" 
  • "value" 
  • "accesskey"
mon avatar

Document fait avec Nvu