OfficeDev/Outlook-Add-in-Commands-Translator

Name: Outlook-Add-in-Commands-Translator

Owner: Office Developer

Description: The Translator add-in uses the commands model for Outlook add-ins to add a button to the ribbon in the new message form.

Created: 2015-08-21 17:55:59.0

Updated: 2017-04-17 19:51:56.0

Pushed: 2018-01-31 20:29:13.0

Homepage: null

Size: 376

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Outlook-Add-in-Commands-Translator

The Translator add-in uses the commands model for Outlook add-ins to add a button to the ribbon in the new message form. The button sends the selected text from the message body to a translator web service to translate from English to Russian.

Prerequsites

In order to run this sample, you will need the following:

Configuring and installing the sample
  1. Download or fork the repository.

  2. Open TranslateHelper.js in a text editor and replace the YOUR API KEY HERE value with your API key for the Yandex Translate API. Save your changes.

  3. Upload the AppCompose, Content, and Images directories to a directory on your web server.

  4. Open TranslateAppManifest.xml in a text editor. Replace all instances of YOUR_WEB_SERVER with the HTTPS URL of the directory where you uploaded the files in the previous step. Save your changes.

  5. Logon to your email account with a browser at either https://outlook.office365.com (for Office 365), or https://www.outlook.com (for Outlook.com). Click on the gear icon in the upper-right corner, then click Manage add-ins.

    The Manage add-ins menu item on https://www.outlook.com

  6. In the add-in list, click the + icon and choose Add from a file.

    The Add from file menu item in the add-in list

  7. Click Browse and browse to the TranslateAppManifest.xml file on your development machine. Click Next.

    The Add add-in from a file dialog

  8. On the confirmation screen, you will see a warning that the add-in is not from the Office Store and hasn't been verified by Microsoft. Click Install.

  9. You should see a success message: You've added an add-in for Outlook. Click OK.

Running the sample
  1. Open Outlook 2016 and connect to the email account where you installed the add-in.

  2. Create a new email. Notice that the add-in has placed a Translate button on the command ribbon.

    The Translate button on a new mail form in Outlook

  3. Type some English text into the body. Select the text, then click Translate.

    The new mail form with English text selected in the body

  4. After a moment, the selected text will be replaced with the Russian translation, and you should see the message Translated successfully in the information bar.

    The text translated into Russian by the add-in

Key components of the sample
How's it all work?

The key part of the sample is the structure of the manifest file. The manifest uses the same version 1.1 schema as any Office add-in's manifest. However, there is a new section of the manifest called VersionOverrides. This section holds all of the information that clients that support add-in commands (currently only Outlook 2016) need to invoke the add-in from a ribbon button. By putting this in a completely separate section, the manifest can also include the original markup to enable the add-in to be loaded in a task pane under the original compose mode add-in model. You can see this in action by loading the add-in in Outlook 2013 or Outlook on the web.

The Translator add-in loaded in Outlook on the web

The Translator add-in loaded in Outlook on the web

Within the VersionOverrides element, there are two child elements, Resources and Hosts. The Resources element contains information about icons, strings, and what HTML file to load for the add-in. The Hosts section specifies how and when the add-in is loaded.

In this sample, there is only one host specified (Outlook):

t xsi:type="MailHost">

Within this element are the configuration specifics for the desktop version of Outlook:

ktopFormFactor>

The URL to the HTML file with all of the JavaScript code for the button is specified in the FunctionFile element (note that it uses the resource ID specified in the Resources element):

ctionFile resid="functionFile" />

The manifest also limits activation to the new message form by setting a single extension point:

ensionPoint xsi:type="MessageComposeCommandSurface">

The properties of the button are specified in the Control element. Most importantly, the button's click event is connected to the translate function in Translator.js inside the Action element:

ion xsi:type="ExecuteFunction">
<FunctionName>translate</FunctionName>
tion>
Questions and comments
Additional resources
Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.