I am working on a PowerShell script that will need to be available in 2 languages. To make my life easier, it seems like a good idea to me to create a language file for each, and include the strings in there, rather than having the text directly in the code and maintaining 2 copies of the code. Is there a best practice on how to implement this?
The roadblock that I'm at right now is that some of the strings will need to contain variables, so I've already run into some trouble there. I've noticed that it will use the value of the variable at the time that the string is set, which makes sense to me.
So for example, if I have a string which outputs an error level:
$Strings.ErrorMessage = "Error detected with $Level severity"
And then later set $Level to to whatever value, it won't have that value when the script is called. Assuming that $Level isn't set before setting $Strings.ErrorMessage, The output would look like:
Error detected at severity
Is there a way to tell PowerShell to grab the current value of the $Level variable before it is output?
$Strings.ErrorMessage = 'Error detected with $Level severity'and$ExecutionContext.InvokeCommand.ExpandString($Strings.ErrorMessage)or$Strings.ErrorMessage = 'Error detected with {0} severity'and$Strings.ErrorMessage -f $Level.