PowerShell Logo Small

Import-LocalizedData



This is the built-in help made by Microsoft for the command 'Import-LocalizedData', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Imports language-specific data into scripts and functions based on the UI culture that is selected for the operating system.

SYNTAX


Import-LocalizedData [-BindingVariable] <string> [[-UICulture] <string>] [-BaseDirectory <string>] [-FileName <string>] [-SupportedCommand <strin
g[]>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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 is 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 is specified in the command. The cmdlet selects the subdirectory and file based on the value of the $PSUICulture automatic variable. When y
ou 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 file name, to add supported commands, and to sup
press the error message that appears if the .psd1 files are not found.

The Import-LocalizedData cmdlet supports script internationalization in Windows PowerShell 2.0. This initiative aims to better serve users worldw
ide 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.



<

RELATED LINKS


Online version: http://go.microsoft.com/fwlink/?LinkID=113342
about_Script_Internationalization

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>import-localizeddata -bindingVariable messages



Description
-----------
This command imports text strings into the $messages variable. It uses all of the default values for the cmdlet parameters.

If the command is included in the Archives.ps1 script in the C:\test directory, and the value of the $PsUICulture automatic variable is zh-CN, Im
port-LocalizedData imports the Archives.psd1 file in the C:\test\zh-CN directory.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>import-localizeddata -bindingVariable msgTbl -uiculture ar-SA -filename Simple -baseDirectory C:\Data\Localized



Description
-----------
This command imports text strings into the $msgTbl variable of a script.

It uses the UICulture parameter to direct the cmdlet to import data from the Simple.psd1 file in the ar-SA subdirectory of C:\Data\Localized.








-------------------------- EXAMPLE 3 --------------------------

C:\PS># 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 is being processed."
'@

# In C:\Test\Test.ps1

import-localizeddata -bindingvariable messages
write-host $messages.msg2

# In Windows PowerShell

C:\PS> .\test.ps1
This command requires the credentials of a member of the Administrators group on the computer.



Description
-----------
This example shows how to use localized data in a simple script.

The first part of the example shows the contents of the Test.psd1 file. It contains a ConvertFrom-StringData command that converts a series of na
med text strings into a hash table. The test.psd1 file is located in the en-US subdirectory of the C:\Test directory that contains the script.

The second part of the example shows the contents of the Test.ps1 script. It contains an Import-LocalizedData command that imports the data from
the matching .psd1 file into the $Messages variable and a Write-Host command that writes one of the messages in the $Messages variable to the hos
t program.

The last part of the example runs the script. The output shows that it displays the correct user message in the UI language set for the current u
ser of the operating system.








-------------------------- EXAMPLE 4 --------------------------

C:\PS># 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
...



Description
-----------
This example shows how to use Import-LocalizedData to replace default text strings defined in the DATA section of a script.

In this example, the DATA section of the TestScript.ps1 script contains a ConvertFrom-StringData command that converts the contents of the DATA s
ection to a hash table and stores in the value of the $UserMessages variable.

The script also includes an Import-LocalizedData command, which imports a hash table of translated text strings from the TestScript.psd1 file in
the subdirectory specified by the value of the $PsUICulture variable. If the command finds the .psd1 file, it saves the translated strings from t
he file in the value of the same $UserMessages variable, overwriting the hash table saved by the DATA section logic.

The third command displays the first message in the $UserMessages variable.

If the Import-LocalizedData command finds a .psd1 file for the $PsUICulture language, the value of the $UserMessages variable contains the transl
ated text strings. If the command fails for any reason, the command displays the default text strings defined in the DATA section of the script.








-------------------------- EXAMPLE 5 --------------------------

C:\PS># In Day1.ps1
Import-LocalizedData -bindingVariable Day
Day.MessageDate

# In Day2.ps1
Import-LocalizedData -bindingVariable Day -errorAction:silentlycontinue
Day.MessageDate

C:\PS> .\Day1.ps1

Import-LocalizedData : Cannot 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


C:\PS> .\Day2.ps1

Today is Tuesday



Description
-----------
This example shows how to suppress the error messages that appear when Import-LocalizedData cannot find the directories that match the user's UI
culture or cannot find a .psd1 file for the script in those directories.

You can use the ErrorAction common parameter with a value of "SilentlyContinue" to suppress the error message. This is especially useful when you
have provided user messages in a default or "fallback" language, and no error message is needed.

This example compares two scripts, Day1.ps1 and Day2.ps1, that include an Import-LocalizedData command. The scripts are identical, except that Da
y2 uses the ErrorAction common parameter with a value of SilentlyContinue.

The sample output shows the results of running both scripts when the UI culture is set to fr-BE and there are no matching files or directories fo
r that UI culture. Day1.ps1 displays an error message and English output. Day2.ps1 just displays the English output.