public/Get-Translation.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Get-Translation
{
    param
    (
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
        )]
        [String[]]
        $Value,

        [Parameter(Mandatory = $true)]
        [CultureInfo]
        $From,

        [Parameter(Mandatory = $true)]
        [CultureInfo]
        $To,

        [Parameter()]
        [string]
        $Provider = 'Azure'
    )

    begin
    {
        $pipeCollection = New-Object -TypeName 'System.Collections.Generic.List[string]'
    }

    process
    {
        if ($Value.Count -eq 1)
        {
            $pipeCollection.Add($Value)
        }
        else
        {
            $pipeCollection.AddRange($Value)
        }
    }

    end
    {
        switch ($Provider)
        {
            'Azure' { $pipeCollection | New-AzureTranslation -From $From -To $To }
            default { Write-Warning -Message "No implementation found for provider $Provider. Available: $($(Get-ChildItem -Path "$PSScriptRoot\..\private" -File).Foreach({[regex]::Match($_.BaseName, 'New-(\w+)Translation').Groups[1].Value}) -join ',')"}
        }
    }
}