Giter Site home page Giter Site logo

skyms / outlook-add-in-commands-translator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from officedev/outlook-add-in-commands-translator

0.0 2.0 0.0 520 KB

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

License: MIT License

CSS 26.00% JavaScript 50.57% HTML 23.43%

outlook-add-in-commands-translator's Introduction

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:

  • A web server to host the sample files. The server must be able to accept SSL-protected requests (https) and have a valid SSL certificate.
  • An Office 365 email account or an Outlook.com email account.
  • An API key for the Yandex Translate API.
  • Outlook 2016, which is part of the Office 2016 Preview.

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

  1. 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

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

The Add add-in from a file dialog

  1. 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.
  2. 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

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

The new mail form with English text selected in the body

  1. 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):

<Host xsi:type="MailHost">

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

<DesktopFormFactor>

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):

<FunctionFile resid="functionFile" />

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

<ExtensionPoint 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:

<Action xsi:type="ExecuteFunction">
    <FunctionName>translate</FunctionName>
</Action>

Questions and comments

  • If you have any trouble running this sample, please log an issue.
  • Questions about Office Add-in development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with office-addins.

Additional resources

Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.