Skip to content

Get LocalizedDataForInvariantCulture

dscbot edited this page Feb 13, 2024 · 3 revisions

Get-LocalizedDataForInvariantCulture

SYNOPSIS

Gets language-specific data when the culture is invariant. This directly gets the data from the DefaultUICulture, but without calling "Import-LocalizedData" which throws when the pwsh session is configured to be of invariant culture (as in the Guest Config agent).

SYNTAX

Get-LocalizedDataForInvariantCulture [-BaseDirectory] <String> [-FileName] <String>
 [[-DefaultUICulture] <String>] [<CommonParameters>]

DESCRIPTION

The Get-LocalizedDataForInvariantCulture grabs the data from a localized string data psd1 file, without calling Import-LocalizedData which errors when called in a powershell session with the Globalization-Invariant mode enabled (https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode).

Instead, this function reads and executes the content of a psd1 file in a constrained language mode that only allows basic ConvertFrom-stringData.

EXAMPLES

EXAMPLE 1

Get-LocalizedDataForInvariantCulture -BaseDirectory .\source\ -FileName DscResource.Common -DefaultUICulture en-US

This is an example, usually it is only used by Get-LocalizedData in DSC resources to import the localized strings when the Culture is Invariant (id 127).

PARAMETERS

-BaseDirectory

Specifies the base directory where the .psd1 files are located. The default is the directory where the script is located. Import-LocalizedData searches for the .psd1 file for the script in a language-specific subdirectory of the base directory.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DefaultUICulture

Specifies which UICulture to default to if current UI culture or its parents culture don't have matching data file.

For example, if you have a data file in 'en-US' but not in 'en' or 'en-GB' and your current culture is 'en-GB', you can default back to 'en-US'.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: En-US
Accept pipeline input: False
Accept wildcard characters: False

-FileName

Specifies the base name of the data file (.psd1) to be imported. Enter a file name. You can specify a file name that does not include its .psd1 file name extension, or you can specify the file name including the .psd1 file name extension.

The FileName parameter is required when Get-LocalizedDataForInvariantCulture is not used in a script. Otherwise, the parameter is optional and the default value is the base name of the calling script. You can use this parameter to directly search for a specific .psd1 file.

For example, if the FileName is omitted and the script name is FindFiles.ps1, Get-LocalizedDataForInvariantCulture searches for the FindFiles.psd1 or FindFiles.strings.psd1 data file.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

The Get-LocalizedDataForInvariantCulture should only be used when we want to avoid using Import-LocalizedData, such as when doing so will fail because the powershell session is in Globalization-Invariant mode: https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode

Before using Get-LocalizedDataForInvariantCulture, localize your user messages to the desired default locale (UI culture, usually en-US) in a hash table of key/value pairs, and save the hash table in a file with the same name as the script or module with a .psd1 file name extension. Create a directory under the module base or script's parent directory for each supported UI culture, and then save the .psd1 file for each UI culture in the directory with the UI culture name.

For example, localize your user messages for the de-DE locale and format them in a hash table. Save the hash table in a .psd1 file. Then create a de-DE subdirectory under the script directory, and save the de-DE .psd1 file in the de-DE subdirectory. Repeat this method for each locale that you support.

Import-LocalizedData performs a structured search for the localized user messages for a script.

Get-LocalizedDataForInvariantCulture only search in the BaseDirectory specified. It then searches within the base directory for a subdirectory with the same name as the value of the $DefaultUICulture variable (specified or default to en-US), such as de-DE or ar-SA. Then, it searches in that subdirectory for a .psd1 file with the same name as provided FileName such as FileName.psd1 or FileName.strings.psd1.

RELATED LINKS

Clone this wiki locally