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

Extractor Laravel Package

php-translation/extractor

Extracts translation messages from PHP projects for the php-translation ecosystem. Scans source code and templates to collect translatable strings and generate catalogs, helping keep i18n files in sync across frameworks and custom apps.

View on GitHub
Deep Wiki
Context7

Extract translations form the source code

Frequently asked questions about Extractor
How do I extract translations from Laravel Blade templates using php-translation/extractor?
Run the CLI command `vendor/bin/extractor extract --output=lang/en.json` in your project root. By default, it scans Blade files (.blade.php) in the `resources/views` directory. For custom paths, use `--paths=app/Views,resources/views` or configure `.extractor.json`.
Does php-translation/extractor support Laravel’s `trans()` helper and `__()` functions?
Yes, it automatically detects Laravel’s translation functions like `trans()`, `__()`, `_e()`, and `trans_choice()`. It also handles dynamic placeholders (e.g., `trans('key', ['var' => $value])`) but may require manual review for complex logic.
Can I integrate this into Laravel’s CI/CD pipeline (GitHub Actions, GitLab CI)?
Absolutely. Add it to your workflow as a post-merge step or pre-commit hook. Example GitHub Action: `run: vendor/bin/extractor extract --output=lang/en.json`. For large repos, use `--parallel` to speed up extraction or cache results to avoid redundant scans.
What Laravel versions does php-translation/extractor support?
The package is optimized for Laravel 10+ (PHP 8.1+). For older versions (Laravel 9 or below), test thoroughly as some newer Blade syntax or helper changes might not be fully backward-compatible. Check the [release notes](https://github.com/php-translation/extractor/releases) for version-specific details.
How do I handle false positives (e.g., hardcoded IDs like `user.id`) in extracted translations?
Use the `--ignore-patterns` flag to exclude non-translatable strings, such as `--ignore-patterns='\\.id$|\\.class$'`. For complex cases, manually review the output or post-process the extracted files with a script to filter out false positives.
Can php-translation/extractor work with third-party translation tools like Crowdin or Poedit?
Yes, it exports translations to standard formats like XLIFF, PO, and JSON, which are compatible with Crowdin, Poedit, and other translation management systems. Configure the output format with `--output-format=xlf` or `--output-format=po` and sync the files with your TMS.
What if my Laravel app uses dynamic Blade syntax (e.g., `@foreach`, `@stack`) that breaks extraction?
Dynamic Blade constructs may produce incomplete or incorrect extractions. Start with a small subset of templates (e.g., `--paths=resources/views/auth`) and manually validate the output. For advanced cases, use `--skip-complex` to exclude problematic files or extend the parser via custom rules.
How do I test extracted translations to ensure they match my Laravel app’s `lang/` files?
Use PHPUnit or Pest to assert that extracted keys exist in your `lang/` files. Example test: `assertFileExists(resource_path('lang/en/json.json'));` and validate keys with `assertArrayHasKey('key', $translations)`. For automated checks, integrate the extractor into your test suite via a custom command.
Are there alternatives to php-translation/extractor for Laravel localization?
For Laravel-specific needs, consider `spatie/laravel-translation-loader` (for loading translations) or `laravel-lang/lang` (for pre-built language packs). For broader extraction, tools like `laravel-i18n` or `gettext` (via `symfony/intl`) are alternatives, but they lack Blade/Twig support out of the box.
How do I handle JavaScript or TypeScript translations in a Laravel app with this package?
php-translation/extractor focuses on PHP/Blade files. For JavaScript/TypeScript, use complementary tools like `i18next-scanner` or `vue-i18n`’s extractor. Export JS translations separately and merge them with PHP-extracted files in your `lang/` directory or TMS.
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony