308
edits
No edit summary |
|||
Line 19: | Line 19: | ||
In addition to the Parser 2 API changes listed above, the main change to be made is to wrap any localizable strings in your <code>preview</code> and <code>execute</code> methods with the function <code>_()</code>. This <code>_()</code> command (familiar to anyone with prior experience with [http://en.wikipedia.org/wiki/Gettext Gettext]) handles the localization by finding the appropriate matching localized string on preview or execution. | In addition to the Parser 2 API changes listed above, the main change to be made is to wrap any localizable strings in your <code>preview</code> and <code>execute</code> methods with the function <code>_()</code>. This <code>_()</code> command (familiar to anyone with prior experience with [http://en.wikipedia.org/wiki/Gettext Gettext]) handles the localization by finding the appropriate matching localized string on preview or execution. | ||
displayMessage(_('No results were found.')); | |||
In the case above, <code>_()</code> will then take care of finding appropriate localizations of the string "No results were found" for your command and, if available, display that string instead. | |||
The <code>_()</code> function also handles [http://code.google.com/p/trimpath/wiki/JavaScriptTemplates <code>renderTemplate</code>ing] if you also give it an object with replacement variables. For examples, you can write the following: | |||
displayMessage(_("${number} results found.", {number: numOfResults})) | |||
By default, this will display, for example, "3 results found." if <code>numOfResults == 3</code> and something like "Il y a 3 résultats" given a French localization of "Il y a ${number} résultats". This templating can also be used to handle pluralization—please refer to [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|Making Commands Localizable]] for more information. | |||
There is no need to wrap any properties of the commands (<code>names</code>, <code>help</code>, <code>author</code>, etc.) in <code>_()</code>, nor do you need to wrap string previews in <code>_()</code>, in order for the command to be localizable. These direct properties of the command are automatically localizable as long as they are set in the original command. | |||
More tips on making strings localizable can be found in [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|Making Commands Localizable]]. | More tips on making strings localizable can be found in [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|Making Commands Localizable]]. |
edits