1,007
edits
| Line 87: | Line 87: | ||
There are a number of other useful functions in the <code>CmdUtils</code> namespace. We don't yet have full documentation for these commands, but you'll get a sense of the useful ones in this tutorial. For more detailed information, take a look at [http://hg.toolness.com/ubiquity-firefox/file/9a6c9935da9f/ubiquity/chrome/content/cmdutils.js cmdutils.js]. | There are a number of other useful functions in the <code>CmdUtils</code> namespace. We don't yet have full documentation for these commands, but you'll get a sense of the useful ones in this tutorial. For more detailed information, take a look at [http://hg.toolness.com/ubiquity-firefox/file/9a6c9935da9f/ubiquity/chrome/content/cmdutils.js cmdutils.js]. | ||
=== Making sure your command is localizable === | |||
Ubiquity now supports multiple languages. That means that hopefully someday someone will be translating your commands to the other languages that Ubiquity supports. Making your command localizable is easy, and a good habit to get into! You just have to wrap any strings that appear in your <code>preview()</code> and <code>execute()</code> methods with: | |||
_() | |||
This may look odd, but what it does is quite important: it makes your strings appear in the template files that localizers will be using. So let's make our "Hello world!" command localizable: | |||
<pre> | |||
CmdUtils.CreateCommand({ | |||
names: ["say hello"], | |||
execute: function() { | |||
displayMessage( _("Hello, World!") ); | |||
} | |||
}); | |||
</pre> | |||
This makes it so that when a localization template is generated from your command feed, "Hello, World!" will be listed among the strings to be translated. | |||
Note that we don't need to wrap the names, or other strings that appear in the command metadata -- these are automatically wrapped for us. We only need to wrap strings that appear inside the functions. | |||
== Adding a Preview == | == Adding a Preview == | ||
| Line 103: | Line 124: | ||
preview: "Displays a <i>salutary</i> greeting to the planet.", | preview: "Displays a <i>salutary</i> greeting to the planet.", | ||
execute: function() { | execute: function() { | ||
displayMessage( "Hello, World!" ); | displayMessage( _("Hello, World!") ); | ||
} | } | ||
}) | }) | ||
edits