CmdID / PowerShell / Cmdlets / Import
Import-LocalizedData
Imports language-specific data into scripts and functions based on the UI culture that's selected for the operating system. PowerShell reference
From the PowerShell reference 5 parameters
What it does
Imports language-specific data into scripts and functions based on the UI culture that's selected for the operating system. The Import-LocalizedData cmdlet dynamically retrieves strings from a subdirectory whose name matches the UI language set for the current user of the operating system. It's designed to enable scripts to display user messages in the UI language selected by the current user. Import-LocalizedData imports data from .psd1 files in language-specific subdirectories of the script directory and saves them in a local variable that's specified in the command. The cmdlet selects the subdirectory and file based on the value of the $PSUICulture automatic variable. When you use the local variable in the script to display a user message, the message appears in the user's UI language. You can use the parameters of Import-LocalizedData to specify an alternate UI culture, path, and filename, to add supported commands, and to suppress the error message that appears if the .psd1 files aren't found. The Import-LocalizedData cmdlet supports the script internationalization initiative that was introduced in Windows PowerShell 2.0. This initiative aims to better serve users worldwide by making it easy for scripts to display user messages in the UI language of the current user. For more information about this and about the format of the .psd1 files, see about_Script_Internationalization.
Import-LocalizedData [[-BindingVariable] <String>] [[-UICulture] <String>] [-BaseDirectory <String>] [-FileName <String>] [-SupportedCommand <String[]>] [<CommonParameters>]
Import text strings
Import-LocalizedData -BindingVariable "Messages"IdentifyImport localized data strings
Import-LocalizedData -FileName "Test.psd1" -UICulture "en-US"IdentifyImport UI culture strings
Import-LocalizedData -BindingVariable "MsgTbl" -UICulture "ar-SA" -FileName "Simple" -BaseDirectory "C:\Data\Localized"IdentifyImport localized data into a script
PS C:> # In C:\Test\en-US\Test.psd1:
ConvertFrom-StringData @'
# English strings
Msg1 = "The Name parameter is missing from the command."
Msg2 = "This command requires the credentials of a member of the Administrators group on the computer."
Msg3 = "Use $_ to represent the object that's being processed."
'@
# In C:\Test\Test.ps1
Import-LocalizedData -BindingVariable "Messages"
Write-Host $Messages.Msg2
# In Windows PowerShell
PS C:> .\Test.ps1
This command requires the credentials of a member of the Administrators group on the computer.IdentifyReplace default text strings in a script
PS C:> # In TestScript.ps1
$UserMessages = DATA
{ ConvertFrom-StringData @'
# English strings
Msg1 = "Enter a name."
Msg2 = "Enter your employee ID."
Msg3 = "Enter your building number."
'@
}
Import-LocalizedData -BindingVariable "UserMessages"
$UserMessages.Msg1...IdentifySuppress error messages if the UI culture isn't found
PS C:> # In Day1.ps1
Import-LocalizedData -BindingVariable "Day"
# In Day2.ps1
Import-LocalizedData -BindingVariable "Day" -ErrorAction:SilentlyContinue
PS C:> .\Day1.ps1
Import-LocalizedData : Can't find PowerShell data file 'Day1.psd1' in directory 'C:\ps-test\fr-BE\'
or any parent culture directories.
At C:\ps-test\Day1.ps1:17 char:21+ Import-LocalizedData <<<< Day
Today is Tuesday
PS C:> .\Day2.ps1
Today is TuesdayIdentifyIts page in the reference: Import-LocalizedData.
Parameters
-BaseDirectorySpecifies 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.-BindingVariableSpecifies the variable into which the text strings are imported. Enter a variable name without a dollar sign ($).
In Windows PowerShell 2.0, this parameter is required. In Windows PowerShell 3.0, this parameter is optional. If you omit this parameter, Import-LocalizedData returns a hashtable of the text strings. The hashtable is passed down the pipeline or displayed at the command line.
When using Import-LocalizedData to replace default text strings specified in the DATA section of a script, assign the DATA section to a variable and enter the name of the DATA section variable in the value of the BindingVariable parameter. Then, when Import-LocalizedData saves the imported content in the BindingVariable, the imported data will replace the default text strings. If you aren't specifying default text strings, you can select any variable name.-FileNameSpecifies the name of the data file (.psd1) to be imported. Enter a filename. You can specify a filename that doesn't include its .psd1 filename extension, or you can specify the filename including the .psd1 filename extension. Data files should be saved as Unicode or UTF-8.
The FileName parameter is required when Import-LocalizedData isn't used in a script. Otherwise, the parameter is optional and the default value is the base name of the script. You can use this parameter to direct Import-LocalizedData to search for a different .psd1 file.
For example, if the FileName is omitted and the script name is FindFiles.ps1,
Import-LocalizedData searches for the FindFiles.psd1 data file.-SupportedCommandSpecifies cmdlets and functions that generate only data.
Use this parameter to include cmdlets and functions that you have written or tested. For more information, see about_Script_Internationalization.-UICultureSpecifies an alternate UI culture. The default is the value of the $PSUICulture automatic variable. Enter a UI culture in <language>-<region> format, such as en-US, de-DE, or ar-SA.
The value of the UICulture parameter determines the language-specific subdirectory (within the base directory) from which Import-LocalizedData gets the .psd1 file for the script.
The cmdlet searches for a subdirectory with the same name as the value of the UICulture parameter or the $PSUICulture automatic variable, such as de-DE or ar-SA. If it can't find the directory, or the directory doesn't contain a .psd1 file for the script, it searches for a subdirectory with the name of the language code, such as de or ar. If it can't find the subdirectory or .psd1 file, the command fails and the data is displayed in the default language specified in the script.