Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Scanner Laravel Package

gettext/php-scanner

Scan PHP source to extract gettext translations for use with gettext/gettext. Supports multiple domains, default domain selection, and extracting translator/i18n comments. Produces Translations you can export to .po files with generators like PoGenerator.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Internationalization (i18n) Roadmap: Enables automated extraction of translatable strings from PHP/Laravel codebases, reducing manual effort in localization workflows. Aligns with a build vs. buy decision to avoid reinventing a scanner for gettext integration, especially for teams already using Laravel’s i18n stack.
  • Developer Productivity: Automates the extraction of strings from comments (e.g., i18n: or Translators:) and code, accelerating time-to-market for multilingual features. Reduces cognitive load for developers by standardizing translation extraction patterns.
  • Scalability: Supports domain-specific translations (e.g., separating UI strings from admin panel strings) and sprintf formatting flags, critical for large-scale Laravel apps with complex localization needs (e.g., SaaS platforms, e-commerce).
  • Compliance with Modern Laravel: Supports PHP 8.4 and integrates with Laravel’s existing i18n tools (e.g., laravel-gettext, symfony/translation), ensuring compatibility with long-term tech stacks.
  • Use Cases:
    • Localizing Laravel apps with dynamic string extraction, reducing reliance on manual .po file updates.
    • Migrating legacy Laravel apps to gettext without rewriting i18n logic.
    • Enabling context-aware translations (e.g., distinguishing between "Submit" in forms vs. buttons) via domain isolation.
    • Supporting Blade templates (with pre-processing) for translatable strings outside PHP files.

When to Consider This Package

  • Adopt if:

    • Your Laravel app uses gettext (via laravel-gettext, symfony/translation, or native PHP extension) and needs automated string extraction.
    • You have hundreds of PHP/Blade files with hardcoded translatable strings or comments (e.g., // i18n:).
    • Your team lacks bandwidth to manually extract strings or maintain .po files, especially during rapid development cycles.
    • You require sprintf/printf support or domain-specific translation domains (e.g., messages, validation, admin).
    • Your PHP/Laravel version is 7.4+ (minimum requirement) and you’re open to minor pre-processing for Blade templates.
    • You’re prioritizing developer productivity over real-time translation updates (e.g., not using crowd-sourced platforms like Crowdin).
  • Look elsewhere if:

    • Your Laravel app relies on JSON/JS-based i18n (e.g., laravel-translatable, vue-i18n) where strings are managed outside PHP. Consider tools like laravel-translation-manager or i18next.
    • You need real-time translation updates without .po file generation (e.g., dynamic content platforms). Evaluate managed services like DeepL, AWS Translate, or Lokalise.
    • Your codebase is heavily obfuscated or uses dynamic string concatenation (e.g., eval(), complex Blade logic) not covered by the scanner. May require custom pre-processing or a different approach.
    • You’re using Laravel 5.8 or below on PHP 7.2, as the package requires PHP 7.4+. Consider a polyfill or alternative tool.
    • Your team prefers visual tools over CLI/scripting for translation extraction (e.g., Poedit alone). This package is CLI/script-driven.

How to Pitch It (Stakeholders)

For Executives:

"This package automates 80% of our localization workflow by scanning Laravel/PHP code for translatable strings—reducing manual effort and accelerating global launches. For example, a 50,000-line Laravel codebase could generate .po files in minutes instead of days, cutting localization costs by 20–30%. It’s a low-risk, high-impact tool that integrates seamlessly with our existing gettext stack, ensuring compliance with Laravel’s i18n best practices. The MIT license and active maintenance (PHP 8.4 support) guarantee long-term viability, while domain-specific scanning future-proofs our multilingual features. Pilot this in [Module X] to replace manual .po file updates and unlock faster time-to-market for new languages."

For Engineering (Laravel Team):

*"The gettext/php-scanner is a PHP parser that extracts translatable strings from:

  • Comments: // i18n: Welcome! or // Translators: %s
  • Function calls: __('Login'), _e(), or trans()
  • Sprintf patterns: sprintf(__('User %s logged in'), $name)
  • Static/class methods and arrays (e.g., ['error' => __('Invalid input')]).

Key benefits for Laravel:

  • Zero false positives: Uses nikic/php-parser (same as PHPStan) for accurate AST analysis.
  • Domain isolation: Route strings to different .po files (e.g., messages.po for UI, validation.po for errors).
  • CI/CD friendly: Scriptable via CLI or embedded in Laravel’s post-update-cmd or Git hooks.
  • Blade support: Requires pre-processing (e.g., converting @lang to __() calls) but enables full coverage.

Trade-offs:

  • Blade templates: Not natively supported; need to annotate or pre-process (e.g., {{-- i18n:Hello --}}).
  • Initial setup: Configure file paths, domains, and comment patterns (e.g., // i18n: vs. // translatable).

Proposal: Integrate this into our [localization pipeline] to replace manual .po file updates. Estimated savings: 10–15 dev hours/month and reduced QA overhead for missing translations. Let’s pilot it in the [Dashboard Module] first."*

For Localization Teams:

*"This tool will revolutionize our workflow by:

  1. Eliminating manual extraction: Automatically pull all translatable strings from code, including edge cases like sprintf placeholders and domain-specific strings.
  2. Improving consistency: Standardize extraction via comments (e.g., // Translators: %s) and function calls, reducing ambiguity.
  3. Reducing bottlenecks: Generate .po files on-demand (e.g., post-PR merge) instead of manual syncs, cutting turnaround time for new languages.
  4. Supporting context: Use domains to separate UI, validation, and admin strings, making translations more maintainable.

Ask:

  • Provide a list of your current .po files and codebase structure (e.g., Blade/PHP paths) so we can configure domains and comment patterns.
  • Identify any Blade templates with translatable strings that need annotation (e.g., {{-- i18n: --}}).
  • Confirm whether you’d prefer to merge scanned strings into existing .po files or generate new ones per domain.

Outcome: Faster updates, fewer missing translations, and clearer ownership of translatable content."*

For DevOps/Infrastructure:

*"This package can be integrated into our CI/CD pipeline to:

  • Automate .po file generation: Trigger scanning on git push or PR merges (e.g., via GitHub Actions or Laravel Forge).
  • Validate translations: Fail builds if new translatable strings are found without corresponding .po entries.
  • Sync with translation services: Push generated .po files to Crowdin/Lokalise or store them in S3 for manual review.

Example Workflow:

  1. Developer adds // i18n: New feature! to a Blade file.
  2. CI runs php-scanner to extract the string and generate resources/lang/en/messages.po.
  3. Localization team reviews the update in Poedit or Crowdin.
  4. Translated strings are pulled back into the codebase via Laravel’s translation loader.

Tools to Leverage:

  • GitHub Actions: Run scanner on push to main branch.
  • Laravel Mix: Add a custom script (npm run scan-translations) to trigger scanning.
  • Artisan Commands: Wrap the scanner in a custom command (e.g., php artisan extract:translations)."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor