Skip to content

Get-LocalizedDataForInvariantCulture: Localize debug messages #170

Merged
johlju merged 5 commits intomainfrom
copilot/fix-c85514e5-f47e-4a2a-8be7-d72f02895945
Aug 27, 2025
Merged

Get-LocalizedDataForInvariantCulture: Localize debug messages #170
johlju merged 5 commits intomainfrom
copilot/fix-c85514e5-f47e-4a2a-8be7-d72f02895945

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 27, 2025

Summary

Fixes #169 by replacing hardcoded debug and verbose messages in Get-LocalizedDataForInvariantCulture.ps1 with properly localized strings, ensuring compliance with the DSC Community coding guidelines.

Problem

The function Get-LocalizedDataForInvariantCulture.ps1 contained hardcoded debug messages that violated the project's localization guidelines. Per the coding guidelines, all Write-Debug, Write-Verbose, Write-Error, and Write-Warning messages must be localized using $script:localizedData.

The following hardcoded messages were identified:

  • Line 106: 'Found an extension to the file name to search. Stripping...'
  • Line 122: "Found '$filePath'."
  • Line 129: "File '$filePath' not found."
  • Line 139: 'Getting file {0}'

Solution

1. Added Localized Strings

Added 4 new localized string keys to source/en-US/DscResource.Common.strings.psd1:

## Get-LocalizedDataForInvariantCulture
GetLocalizedDataForInvariantCulture_GettingFile = Getting file {0}. (GLDFIC0001)
GetLocalizedDataForInvariantCulture_FoundExtension = Found an extension to the file name to search. Stripping... (GLDFIC0002)
GetLocalizedDataForInvariantCulture_FoundFile = Found '{0}'. (GLDFIC0003)
GetLocalizedDataForInvariantCulture_FileNotFound = File '{0}' not found. (GLDFIC0004)

2. Updated Function Implementation

Replaced all hardcoded strings in source/Public/Get-LocalizedDataForInvariantCulture.ps1:

Before:

Write-Debug -Message 'Found an extension to the file name to search. Stripping...'
Write-Debug -Message "Found '$filePath'."
Write-Debug -Message "File '$filePath' not found."
Write-Verbose -Message ('Getting file {0}' -f $languageFile)

After:

Write-Debug -Message $script:localizedData.GetLocalizedDataForInvariantCulture_FoundExtension
Write-Debug -Message ($script:localizedData.GetLocalizedDataForInvariantCulture_FoundFile -f $filePath)
Write-Debug -Message ($script:localizedData.GetLocalizedDataForInvariantCulture_FileNotFound -f $filePath)
Write-Verbose -Message ($script:localizedData.GetLocalizedDataForInvariantCulture_GettingFile -f $languageFile)

Testing

  • ✅ Verified localized strings file syntax is valid
  • ✅ Confirmed all hardcoded strings have been replaced
  • ✅ Validated function maintains identical behavior
  • ✅ Tested end-to-end functionality with localized messages

Example output showing localized messages working:

DEBUG: File './source/en-US/DscResource.Common.psd1' not found. (GLDFIC0004)
DEBUG: Found './source/en-US/DscResource.Common.strings.psd1'. (GLDFIC0003)
VERBOSE: Getting file ./source/en-US/DscResource.Common.strings.psd1. (GLDFIC0001)

Impact

  • Scope: Minimal changes - only 2 files modified (10 insertions, 4 deletions)
  • Compatibility: No breaking changes, maintains exact same functional behavior
  • Standards: Now fully compliant with DSC Community localization guidelines
  • Maintainability: Debug messages can now be localized for international users

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.com
    • Triggering command: pwsh -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 Reviewable

Copilot AI changed the title [WIP] Fix issue @dsccommunity/DscResource.Common/issues/169 Fix #169: Localize hardcoded debug messages in Get-LocalizedDataForInvariantCulture Aug 27, 2025
Copilot AI requested a review from johlju August 27, 2025 14:52
@johlju johlju changed the title Fix #169: Localize hardcoded debug messages in Get-LocalizedDataForInvariantCulture Get-LocalizedDataForInvariantCulture: Localize debug messages Aug 27, 2025
@johlju johlju marked this pull request as ready for review August 27, 2025 16:37
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 27, 2025

Walkthrough

Replaced 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

Cohort / File(s) Summary
Localization strings addition
source/en-US/DscResource.Common.strings.psd1
Added five keys under Get-LocalizedDataForInvariantCulture: Get_LocalizedDataForInvariantCulture_GettingFile, _FoundExtension, _FoundFile, _FileNotFound, _FileNotFoundInFolder.
Script debug messages localization
source/Public/Get-LocalizedDataForInvariantCulture.ps1
Replaced hardcoded Write-Debug messages with localized $script:localizedData lookups and -f formatting; no control-flow or error-handling changes.
Docs update
CHANGELOG.md
Added changelog note indicating debug messages were localized for Get-LocalizedDataForInvariantCulture (issue #169).

Sequence Diagram(s)

(omitted — changes limited to message localization; control flow unchanged)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Localize all debug messages in Get-LocalizedDataForInvariantCulture.ps1 (#169)
Add corresponding localized string keys in strings PSD1 for the debug messages (#169)

Possibly related PRs


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 22ecc26 and 58f88a5.

📒 Files selected for processing (2)
  • source/Public/Get-LocalizedDataForInvariantCulture.ps1 (2 hunks)
  • source/en-US/DscResource.Common.strings.psd1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/Public/Get-LocalizedDataForInvariantCulture.ps1
  • source/en-US/DscResource.Common.strings.psd1
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-c85514e5-f47e-4a2a-8be7-d72f02895945

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@johlju johlju force-pushed the copilot/fix-c85514e5-f47e-4a2a-8be7-d72f02895945 branch from 07df61c to 22ecc26 Compare August 27, 2025 17:06
@johlju
Copy link
Copy Markdown
Member

johlju commented Aug 27, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 09ca2dc and 22ecc26.

📒 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 Guidelines

Terminology

  • 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.ps1

Requirements

  • 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.md
  • source/Public/Get-LocalizedDataForInvariantCulture.ps1
  • source/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 MD013 rule 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 Guidelines

Naming

  • 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.ps1 format (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 array

Hashtables

  • 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.ps1
  • source/en-US/DscResource.Common.strings.psd1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/SqlServerDsc.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_SqlDscDatabase_ConnectingToDatabase

String 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 in source/en-US/DscResource.Common.strings.psd1.

No further action needed.

@johlju
Copy link
Copy Markdown
Member

johlju commented Aug 27, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@johlju reviewed 1 of 3 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @copilot)

@johlju johlju merged commit 23e38b5 into main Aug 27, 2025
10 checks passed
@johlju johlju deleted the copilot/fix-c85514e5-f47e-4a2a-8be7-d72f02895945 branch August 27, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Localize debug messages in Get-LocalizedDataForInvariantCulture.ps1

2 participants