Skip to content

feat: Support message extraction from custom packages and types - #396

Closed
ducconit wants to merge 3 commits into
nicksnyder:mainfrom
ducconit:extract-other-source
Closed

ducconit wants to merge 3 commits into
nicksnyder:mainfrom
ducconit:extract-other-source

Conversation

@ducconit

Copy link
Copy Markdown

This Pull Request updates the goi18n extract command to be more flexible in identifying the source of messages to be extracted. Instead of hardcoding the check to the library's original package, developers can now configure the tool to scan their own structs or wrapper packages.

Key Changes: Added 2 new optional flags to the extract command:

  1. -i18nPackage (string): The import path of the package containing the message definitions.
    Default: github.com/nicksnyder/go-i18n/v2/i18n
  2. -i18nTypes (string): A comma-separated list of struct/type names to scan for message extraction.
    Default: Message,LocalizeConfig

Purpose:

  • Allows developers to extend or wrap the Message struct for their specific needs (e.g., adding validation, extra fields) while still leveraging the existing extract command.
  • Ensures backward compatibility: If these flags are not provided, the extract command behaves exactly as before, requiring no changes to existing codebases.

Example Usage:

# Extract from the default package (same as before)
goi18n extract

# Extract from a custom package and custom types
goi18n extract -i18nPackage "github.com/my-org/my-lib/i18n" -i18nTypes "CustomMessage,CustomConfig" .

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.17%. Comparing base (4e2b2f9) to head (b0e5da4).

Files with missing lines Patch % Lines
goi18n/extract_command.go 73.33% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #396      +/-   ##
==========================================
- Coverage   78.34%   78.17%   -0.17%     
==========================================
  Files          20       20              
  Lines        1496     1521      +25     
==========================================
+ Hits         1172     1189      +17     
- Misses        324      332       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicksnyder

Copy link
Copy Markdown
Owner

You can already embed a i18n.Message in your own struct and extraction will still work. If your use case is something different than that please clarify with some examples. I am not comfortable making this change without more information on your use case. Closing for now.

@nicksnyder nicksnyder closed this Oct 27, 2026
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.

2 participants