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.
gettext or symfony/translation for localization. It complements Laravel’s existing translation mechanisms (e.g., __(), trans() helpers) by automating the extraction of translatable strings from comments and code, reducing manual .po file maintenance.Artisan commands). For example, it can be wrapped in a custom TranslationScanner facade or service provider.messages, validation, admin), enabling granular control over where strings are stored and translated. This maps directly to Laravel’s lang/ directory structure or custom domain configurations.storage/framework/views/ after Blade compilation).nikic/php-parser (v5.x), a robust and widely adopted library in PHP’s static analysis ecosystem. Laravel already uses similar tools (e.g., PHPStan, Psalm), so this dependency is low-risk and well-supported.app/, resources/lang/, routes/) or custom paths. Supports recursive scanning, which is useful for monolithic Laravel applications.i18n:/Translators: comments, which can coexist with Laravel’s existing __() function calls. This dual approach ensures backward compatibility while enabling new workflows (e.g., annotating strings directly in code)..po files in a format compatible with Laravel’s translation loaders (e.g., symfony/translation), enabling seamless integration with existing localization pipelines.@lang, @choice). Mitigation:
i18n: comments (e.g., @{{-- i18n:Hello --}}).laravel-gettext’s Blade directives as a fallback.eval(), create_function(), or complex concatenation). Mitigation: Supplement with manual reviews or custom regex patterns for known edge cases.git diff).__() calls, trans() helpers)? Will it replace, supplement, or run in parallel?.po files?.po files be merged with existing translations (e.g., Git merge conflicts, automated tools like msgmerge)?messages, validation) map to the scanner’s domain configurations?lang/ directory structure or follow a custom schema?.po files and resolving conflicts between scanned and manual translations?__() calls, integration tests for scanned strings)?__() calls have corresponding .po entries)?// translatable, /* i18n */) beyond the default i18n:/Translators:?TranslationScannerServiceProvider) to bind it to the container and boot it during application startup.artisan scan:translations command to trigger scanning and generate .po files on demand or via scheduling (e.g., php artisan scan:translations --watch for development).TranslationScanner::scanAndGenerate()) for use in controllers, commands, or event listeners.Illuminate\Translation\FileLoader) to load .po files generated by the scanner. This may require extending Laravel’s loader to support .po files or using a bridge like symfony/translation.laravel-gettext, the scanner’s output is natively compatible and can be fed directly into the package’s pipeline.storage/framework/views/ after Blade compilation. Requires ensuring Blade files are compiled before scanning (e.g., via php artisan view:clear or a custom event listener).i18n: comments into Blade templates (e.g., via a custom Blade compiler extension)..po files can be imported into Poedit for manual editing or pushed to Crowdin/Lokalise for collaborative translation.npm run scan-translations).husky or Laravel’s git hooks).resources/lang/ or a specific domain like validation)..po files to identify false positives/negatives.app/Http/Controllers/, routes/)..po file changes).__() calls without comments).gettext support or third-party packages like laravel-gettext/symfony/translation.gettext PHP extension for runtime translation (optional if using symfony/translation).intl mayHow can I help you explore Laravel packages today?