Entra / Microsoft 365 · Compliance & audit
Assign local language strings to sensitivity labels
A script showing how to set local language values for sensitivity labels using the Microsoft Translator service.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnlineConnect-IPPSSession
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
Function Translate-String {[cmdletbinding()]Param([string]$InputString,[string]$LanguageCode )$textJson = @{"Text" = $InputString} | ConvertTo-Json$Body = "[$textJson]"$Uri = "$($global:BaseUri)&to=$($LanguageCode)&textType=html"$Status = Invoke-RestMethod -Method Post -Uri $uri -Headers $global:headers -Body $Body$Translation = $Status[0].translations[0].textReturn $Translation}$TranslatorKey = "20be21011ba2747a0996c4134492bfc97" # You need a valid key for Microsoft Translator$global:BaseUri = "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0"$global:Headers = @{'Ocp-Apim-Subscription-Key' = $translatorKey'Ocp-Apim-Subscription-Region' = 'northeurope' # added (change if needed)'Content-type' = 'application/json; charset=utf-8'}# Make sure that we're connected to Exchange Online and the compliance endopointConnect-ExchangeOnlineConnect-IPPSSession# Declare the set of languages that we're going to translate for$Languages = @("fr-fr","it-it","de-de", "ar-ar")# Find set of labels that support LLV stringsWrite-Host "Finding sensitivity labels to process..."[array]$FileLabels = Get-Label | Where-Object {$_.ContentType -Like "*File*"}ForEach ($Label in $FileLabels) {$FrenchDisplayName = $Null; $GermanDisplayName = $Null; $ItalianDisplayName = $Null; $ArabicDisplayName = $Null$FrenchTooltip = $Null; $GermanToolTip = $Null; $FrenchToolTip = $Null; $ArabicToolTip = $NullWrite-Host ("Setting language values for the {0} label" -f $Label.displayname)[string]$FrenchDisplayName = Translate-String -InputString $Label.DisplayName -LanguageCode "fr"[string]$FrenchTooltip = Translate-String -InputString $Label.ToolTip -LanguageCode "fr"[string]$ItalianDisplayName = Translate-String -InputString $Label.DisplayName -LanguageCode "it"[string]$ItalianTooltip = Translate-String -InputString $Label.ToolTip -LanguageCode "it"[string]$GermanDisplayName = Translate-String -InputString $Label.DisplayName -LanguageCode "de"[string]$GermanTooltip = Translate-String -InputString $Label.ToolTip -LanguageCode "de"[string]$ArabicDisplayName = Translate-String -InputString $Label.DisplayName -LanguageCode "ar"[string]$ArabicTooltip = Translate-String -InputString $Label.ToolTip -LanguageCode "ar"$DisplayNameLocaleSettings = [PSCustomObject]@{LocaleKey='DisplayName';Settings=@(@{key=$Languages[0];Value=$FrenchDisplayName;}@{key=$Languages[1];Value=$ItalianDisplayName;}@{key=$Languages[2];Value=$GermanDisplayName;}@{key=$Languages[3];Value=$ArabicDisplayName;})}$TooltipLocaleSettings = [PSCustomObject]@{LocaleKey='Tooltip';Settings=@(@{key=$Languages[0];Value=$FrenchToolTip;}@{key=$Languages[1];Value=$ItalianToolTip;}@{key=$Languages[2];Value=$GermanToolTip;}@{key=$Languages[3];Value=$ArabicTooltip;})}Set-Label -Identity $Label.ImmutableId -LocaleSettings (ConvertTo-Json $DisplayNameLocaleSettings -Depth 3 -Compress),(ConvertTo-Json $TooltipLocaleSettings -Depth 3 -Compress)}rite-Host "All labels updated with local language values..."
Attribution
Author
Office365itpros