Search code examples
c#blazormicrosoft-teamsteams-toolkitrazor-components

Set Config Tab and Pinned Tabs(website) culture same as Team in a Teams App Package (C# and Blazor)


I have a Teams app package which is built on C# and Blazor created using Microsoft Teams App project template. This website has pages for config tab and after selecting the item in config tab, there are pages which gets pinned in a channel. I used ASP.net code globalization and localization, which works well with Browser language. But instead of browser language, I would like to set the culture same as Teams(Current User Language in Teams). Did anyone worked on this scenario and point me to the right direction.

enter image description here


Solution

  • I removed the code of setting culture and tab from OnAfterRenderAsync and addded in my event. It worked.

    private async void SetSelectedResult(SearchModel selectedItem)
        {
            SetCulture();
            _selectedItem = selectedItem;
            if (_selectedItem != null)
            {
                var settings = new TeamsInstanceSettings
                {
                    SuggestedDisplayName = _selectedItem.Description,
                    EntityId = _selectedItem.ID.ToString(),
                    ContentUrl = $"{NavigationManager.BaseUri}entity/{_selectedItem.ID}/{_selectedItem.EntityType}/{_selectedItem.Division}",
                    WebsiteUrl = $"{NavigationManager.BaseUri}entity/{_selectedItem.ID}/{_selectedItem.EntityType}/{_selectedItem.Division}"
                };
    
                await MicrosoftTeams.InitializeAsync();
                await MicrosoftTeams.RegisterOnSaveHandlerAsync(settings);
            }
        }