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.
i18n: or Translators:) and code, accelerating time-to-market for multilingual features. Reduces cognitive load for developers by standardizing translation extraction patterns.laravel-gettext, symfony/translation), ensuring compatibility with long-term tech stacks..po file updates.Adopt if:
laravel-gettext, symfony/translation, or native PHP extension) and needs automated string extraction.// i18n:)..po files, especially during rapid development cycles.messages, validation, admin).Look elsewhere if:
laravel-translatable, vue-i18n) where strings are managed outside PHP. Consider tools like laravel-translation-manager or i18next..po file generation (e.g., dynamic content platforms). Evaluate managed services like DeepL, AWS Translate, or Lokalise.eval(), complex Blade logic) not covered by the scanner. May require custom pre-processing or a different approach."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."
*"The gettext/php-scanner is a PHP parser that extracts translatable strings from:
// i18n: Welcome! or // Translators: %s__('Login'), _e(), or trans()sprintf(__('User %s logged in'), $name)['error' => __('Invalid input')]).Key benefits for Laravel:
nikic/php-parser (same as PHPStan) for accurate AST analysis..po files (e.g., messages.po for UI, validation.po for errors).post-update-cmd or Git hooks.@lang to __() calls) but enables full coverage.Trade-offs:
{{-- i18n:Hello --}}).// 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."*
*"This tool will revolutionize our workflow by:
// Translators: %s) and function calls, reducing ambiguity..po files on-demand (e.g., post-PR merge) instead of manual syncs, cutting turnaround time for new languages.Ask:
.po files and codebase structure (e.g., Blade/PHP paths) so we can configure domains and comment patterns.{{-- i18n: --}})..po files or generate new ones per domain.Outcome: Faster updates, fewer missing translations, and clearer ownership of translatable content."*
*"This package can be integrated into our CI/CD pipeline to:
.po file generation: Trigger scanning on git push or PR merges (e.g., via GitHub Actions or Laravel Forge)..po entries..po files to Crowdin/Lokalise or store them in S3 for manual review.Example Workflow:
// i18n: New feature! to a Blade file.php-scanner to extract the string and generate resources/lang/en/messages.po.Tools to Leverage:
push to main branch.npm run scan-translations) to trigger scanning.php artisan extract:translations)."*How can I help you explore Laravel packages today?