-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ResStr.ps1
More file actions
64 lines (57 loc) · 2.36 KB
/
Get-ResStr.ps1
File metadata and controls
64 lines (57 loc) · 2.36 KB
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
function Get-ResStr {
[CmdletBinding()]
param (
[string]$Key
)
begin {
# Here we could not write STARTING_FUNCTION because of a recursion
New-Variable -Name 'data' -Scope 'Private' -Value ($null)
New-Variable -Name 'path' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'reslang' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'values' -Scope 'Private' -Value ([System.Collections.Hashtable]@{})
New-Variable -Name 'xml' -Scope 'Private' -Value ($null)
New-Variable -Name 'xmlContent' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'xmlFile' -Scope 'Private' -Value ($null)
New-Variable -Name 'xmlFiles' -Scope 'Private' -Value ([System.Object[]]@())
New-Variable -Name 'result' -Scope 'Private' -Value ([string]'')
$initialVariables = Get-CurrentVariables -Debug:$DebugPreference
}
process {
if ($ecResx.count -eq 0) {
Write-Verbose "Get-ResX Init"
[string]$path = (Get-Module -Name EulandaConnect | Select-Object -ExpandProperty Path)
[string]$path = Split-path $path
$xmlFiles = Get-ChildItem "$path\*.resx"
foreach ($xmlFile in $xmlFiles) {
$reslang = $xmlFile.Name.Split('.')[1]
$xmlContent = Get-Content $xmlFile -Raw
$xml = [xml]$xmlContent
foreach ($data in $xml.root.data) {
if ($ecResx[$data.name]) {
$ecResx[$data.name][$reslang]= $data.value
} else {
$values = @{}
$values[$reslang] = $data.value
$ecResx[$data.name] = $values
}
}
}
}
if ($ecResx.ContainsKey($key)) {
if ($ecResx[$key].ContainsKey($ecCulture)) {
$result = $ecResx[$Key][$ecCulture]
} elseif ($ecResx[$key].ContainsKey('en-US')) {
$result = $ecResx[$Key]['en-US']
} else {
$result = "?[$ecCulture`:$key]"
}
} else {
$result = "?[$key]"
}
}
end {
Get-CurrentVariables -InitialVariables $initialVariables -Debug:$DebugPreference
Return $result
}
# Test: Get-ResStr -key 'OUT_WELCOME_COPYRIGHT'
}