August 8, 2023

How to get Teams Client Language Setting

I explain in this post a way to get the Teams Client Language programmatically - for both Teams Classic and Teams New clients.

Motivation

A lot of automation based on UIAutomation for example rely on the name of the UI elements. These names are of course language specific.

For Teams automation like in the Teams PowerTools, a way to detect the language setting used in the Teams client would be much appreciated. (Else, one would have to add an other setting in the PowerTools for it.)

How to get Teams Client Language Setting

I have first looked at the entries in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Office\Teams
but could not found anything.

Then I looked under
%AppData%\Microsoft\Teams\

There is file:
 settings.json
but it does not contain this information.
There is another file:
desktop-config.json

It seems to contain the information in the currentWebLanguage property (the name looks still a bit weird to me, why Web in it?)

"currentWebLanguage":"en-US"

For the Teams New Client the setting file is located under %LOCALAPPDATA%\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\app_settings.json in the 'language' property.

AutoHotkey Implementation

Below is the implementation how to get this information in AutoHotkey:

Teams_GetLang() {
; return desktop client language
; sLang := Teams_GetLang()

; For Classic Teams:
;   Read value in %AppData%\Microsoft\Teams\desktop-config.json -> currentWebLanguage
; For New Teams:
;           %LOCALAPPDATA%\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\app_settings.json -> language
; e.g. "en-us"
static Lang
If !(Lang = "")
    return Lang

If Teams_IsNew() {
    EnvGet, LOCALAPPDATA, LOCALAPPDATA
    JsonFile := LOCALAPPDATA . "\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\app_settings.json"
    FileRead, Json, %JsonFile%
    If ErrorLevel {
        TrayTip, Error, Reading file %JsonFile%!,,3
        return
    }
    oJson := Jxon_Load(Json)
    Lang := oJson["language"]
    If (Lang="")
        {

        }
    return Lang
} Else {
    JsonFile := A_AppData . "\Microsoft\Teams\desktop-config.json"
    FileRead, Json, %JsonFile%
    If ErrorLevel {
        TrayTip, Error, Reading file %JsonFile%!,,3
        return
    }
    oJson := Jxon_Load(Json)
    Lang := oJson["currentWebLanguage"]
    return Lang
}

} ; eofun

Note the use of the static variable to keep the setting memorized and optimize the runtime.
(If you change the language setting in the Teams client you will have to rerun the script to update.)

This is implemented in the Teams Library Lib/Teams.ahk -> Teams_GetLang function

See also

How to extend Teams PowerTools to support non English Client setting

No comments:

Post a Comment