GithubHelp home page GithubHelp logo

user135711 / office-add-in-translateaspnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from officedev/office-add-in-translateaspnet

0.0 1.0 0.0 11.23 MB

The sample translates the currently selected text in a Word or Excel file into the specified language using the Microsoft Translator service

License: Other

HTML 8.47% CSS 38.98% JavaScript 50.77% ASP 0.01% C# 0.47% PowerShell 1.32%

office-add-in-translateaspnet's Introduction

Office Add-in - Use Bing Translator and ASP.NET in an add-in

Table of contents

##Summary

This sample translates the currently selected text in a Word or Excel file into the specified language using the Microsoft Translator service.

This add-in gets the current selection from the Office document and then sends it to the Bing Translator service for a translation into the specified language.

Screenshot of running sample

##Prerequisites This sample requires the following:

  • Visual Studio 2013 with Update 5 or Visual Studio 2015.
  • A subscription to the Microsoft Translator API on Azure Marketplace.
  • Word 2013 or later
  • Internet Explorer 9 or later, which must be installed but doesn't have to be the default browser. To support Office Add-ins, the Office client that acts as host uses browser components that are part of Internet Explorer 9 or later.
  • One of the following as the default browser: Internet Explorer 9, Safari 5.0.6, Firefox 5, Chrome 13, or a later version of one of these browsers.
  • Familiarity with JavaScript programming and web services.

##Key components

  • CodeSample_TranslateASPNET project
  • CodeSample_TranslateASPNETWeb project
    • Home.html. It contains the HTML control for the add-in's user interface.
    • Home.js. It contains the event handler for the Office.initialize event of the add-in, handles the button click event for the add-in's button, calls the ASP.NET web service, parses the response, and updates the UI with the output.
    • Translate.asmx.cs. It defines the web service that handles the HTTP request from the add-in, stores the developer's client ID and client secret, and sends translation requests to the Microsoft Translator service.
    • AdminAccess.cs. It contains the AdmAuthentication and AdmAccess classes that update the access token for the server to communicate with the Microsoft Translator service.

##Description of the code

The sample demonstrates two specific techniques: how to add an ASP.NET web service to an Office Add-in and how to use the Microsoft Translator service. The ASP.NET web service in the solution stores the clientID and clientSecret parameters that the Microsoft Translator service requires to obtain an access token (which, in turn, is required for calling the Microsoft Translator service for a translation).

The Translate.asmx file in the code sample handles HTTP requests coming from the add-in, sends the translation request to the Microsoft Translator service, and then returns the results to the add-in. The AdminAccess.cs file in the App_Code folder handles the access tokens returned from the Microsoft Translator service.

##Build and debug

  1. To configure the Translator app, get a client ID and client secret from the Azure DataMarket. For more information, see Obtaining an Access Token.
  2. Replace the default values for clientID and clientSecret in the Translate.asmx.cs file with your own values.
  3. Open the CodeSample_TranslateASPNET.sln file in Visual Studio.
  4. Set the Start Document property of the CodeSample_TranslateASPNETWeb project to either New Excel Workbook or New Word Document.
  5. Press F5 to build and deploy the sample add-in Excel or Word.
  6. On the Home ribbon, click Open in the Translator group.
  7. Type text in a cell of the new Excel workbook or in the new Word document. Select the text.
  8. Select your From and To languages, and then press the Translate the selected word button.

Troubleshooting

  • If the Translator group does not appear on the Home ribbon, choose Insert > My Add-ins > CodeSample_TranslateASPNET.
  • If the app raises a "400: Bad request" exception, ensure that you have replaced the constants in the Translate.asmx.cs file with your own client ID and client secret values. Also, ensure that the HTTP request to the Microsoft Translator service has an Authorization header with a value set to Bearer, a space, and a current access token for the Microsoft Translator service.

Questions and comments

  • If you have any trouble running this sample, please log an issue.
  • Questions about Office Add-ins 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.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

office-add-in-translateaspnet's People

Contributors

davidchesnut avatar jamescro avatar o365devx avatar rick-kirkham avatar tslappy avatar

Watchers

 avatar

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.