Public/Language.txt

function Disable-CrmLanguagePack{
# .ExternalHelp Campgemini.Xrm.Data.PowerShell.Help.xml
 
    [CmdletBinding()]
    PARAM(
        [parameter(Mandatory=$false)]
        [Microsoft.Xrm.Sdk.IOrganizationService]$conn,
        [parameter(Mandatory=$true, Position=1)]
        [Int]$LCID
    )
 
    $conn = VerifyCrmConnectionParam -conn $conn -pipelineValue ($PSBoundParameters.ContainsKey('conn'))
 
    $request = New-Object Microsoft.Crm.Sdk.Messages.DeprovisionLanguageRequest
    $request.Language = $LCID
     
    try
    {
        $result = $conn.Execute($request)
        if($result -eq $null)
        {
            throw $_.Exception
        }
    }
    catch
    {
        throw $_.Exception
    }
}
 
function Enable-CrmLanguagePack{
# .ExternalHelp Campgemini.Xrm.Data.PowerShell.Help.xml
 
    [CmdletBinding()]
    PARAM(
        [parameter(Mandatory=$false)]
        [Microsoft.Xrm.Sdk.IOrganizationService]$conn,
        [parameter(Mandatory=$true, Position=1)]
        [Int]$LCID
    )
 
    $conn = VerifyCrmConnectionParam -conn $conn -pipelineValue ($PSBoundParameters.ContainsKey('conn'))
 
    $request = New-Object Microsoft.Crm.Sdk.Messages.ProvisionLanguageAsyncRequest
    $request.Language = $LCID
     
    try
    {
        $result = $conn.Execute($request)
        if($result -eq $null)
        {
            throw $_.Exception
        }
    }
    catch
    {
        throw $_.Exception
    }
}
 
function Export-CrmSolutionTranslation{
# .ExternalHelp Campgemini.Xrm.Data.PowerShell.Help.xml
 
    [CmdletBinding()]
    PARAM(
        [parameter(Mandatory=$false)]
        [Microsoft.Xrm.Sdk.IOrganizationService]$conn,
        [parameter(Mandatory=$true, Position=1)]
        [string]$SolutionName,
        [parameter(Mandatory=$false)]
        [string]$TranslationFilePath,
        [parameter(Mandatory=$false)]
        [string]$TranslationZipFileName
    )
 
    $conn = VerifyCrmConnectionParam -conn $conn -pipelineValue ($PSBoundParameters.ContainsKey('conn'))
 
    try
    {
        $solutionRecords = (Get-CrmRecords -conn $conn -EntityLogicalName solution -FilterAttribute uniquename -FilterOperator "like" -FilterValue $SolutionName -Fields publisherid,version )
 
        #if we can't find just one solution matching then ERROR
        if($solutionRecords.CrmRecords.Count -ne 1)
        {
            $friendlyName = $conn.ConnectedOrgFriendlyName.ToString()
 
            Write-Error "Solution with name `"$SolutionName`" in CRM Instance: `"$friendlyName`" not found!"
            break
        }
        #else PROCEED
 
        $version = $solutionRecords.CrmRecords[0].version
 
        write-verbose "Solution found with version# $version"
        
        $exportPath = if($TranslationFilePath -ne ""){ $TranslationFilePath } else { Get-Location }
         
        #if a filename is not given, then we'll default one to CrmTranslations_[solutionname]_[version].zip
        if($TranslationZipFileName.Length -eq 0)
        {
            $version = $version.Replace('.','_')
            $translationZipFileName = "CrmTranslations_$SolutionName`_$version.zip"
        }
 
        #now we should have the final path
        $path = Join-Path $exportPath $translationZipFileName
 
        Write-Verbose "Solution path: $path"
 
        #create the export translation request then set all the properties
        $exportRequest = New-Object Microsoft.Crm.Sdk.Messages.ExportTranslationRequest
        $exportRequest.SolutionName = $SolutionName
 
        Write-Verbose 'ExportTranslationRequest may take several minutes to complete execution.'
         
        $response = [Microsoft.Crm.Sdk.Messages.ExportTranslationResponse]($conn.Execute($exportRequest))
 
        [System.IO.File]::WriteAllBytes($path,$response.ExportTranslationFile)
 
        Write-Verbose "Successfully wrote file: $path"
        $result = New-Object psObject
 
        Add-Member -InputObject $result -MemberType NoteProperty -Name "ExportTranslationResponse" -Value $response
        Add-Member -InputObject $result -MemberType NoteProperty -Name "SolutionTranslationPath" -Value $path
 
        return $result
    }
    catch
    {
        Write-Error $_.Exception
    }
 
    return $result
}
 
function Get-CrmAllLanguagePacks{
# .ExternalHelp Campgemini.Xrm.Data.PowerShell.Help.xml
 
    [CmdletBinding()]
    PARAM(
        [parameter(Mandatory=$false)]
        [Microsoft.Xrm.Sdk.IOrganizationService]$conn
    )
 
    $conn = VerifyCrmConnectionParam -conn $conn -pipelineValue ($PSBoundParameters.ContainsKey('conn'))
 
    $request = New-Object Microsoft.Crm.Sdk.Messages.RetrieveAvailableLanguagesRequest
 
    try
    {
        $response = $conn.Execute($request)
    }
    catch
    {
        throw $_.Exception
    }
 
    return $response.LocaleIds
}
 
function Import-CrmSolutionTranslation{
# .ExternalHelp Campgemini.Xrm.Data.PowerShell.Help.xml
 
    [CmdletBinding()]
    PARAM(
        [parameter(Mandatory=$false)]
        [Microsoft.Xrm.Sdk.IOrganizationService]$conn,
        [parameter(Mandatory=$true, Position=1)]
        [string]$TranslationFileName,
        [parameter(Mandatory=$false, Position=2)]
        [switch]$PublishChanges
    )
 
    $conn = VerifyCrmConnectionParam -conn $conn -pipelineValue ($PSBoundParameters.ContainsKey('conn'))
        
    try
    {
        $importId = [guid]::NewGuid()
        $translationFile = [System.IO.File]::ReadAllBytes($TranslationFileName)
 
        #create the import translation request then set all the properties
        $importRequest = New-Object Microsoft.Crm.Sdk.Messages.ImportTranslationRequest
        $importRequest.TranslationFile = $translationFile
        $importRequest.ImportJobId = $importId
         
        Write-Verbose 'ImportTranslationRequest may take several minutes to complete execution.'
        $response = [Microsoft.Crm.Sdk.Messages.ImportTranslationResponse]($conn.Execute($importRequest))
                 
        Write-Verbose "Confirming the result"
        $xml = [xml](Get-CrmRecord -conn $conn -EntityLogicalName importjob -Id $importId -Fields data).data
        $importresult = $xml.importtranslations
         
        if($importresult.status -ne "Succeeded")
        {
            $importerrordetails = $importresult.errordetails
            Write-Verbose "Import result: $importerrordetails"
            throw $importerrordetails
        }
        else
        {
            if($PublishChanges){
                Write-Verbose "Guid populated and user requested publish changes request..."
                Write-Verbose "Executing command: Publish-CrmAllCustomization, passing in the same connection"
             
                Publish-CrmAllCustomization -conn $conn
            }
            else{
                Write-Verbose "Import Complete don't forget to publish customizations."
            }
        }
    }
    catch
    {
        Write-Error $_.Exception
    }
}