Skip to content

Latest commit

 

History

History
 
 
page_type description products languages extensions urlFragment
sample
Microsoft Teams app localization using Bot and Tab
office-teams
office
office-365
nodejs
contentType createdDate
samples
07/07/2021 01:38:25 PM
officedev-microsoft-teams-samples-app-localization-nodejs

Teams App Localization Node.js

This sample illustrates how to implement Localization for Microsoft Teams apps.

Interaction with app

image

Prerequisites

  • Microsoft Teams is installed and you have an account (not a guest account)
  • To test locally, NodeJS must be installed on your development machine (version 16.14.2 or higher)
  • ngrok or equivalent tunneling solution
  • M365 developer account or access to a Teams account with the appropriate permissions to install an app.

Setup

  1. Register a new application in the Azure Active Directory – App Registrations portal.

  2. Setup for Bot

    • Also, register a bot with Azure Bot Service, following the instructions here.
    • Ensure that you've enabled the Teams Channel
    • While registering the bot, use https://<your_ngrok_url>/api/messages as the messaging endpoint.

    NOTE: When you create your app registration, you will create an App ID and App password - make sure you keep these for later.

  3. Setup NGROK

    • Run ngrok - point to port 3978
      ngrok http -host-header=rewrite 3978
  4. Setup for code

    • Clone the repository
    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  • In a terminal, navigate to samples\app-localization\nodejs

    cd samples/app-localization/nodejs
  • Install modules

    npm install
    
  1. Update the .env configuration for the bot to use the MicrosoftAppId and MicrosoftAppPassword, BaseUrl with application base url. For e.g., your ngrok url. (Note the MicrosoftAppId is the AppId created in step 1 (Setup for Bot), the MicrosoftAppPassword is referred to as the "client secret" in step 1 (Setup for Bot) and you can always create a new client secret anytime.)

  2. Setup Manifest for Teams

  • This step is specific to Teams.
    • Edit the manifest.json contained in the appPackage/ folder to replace with your MicrosoftAppId (that was created in step1.1 and is the same value of MicrosoftAppId in .env file) everywhere you see the place holder string {MicrosoftAppId} (depending on the scenario the Microsoft App Id may occur multiple times in the manifest.json)
    • Edit the manifest.json for validDomains and replace {{domain-name}} with base Url of your domain. E.g. if you are using ngrok it would be https://1234.ngrok.io then your domain-name will be 1234.ngrok.io.
    • Zip up the contents of the appPackage/ folder to create a manifest.zip
    • Upload the manifest.zip to Teams (in the left-bottom Apps view, click "Upload a custom app")
  1. Run your app.
  • Start the bot

    npm start

Interacting with the app in Teams

In Teams, Once the app is successfully installed, you can interact with tab and bot in your preferred language.

To change language in Teams

To change the language in Microsoft Teams, please click your profile picture at the top of the app, then select Settings -> General and go to the Language section. Choose the preferred language and restart to apply the change. This sample supports en-US, fr-CA, hi-IN and es-MX.

Running the sample

  1. Installation: You should see your app installation screen content in selected language. image

  2. Bot: send any message to see localized image

To Add more languages for localization in Teams through Code.

Add Resource files for the respective languages, Check culture fallback behaviour and how to add other cultures refer Globalization and localization Fundamentals.

Further Reading

Localization for Microsoft Teams apps.