|
|
Songbird Wiki > Developer Center > Articles > Add-on Locale Support
Add-on Locale SupportFrom $1Table of contentsWhy your extension needs locale supportIn case you haven't noticed, Songbird is not just available in English - it's available for an ever-increasing number of languages and localizations. Imagine international users' reactions to seeing a fully localized application only to have random English strings from your add-on mingling with their native language interface! If you are new to extension creation, you're probably wondering how you can possibly support every language with your add-on. Thankfully, the Gecko engine provides some magic: Songbird will automatically detect what language your add-on should display based on the user's application settings. If the target language is not provided by your add-on, then it will fall back to English (en-US) as the default. You can structure your add-on such that it will be considerably easier for other translation and localisation experts to localise for you. All you simply have to do is build in the locale support. A simple solution for a simple user interfaceIt's often the case that the number of strings to be used in your extension is just a list of simple common words, such as: Home Edit Cancel Title Artist Tags Download Please wait... Or they may be longer strings that already appear in elsewhere in Songbird interfaces such as: Copy music files with the following extensions to the device: Check for Updates... Select destination folder: In that case, the simplest solution is to extract the localizable entities from the Songbird application itself. See in this file for a list of all the strings you can extract and notice the mapping they have to entity names in this file.
As you can see, this is the address of a locale file inside the Songbird chrome, and it will automatically switch to the needed locale language of the Songbird user.
Important note : the entity name in the XUL must be in the following format: &entity.name;
If you have:
<toolbarbutton id="overlayToolbar"
class="toolbarbutton-1 chromeclass-toolbar-additional"
label="Play/Pause"
oncommand="onPlayPauseOverlayToolbar();"/>
</toolbarpalette>
You can see that the Play/Pause string is already in the application interface as:
So you can go ahead and use this entity in your XUL:
<toolbarbutton id="overlayToolbar"
class="toolbarbutton-1 chromeclass-toolbar-additional"
label="&menu.control.play;"
oncommand="onPlayPauseOverlayToolbar();"/>
</toolbarpalette>
Create a locale structureOf course, generally, your add-on will have more strings than the Songbird application can provide by default, so the above solution will be insufficient for these strings. For this case, you need to create a full dedicated locale structure: All you have to do is to add a locale folder in the chrome at the same level as content and skin. Inside the locale folder, create one subfolder per supported language. Consolidate user interface strings into one locationTo make it easier to localise, we want to take those embedded strings out of the XUL and put them into a central file in the locale subfolder we just created. So we need to substitute in an entity for these embedded strings. Spot strings in the XUL filesHere is a sample of code of what a XUL file looks like with embedded user interface strings (green highlighted)
Create entities- Remember from above, the syntax for an entity in a XUL file is: &entity.name; Each unique string must have a unique entity name. So in general, non-repeating strings should be uniquely named. If you are using the same literal string in multiple places, then reusing the entity name is fine. Here is the same XUL code, but with the embedded English strings represented by entities. Move the strings to the locale/*.dtd fileNow we need to move the embedded strings we just took out and place them into a locale-specific .dtd file. The syntax for an entity line in a .dtd file is:
So for our example, our strings will move into a .dtd file that looks like: Very important note: The encoding for .dtd files MUST be UTF-8 Add a doctype lineIn order to get the add-on to look for locale strings in our locale subfolder, we have to ensure we set the correct doctype at the top of every XUL file. Example:
As you can see, we point it to the path to the locale file related to this specific XUL file (good practice is to choose same filename for both, e.g about.xul --> about.dtd ) The doctype "definition" depends of the kind of XUL file you have. It can be: overlay - dialog - window Properties for .js filesOf course, add-ons are more than just XUL. You may have some strings embedded in your .js files, and if they will be displayed to your user at any point, then they should be localised too. There are two methods to localize these kinds of strings, both based on the principle that there is a list of strings (otherwise known as a stringbundle) in the locale folder, which the Javascript file will fetch its variables from. Create a stringbundle in the xulHere is the kind of strings we want to localize in our Javascript :
You can insert these three lines in the XUL file:
This creates a stringbundle with an id and points it to the path to the locale's .properties file. What this means is that in the Javascript .js file, you can now use:
and place the following in your locale/*.properties file:
Create a stringbundle at the top of the .jsAnother solution is to not modify your .XUL file and instead place the stringbundle at the top of the .js file.
Register the locales in the chrome manifestOne more mandatory step is to register your locales in your add-on's chrome manifest (chrome.manifest file), otherwise the add-on will not even know the locales exist! In your chrome.manifest file, you already have lines to provide paths for content, skin, and overlay: content songbird-mashtape chrome/content/ skin songbird-mashtape classic/1.0 chrome/skin/ overlay windowtype:Songbird:Library chrome://songbird-mashtape/content/overlayLibrary.xul All you have to do is add the path for all the included locale the same way (don't forget the trailing slash!)
A handy alternative: The Externalize extensionIf you feel all the above steps are too long and annoying, or you're just lazy - learn how to use the magical "Externalize" extension (originally written for Firefox by Davide Ficano). It will make the whole process semi-automatic, thus saving you precious time. This extension is now available for Songbird here You can have a look at this 10-step HOWTO guide on the BabelWiki page Tutorials/ReferencesOther BabelZilla tutorials that might be helpful to you: How to localize the initial description How to resize a xul pref dialog according to every language How to localize strings from a help.html file of an extension How to translate the accesskeys for an extension Want more languages and localizations for your add-on? - You are welcome to hop on BabelZilla and submit your extension. BabelZilla is a community of volunteer translators from all over the world, dedicated to the translation of extensions for Moz family apps.
Tags:
|
Powered by MindTouch Deki Wiki |