How to Retrieve User Locale from Microsoft Teams Context in a React Tab App? #12242
Unanswered
sayan-mondal-dcs
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I'm working on a React-based Microsoft Teams tab application where I need to dynamically set the user interface language based on the user's locale settings within Microsoft Teams. I've been able to manage user preferences and locale settings but I want to fetch the locale directly from the Teams context to ensure it aligns with the user's Teams settings.
My Current Setup:
Framework: React with TypeScript
Microsoft Teams SDK: @microsoft/teams-js
Context Management: I'm using React.createContext to manage the theme and other settings.
Localization: Currently handling localization using react-i18next and managing supported languages like en-us, hin-in, and it-it.
What I Want to Achieve:
I want to:
Retrieve the user's locale directly from the Teams context.
Use this locale to adjust the UI language dynamically.
Possibly update the global context I'm using (TeamsFxContext) to include this locale for consistent use across the application.
What I've Tried So Far:
I’ve attempted to use the microsoftTeams.getContext() method, but I'm looking for best practices or examples on how to integrate this properly within my React components, especially in the context of a larger application.
Sample Code:
Here’s a simplified version of my current approach:
References:
How to get MS Teams (Desktop App) language programmatically?](https://stackoverflow.com/questions/71967840/how-to-get-ms-teams-desktop-app-language-programmatically)
How to set time zone in microsoft teams
Questions:
I'm not able to get the locale from Microsoft Teams React tab app?
Are there any pitfalls or improvements I should consider when using microsoftTeams.getContext() for this purpose?
How can I ensure that the locale is correctly passed down through my context and available throughout the app?
Additional Context:
I’m also using react-i18next for translation management.
The application is integrated with Microsoft Teams via Teams FX, and I'm also leveraging the Microsoft Graph API.
Any guidance would be greatly appreciated!
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions