- How do I install spreadsheet-translator-core in a Laravel project?
- Run `composer require samuelvi/spreadsheet-translator-core` in your project directory. The package integrates with Laravel’s service container automatically, so no manual registration is needed. Ensure your `composer.json` lists Laravel 9+ or 10+ as a requirement, as this aligns with the package’s PHP 8.1+ support (PHP 8.4 is now optional but recommended for new projects).
- Does this package support Laravel Excel or Nova for spreadsheet handling?
- Yes, it’s fully compatible with Laravel Excel and Nova. The core library focuses on parsing and transforming spreadsheet data into translation resources, while Laravel Excel or Nova can handle file uploads/downloads. For Nova, you’d typically use the package’s transformers in custom actions or resource tools. PHP 8.4 may further simplify custom logic with typed properties or enums.
- What Laravel versions does spreadsheet-translator-core support?
- The package officially supports Laravel 9.x, 10.x, and 11.x, with PHP 8.1+ as the baseline. PHP 8.4 is now supported and recommended for new projects, offering performance benefits like JIT compilation and stricter typing. If you’re on an older Laravel version (e.g., 8.x), check for deprecated function usage or compatibility issues, as some PHP 8.4 features may not be backward-compatible.
- Can I use this for async processing with Laravel queues?
- Absolutely. The package is designed to work seamlessly with Laravel queues, especially with PHP 8.4’s fiber support (if enabled). You can dispatch spreadsheet parsing jobs to a queue, and the transformers will process data asynchronously. For large files, this avoids timeouts and improves responsiveness. Ensure your queue worker is configured to handle PHP 8.4 if leveraging new features.
- How do I validate spreadsheet data before importing translations?
- The package includes custom rule sets and schema enforcement for validation. Define rules in your transformer classes (e.g., `SpreadsheetRule::required('key')` or `SpreadsheetRule::enum('status', UserStatus::class)`). PHP 8.4’s enums and stricter typing can simplify validation logic. For complex schemas, combine with Laravel’s validation or use the package’s built-in error handling to log issues during parsing.
- Will this package work with PhpSpreadsheet or League/Csv?
- Yes, the package supports both PhpSpreadsheet (for Excel) and League/Csv (for CSV files). Under the hood, it delegates parsing to these libraries, so you can choose either based on your needs. PHP 8.4 compatibility is now enforced for these dependencies, so ensure your `composer.json` requires their latest versions. For CSV-only projects, League/Csv may offer lighter performance.
- How do I handle large spreadsheet files without memory issues?
- For large files, use chunked processing by configuring the transformer to yield results incrementally (e.g., `SpreadsheetTransformer::chunk(1000)`). Combine this with Laravel queues to offload processing. PHP 8.4’s fiber support (if enabled) can further optimize async workloads by reducing blocking operations. Always test memory usage with `memory_get_usage()` in your transformer logic.
- Are there alternatives to spreadsheet-translator-core for Laravel?
- If you need lightweight CSV parsing, consider `league/csv` directly or `spatie/array-to-object`. For Excel-focused tools, `maatwebsite/excel` is a strong alternative, though it lacks built-in translation resource conversion. This package stands out for its i18n-specific workflows, custom validation, and Laravel integration. For microservices, evaluate `spreadsheet-translator` (the full suite) if you need additional adapters.
- How do I test spreadsheet transformations in my Laravel app?
- Use PHPUnit or Pest to test transformers with mock spreadsheet data. Create test cases for edge cases (e.g., empty cells, invalid formats) and validate output against expected translation structures. PHP 8.4’s strict typing can help catch issues early—enable `strict_types=1` in your `php.ini` or `composer.json` for new projects. For integration tests, use Laravel’s `fake` methods to simulate file uploads.
- What are the production considerations for PHP 8.4 upgrades?
- Before upgrading, audit your transformers for PHP 8.4 compatibility (e.g., deprecated functions like `create_function`). Enable PHP 8.4’s JIT compiler in production for performance gains, but monitor memory usage. Test with a staging environment that mirrors production (e.g., same PHP extensions like `dom`, `fileinfo`). For queues, ensure workers are updated to PHP 8.4 if using fibers. Roll out gradually and monitor with Laravel Telescope for errors.