page_type | description | products | languages | extensions | urlFragment | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
Microsoft Teams app localization using Bot and Tab |
|
|
|
officedev-microsoft-teams-samples-app-localization-nodejs |
This sample illustrates how to implement Localization for Microsoft Teams apps.
- 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.
-
Register a new application in the Azure Active Directory – App Registrations portal.
-
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.
-
Setup NGROK
- Run ngrok - point to port 3978
ngrok http -host-header=rewrite 3978
-
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
-
Update the
.env
configuration for the bot to use theMicrosoftAppId
andMicrosoftAppPassword
,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.) -
Setup Manifest for Teams
- This step is specific to Teams.
- Edit the
manifest.json
contained in theappPackage/
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 themanifest.json
) - Edit the
manifest.json
forvalidDomains
and replace{{domain-name}}
with base Url of your domain. E.g. if you are using ngrok it would behttps://1234.ngrok.io
then your domain-name will be1234.ngrok.io
. - Zip up the contents of the
appPackage/
folder to create amanifest.zip
- Upload the
manifest.zip
to Teams (in the left-bottom Apps view, click "Upload a custom app")
- Edit the
- Run your app.
-
Start the bot
npm start
In Teams, Once the app is successfully installed, you can interact with tab and bot in your preferred language.
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.
-
Installation: You should see your app installation screen content in selected language.
-
Bot: send any message to see localized image
Add Resource files for the respective languages, Check culture fallback behaviour and how to add other cultures refer Globalization and localization Fundamentals.