Skip to content

Commit

Permalink
Get-LocalizedDataRecursive: Use localized strings (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-hughes authored May 14, 2024
1 parent a19ca99 commit 8391fad
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- DscResource.Base
- Move code coverage task in the pipeline to use task `PublishCodeCoverageResults@2`.
- `Get-LocalizedDataRecursive`
- Move strings to localized versions ([issue #7](https://github.com/dsccommunity/DscResource.Base/issues/7)).
- Fix various formatting issues

## [1.1.0] - 2023-02-26

Expand Down
4 changes: 2 additions & 2 deletions source/Classes/010.ResourceBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class ResourceBase

<#
TODO: When this fails, for example when the localized string file is missing
the LCM returns the error 'Failed to create an object of PowerShell
class SqlDatabasePermission' instead of the actual error that occurred.
the LCM returns the error 'Failed to create an object of PowerShell
class SqlDatabasePermission' instead of the actual error that occurred.
#>
$this.localizedData = Get-LocalizedDataRecursive @getLocalizedDataRecursiveParameters
}
Expand Down
2 changes: 1 addition & 1 deletion source/Private/ConvertFrom-CompareResult.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Returns a hashtable with property name and their expected value.
.PARAMETER CompareResult
The result from Compare-DscParameterState.
The result from Compare-DscParameterState.
.EXAMPLE
ConvertFrom-CompareResult -CompareResult (Compare-DscParameterState)
Expand Down
2 changes: 1 addition & 1 deletion source/Private/ConvertFrom-Reason.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
that can be returned as the value of a DSC resource's property **Reasons**.
.PARAMETER Reason
Specifies an array of `[Reason]`. Normally the result from the command `Resolve-Reason`.
Specifies an array of `[Reason]`. Normally the result from the command `Resolve-Reason`.
.EXAMPLE
Resolve-Reason -Reason (Resolve-Reason) -ResourceName 'MyResource'
Expand Down
8 changes: 4 additions & 4 deletions source/Private/Get-ClassName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
all inherited classes
.PARAMETER InputObject
The object to be evaluated.
The object to be evaluated.
.PARAMETER Recurse
Specifies if the class name of inherited classes shall be returned. The
recursive stops when the first object of the type `[System.Object]` is
found.
Specifies if the class name of inherited classes shall be returned. The
recursive stops when the first object of the type `[System.Object]` is
found.
.EXAMPLE
Get-ClassName -InputObject $this -Recurse
Expand Down
8 changes: 4 additions & 4 deletions source/Private/Get-LocalizedDataRecursive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
instance.
.EXAMPLE
Get-LocalizedDataRecursive -ClassName (Get-ClassNamn -InputObject $this -Recurse)
Get-LocalizedDataRecursive -ClassName (Get-ClassName -InputObject $this -Recurse)
Returns a hashtable containing all the localized strings for the current
instance and any inherited (parent) classes.
Expand Down Expand Up @@ -73,7 +73,7 @@ function Get-LocalizedDataRecursive
$localizationFileName = '{0}.strings' -f $name
}

Write-Debug -Message ('Importing localization data from {0}' -f $localizationFileName)
Write-Debug -Message ($script:localizedData.DebugImportingLocalizationData -f $localizationFileName)

if ($name -eq 'ResourceBase')
{
Expand All @@ -88,7 +88,7 @@ function Get-LocalizedDataRecursive
else
{
# Assuming derived class that is not part of this module.
throw 'The class ''{0}'' is not part of module DscResource.Base and no BaseDirectory was passed. Please provide BaseDirectory.'
throw ($script:localizedData.ThrowClassIsNotPartOfModule -f $name)
}

# Get localized data for the class
Expand All @@ -107,7 +107,7 @@ function Get-LocalizedDataRecursive

end
{
Write-Debug -Message ('Localization data: {0}' -f ($localizedData | ConvertTo-JSON))
Write-Debug -Message ($script:localizedData.DebugShowAllLocalizationData -f ($localizedData | ConvertTo-JSON))

return $localizedData
}
Expand Down
6 changes: 3 additions & 3 deletions source/Private/Resolve-Reason.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
`Compare-DscParameterState`. The result is an array of the type `[Reason]`.
.PARAMETER Property
The result from the command Compare-DscParameterState.
The result from the command Compare-DscParameterState.
.PARAMETER ResourceName
The name of the resource. Will be used to populate the property Code with
the correct value.
The name of the resource. Will be used to populate the property Code with
the correct value.
.EXAMPLE
Resolve-Reason -Property (Compare-DscParameterState) -ResourceName 'MyResource'
Expand Down
3 changes: 3 additions & 0 deletions source/en-US/DscResource.Base.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
#>

ConvertFrom-StringData @'
DebugImportingLocalizationData = Importing localization data from '{0}' (DRB0001)
ThrowClassIsNotPartOfModule = The class '{0}' is not part of module DscResource.Base and no BaseDirectory was passed. Please provide BaseDirectory. (DRB0002)
DebugShowAllLocalizationData = Localization data: '{0}' (DRB0003)
'@

0 comments on commit 8391fad

Please sign in to comment.