-
Notifications
You must be signed in to change notification settings - Fork 225
/
Get-LocalizedDataRecursive.ps1
75 lines (65 loc) · 2.44 KB
/
Get-LocalizedDataRecursive.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
.SYNOPSIS
Get the localization strings data from one or more localization string files.
This can be used in classes to be able to inherit localization strings
from one or more parent (base) classes.
The order of class names passed to parameter `ClassName` determines the order
of importing localization string files. First entry's localization string file
will be imported first, then next entry's localization string file, and so on.
If the second (or any consecutive) entry's localization string file contain a
localization string key that existed in a previous imported localization string
file that localization string key will be ignored. Making it possible for a
child class to override localization strings from one or more parent (base)
classes.
.PARAMETER ClassName
An array of class names, normally provided by `Get-ClassName -Recurse`.
.OUTPUTS
Returns a string array with at least one item.
#>
function Get-LocalizedDataRecursive
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.String[]]
$ClassName
)
begin
{
$localizedData = @{}
}
process
{
foreach ($name in $ClassName)
{
if ($name -match '\.psd1')
{
# Assume we got full file name.
$localizationFileName = $name
}
else
{
# Assume we only got class name.
$localizationFileName = '{0}.strings.psd1' -f $name
}
Write-Debug -Message ('Importing localization data from {0}' -f $localizationFileName)
# Get localized data for the class
$classLocalizationStrings = Get-LocalizedData -DefaultUICulture 'en-US' -FileName $localizationFileName -ErrorAction 'Stop'
# Append only previously unspecified keys in the localization data
foreach ($key in $classLocalizationStrings.Keys)
{
if (-not $localizedData.ContainsKey($key))
{
$localizedData[$key] = $classLocalizationStrings[$key]
}
}
}
}
end
{
Write-Debug -Message ('Localization data: {0}' -f ($localizedData | ConvertTo-JSON))
return $localizedData
}
}