How may I find out the target language of a report when saving it?

Hi everyone!

I'm saving a report as shown below:


AutomaticTask analyzeTask = project.RunAutomaticTask( targetFiles.GetIds(),AutomaticTaskTemplateIds.AnalyzeFiles);

  foreach (TaskReport report in analyzeTask.Reports)
{ project.SaveTaskReportAs (report.Id, Path.Combine("C:\", report.Id), ReportFormat.Excel);


Where "project" is a FileBasedProject containing multiple target languages.


How may I find out the target language the each saved report is in? 

I hope to save the report with target language as file name.

Thanks for reading!

2 Replies Latest Replies: 4 Jul 2018 7:53 PM by Evzen Polenka
  • Tristen Tan
    How may I find out the target language the each saved report is in?

    As usually with the Studio API, you can't (easily) and need to use some crazy workaround :-\

    In my STraSAK Powershell script I'm saving the report to temporary XML (since I'm not aware of a sensible way to access the original XML report) and parsing the language from the LCID (and since LCID is not unique, it needs to be combined with further parsing of the English language name).

    How easier it would be if the API architect would expose such fundamental stuff as properties of the report object...

    This code is definitely not bulletproof since it will apparently fail big time if it's run on a system whose .NET Framework does not support the locale of the report (i.e. the locale English name is not present in the list of supported locales)...

    ForEach ($T in $Tasks.SubTasks) {
        ForEach ($R in $T.Reports) {
            if ($R.TaskTemplateId -eq [string] [Sdl.ProjectAutomation.Core.AutomaticTaskTemplateIds]::AnalyzeFiles) {
                # Save report to temporary file
                $TempFile = [System.IO.Path]::GetTempFileName()
                $Project.SaveTaskReportAs($R.Id, $TempFile, [Sdl.ProjectAutomation.Core.ReportFormat]::Xml)
                # Read the LCID information from temporarily saved report and use it to create CultureInfo, which is then used to get the culture code
                [xml] $TempReport = Get-Content -LiteralPath $TempFile
                [int] $LCID = $TempReport.task.taskInfo.language.lcid
                # all custom cultures share the same LCID 4096
                # and since the only other available info in the report is the language name, we have to find the name in list of all custom cultures
                if ($LCID -eq 4096) {
                    $ReportCulture = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::UserCustomCulture) | Where-Object -Property EnglishName -eq $
                else {
                    $ReportCulture = New-Object System.Globalization.CultureInfo($LCID)
                # construct the log file name (without extension, which is dependent on log save format)
                $ReportTargetLanguage = $ReportCulture.Name
                $LogFileName = $R.Name -replace "Report","$($SourceLanguage)_$ReportTargetLanguage"
                # If log location does not exist, create it
                if (!(Test-Path -LiteralPath $LogLocation)) {
                    New-Item $LogLocation -Force -ItemType Directory | Out-Null
                $LogLocation = (Resolve-Path -LiteralPath $LogLocation).ProviderPath
                # Save log in Excel format
                if ($ExcelLog) {
                    Write-Host "  $LogFileName.xlsx"
                    $Project.SaveTaskReportAs($R.Id, "$LogLocation\$LogFileName.xlsx", [Sdl.ProjectAutomation.Core.ReportFormat]::Excel)
                # Delete temporarily saved report
                Remove-Item $TempFile -Force
            }  # if $R.TaskTemplateId -eq AnalyzeFiles
        }  # ForEach $R in $T.Reports
    }  # ForEach $T in $Tasks.SubTasks
  • In reply to Evzen Polenka:

    Hi Evzen Polenka,

    Thank you very much for your very prompt and detailed response!!
    I've found inspiration for the solution in your code, in my c# project. So I'll also be extracting the language value from the report and looking for its culture too.
    Yeah, hope SDL can give us a proper tool for this. Maybe I can try raising a ticket?