Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
October 3, 2023

Centralization Through Localization

I’ve recently decided to make a change in the way I write my PowerShell modules. If you’ve been a subscriber, you’ve seen how I write my PowerShell functions. I use Write-Verbose statements liberally, in addition to warnings and errors. Often, I use the same verbose statement in multiple functions. If I need to change the text in a message, I must change it in multiple files. Granted, VSCode makes it easy to change text in multiple files. But that can get tedious, and I will likely make a mistake on complex changes. Then, I realized there was a better solution.

Since the earliest days of PowerShell, we’ve had the ability to create localized content. That is to say, if a function displays a message, it can be displayed in different languages based on the user’s culture. If you write a function that will be run on computers with the French or English culture, you can create culture-specific files that will be used when running the function.

I don’t have a requirement to support multiple cultures, but I can use the feature to centralize my messaging. Let’s see how this works.

Here’s a simple sample function.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.