Get-LocalizedDataForInvariantCulture: Localize debug messages #170
Get-LocalizedDataForInvariantCulture: Localize debug messages #170
Get-LocalizedDataForInvariantCulture: Localize debug messages #170Conversation
Get-LocalizedDataForInvariantCulture: Localize debug messages
WalkthroughReplaced hardcoded Write-Debug messages in Get-LocalizedDataForInvariantCulture.ps1 with localized $script:localizedData strings and added the corresponding localization keys to the en-US strings PSD1. CHANGELOG updated to note the localization under the existing entry (issue #169). Changes
Sequence Diagram(s)(omitted — changes limited to message localization; control flow unchanged) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
07df61c to
22ecc26
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
source/en-US/DscResource.Common.strings.psd1 (2)
73-79: Good keys and IDs; minor consistency nit for quoting file paths.Keys follow Verb_Function_Action and GLDFIC0001–0004 sequence. To match surrounding messages that quote file paths, consider quoting the placeholder in “Getting file {0}.”.
- Get_LocalizedDataForInvariantCulture_GettingFile = Getting file {0}. (GLDFIC0001) + Get_LocalizedDataForInvariantCulture_GettingFile = Getting file '{0}'. (GLDFIC0001)
73-79: Optionally add a localized key for the terminating error message.The function throws a non-localized error when no file is found. Adding a key enables full localization and aligns with module practices.
## Get-LocalizedDataForInvariantCulture Get_LocalizedDataForInvariantCulture_GettingFile = Getting file '{0}'. (GLDFIC0001) Get_LocalizedDataForInvariantCulture_FoundExtension = Found an extension to the file name to search. Stripping... (GLDFIC0002) Get_LocalizedDataForInvariantCulture_FoundFile = Found '{0}'. (GLDFIC0003) Get_LocalizedDataForInvariantCulture_FileNotFound = File '{0}' not found. (GLDFIC0004) + Get_LocalizedDataForInvariantCulture_FileNotFoundInFolder = None of the files '{0}' were found in '{1}'. (GLDFIC0005)source/Public/Get-LocalizedDataForInvariantCulture.ps1 (1)
133-140: Optional: Localize and use ThrowTerminatingError for the “not found in folder” error.Current throw uses a hardcoded string. Consider emitting a localized, categorized terminating error per guidelines.
- throw ('File ''{0}'' not found in ''{1}''.' -f ($localizedFileNamesToTry -join ','),$localizedFolder) + $message = ($script:localizedData.Get_LocalizedDataForInvariantCulture_FileNotFoundInFolder ` + -f ($localizedFileNamesToTry -join ', '), $localizedFolder) + $exception = New-Object System.Management.Automation.ItemNotFoundException ($message) + $errorRecord = New-Object System.Management.Automation.ErrorRecord ` + ($exception, 'GLDFIC0005', [System.Management.Automation.ErrorCategory]::ObjectNotFound, $localizedFolder) + $PSCmdlet.ThrowTerminatingError($errorRecord)If you want, I can open a follow-up PR to add the key and update the error handling.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)source/Public/Get-LocalizedDataForInvariantCulture.ps1(3 hunks)source/en-US/DscResource.Common.strings.psd1(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**
⚙️ CodeRabbit configuration file
**: # DSC Community GuidelinesTerminology
- Command: Public command
- Function: Private function
- Resource: DSC class-based resource
Build & Test Workflow
- Run project scripts in PowerShell from repository root
- Build after source changes:
.\build.ps1 -Tasks build- Test workflow: Build →
Invoke-Pester -Path @('<test paths>') -Output Detailed- New session required after class changes
File Organization
- Public commands:
source/Public/{CommandName}.ps1- Private functions:
source/Private/{FunctionName}.ps1- Unit tests:
tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1- Integration tests:
tests/Integration/Commands/{CommandName}.Integration.Tests.ps1Requirements
- Follow guidelines over existing code patterns
- Always update CHANGELOG.md Unreleased section
- Localize all strings using string keys; remove any orphaned string keys
- Check DscResource.Common before creating private functions
- Separate reusable logic into private functions
- Add unit tests for all commands/functions/resources
- Add integration tests for all public commands and resources
Files:
CHANGELOG.mdsource/Public/Get-LocalizedDataForInvariantCulture.ps1source/en-US/DscResource.Common.strings.psd1
**/*.md
⚙️ CodeRabbit configuration file
**/*.md: # Markdown Style Guidelines
- Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
- Use 2 spaces for indentation
- Use '1.' for all items in ordered lists (1/1/1 numbering style)
- Disable
MD013rule by adding a comment for tables/code blocks exceeding 80 characters- Empty lines required before/after code blocks and headings (except before line 1)
- Escape backslashes in file paths only (not in code blocks)
- Code blocks must specify language identifiers
Text Formatting
- Parameters: bold
- Values/literals:
inline code- Resource/module/product names: italic
- Commands/files/paths:
inline code
Files:
CHANGELOG.md
CHANGELOG.md
⚙️ CodeRabbit configuration file
CHANGELOG.md: # Changelog Guidelines
- Always update the Unreleased section in CHANGELOG.md
- Use Keep a Changelog format
- Describe notable changes briefly, ≤2 items per change type
- Reference issues using format #<issue_number>
- No empty lines between list items in same section
- Do not add item if there are already an existing item for the same change
Files:
CHANGELOG.md
**/*.ps?(m|d)1
⚙️ CodeRabbit configuration file
**/*.ps?(m|d)1: # PowerShell GuidelinesNaming
- Use descriptive names (3+ characters, no abbreviations)
- Functions: PascalCase with Verb-Noun format using approved verbs
- Parameters: PascalCase
- Variables: camelCase
- Keywords: lower-case
- Classes: PascalCase
- Include scope for script/global/environment variables:
$script:,$global:,$env:File naming
- Class files:
###.ClassName.ps1format (e.g.001.SqlReason.ps1,004.StartupParameters.ps1)Formatting
Indentation & Spacing
- Use 4 spaces (no tabs)
- One space around operators:
$a = 1 + 2- One space between type and variable:
[String] $name- One space between keyword and parenthesis:
if ($condition)- No spaces on empty lines
- Try to limit lines to 120 characters
Braces
- Newline before opening brace (except variable assignments)
- One newline after opening brace
- Two newlines after closing brace (one if followed by another brace or continuation)
Quotes
- Use single quotes unless variable expansion is needed:
'text'vs"text $variable"Arrays
- Single line:
@('one', 'two', 'three')- Multi-line: each element on separate line with proper indentation
- Do not use the unary comma operator (
,) in return statements to force
an arrayHashtables
- Empty:
@{}- Multi-line: each property on separate line with proper indentation
- Properties: Use PascalCase
Comments
- Single line:
# Comment(capitalized, on own line)- Multi-line:
<# Comment #>format (opening and closing brackets on own line), and indent text- No commented-out code
Comment-based help
- Always add comment-based help to all functions and scripts
- Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
- Comment-based help indentation: keywords 4 spaces, text 8 spaces
- Include examples for all parameter sets and combinations
- INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
- ...
Files:
source/Public/Get-LocalizedDataForInvariantCulture.ps1source/en-US/DscResource.Common.strings.psd1
source/**/*.ps1
⚙️ CodeRabbit configuration file
source/**/*.ps1: # Localization GuidelinesRequirements
- Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
- Use localized string keys, not hardcoded strings
- Assume
$script:localizedDatais availableString Files
- Commands/functions:
source/en-US/SqlServerDsc.strings.psd1- Class resources:
source/en-US/{ResourceClassName}.strings.psd1Key Naming Patterns
- Format:
Verb_FunctionName_Action(underscore separators), e.g.Get_SqlDscDatabase_ConnectingToDatabaseString Format
ConvertFrom-StringData @' KeyName = Message with {0} placeholder. (PREFIX0001) '@String IDs
- Format:
(PREFIX####)- PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
- Number: Sequential from 0001
Usage
Write-Verbose -Message ($script:localizedData.KeyName -f $value1)
Files:
source/Public/Get-LocalizedDataForInvariantCulture.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: dsccommunity.DscResource.Common (Build Package Module)
🔇 Additional comments (3)
CHANGELOG.md (1)
29-30: Changelog entry looks correct and scoped.Accurately documents the localization change under Unreleased → Changed for Get-LocalizedDataForInvariantCulture, with proper issue reference format.
source/Public/Get-LocalizedDataForInvariantCulture.ps1 (2)
106-108: LGTM: Debug/verbose strings correctly localized and formatted.All Write-Debug messages now use $script:localizedData with proper -f formatting where needed.
Also applies to: 122-124, 129-131, 139-140
106-108: All localization checks passed
- No hardcoded Write-Debug/Write-Verbose messages were found in
source/Public/Get-LocalizedDataForInvariantCulture.ps1.- All four localization keys (
Get_LocalizedDataForInvariantCulture_FileNotFound,…_FoundExtension,…_FoundFile,…_GettingFile) exist insource/en-US/DscResource.Common.strings.psd1.No further action needed.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
johlju
left a comment
There was a problem hiding this comment.
@johlju reviewed 1 of 3 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @copilot)
Summary
Fixes #169 by replacing hardcoded debug and verbose messages in
Get-LocalizedDataForInvariantCulture.ps1with properly localized strings, ensuring compliance with the DSC Community coding guidelines.Problem
The function
Get-LocalizedDataForInvariantCulture.ps1contained hardcoded debug messages that violated the project's localization guidelines. Per the coding guidelines, allWrite-Debug,Write-Verbose,Write-Error, andWrite-Warningmessages must be localized using$script:localizedData.The following hardcoded messages were identified:
'Found an extension to the file name to search. Stripping...'"Found '$filePath'.""File '$filePath' not found."'Getting file {0}'Solution
1. Added Localized Strings
Added 4 new localized string keys to
source/en-US/DscResource.Common.strings.psd1:2. Updated Function Implementation
Replaced all hardcoded strings in
source/Public/Get-LocalizedDataForInvariantCulture.ps1:Before:
After:
Testing
Example output showing localized messages working:
Impact
This change resolves the coding standards violation while maintaining full backward compatibility and following the established localization patterns used throughout the module.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.powershellgallery.compwsh -Command ./build.ps1 -Tasks build(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
This change is