Download the PHP package volcy/translator-core without Composer
On this page you can find all versions of the php package volcy/translator-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download volcy/translator-core
More information about volcy/translator-core
Files in volcy/translator-core
Package translator-core
Short Description Framework-agnostic Blade string extraction and JSON-based translation catalog.
License MIT
Homepage https://github.com/VolcyGithub/translator-core
Informations about the package translator-core
Translator Core
Framework-agnostic Blade string extraction and JSON-based translation catalog system. This library provides the core functionality for scanning Blade templates, building translation indexes, and applying translations to rendered HTML.
Features
- Framework Agnostic: Works with any PHP framework or plain PHP applications
- Blade Template Support: Extracts translatable strings from Blade templates
- Multiple ID Strategies: Configurable ID generation (hash, tag path, explicit)
- Translation Drivers: Support for Google Translate, Groq, and Cerebras APIs
- HTML Translation: Applies translations to rendered HTML via DOM manipulation
- PHP Array Support: Extracts strings from PHP arrays with optional key-based IDs
- Collision Detection: Warns about ID conflicts during scanning
- Framework Bridges: Laravel and FlightPHP integration packages available
- Custom Data Attributes: Support for
data-i18n-*attributes for dynamic content translation - Balanced Element Extraction: Accurate HTML parsing for nested tag structures
Requirements
- PHP 8.0 or higher
- ext-dom
- ext-json
- ext-curl
- ext-mbstring
Installation
Install via Composer:
Requirements
- PHP 8.0 or higher
- ext-dom
- ext-json
- ext-curl
- ext-mbstring
Quick Start
Basic Usage
Building Translations
Applying Translations
ID Strategies
The library supports multiple strategies for generating translation IDs:
Hash Strategy (Default)
Content-based SHA1 hashes for maximum stability.
Tag Path Strategy
Context-aware IDs based on HTML structure.
Explicit Strategy
Manual control via data-i18n attributes with hash fallback.
For detailed information about ID strategies, see ID_STRATEGIES.md.
Translation Drivers
Google Translate
Groq
Cerebras
HTML with Explicit IDs
When using the explicit ID strategy, you can specify translation IDs directly in your HTML:
Custom Data Attributes for Dynamic Content
The scanner now supports custom data-i18n-* attributes for translating dynamic JavaScript content:
The scanner will extract the values from custom data-i18n-* attributes and make them available for translation. This enables compile-time translation for dynamic content that's controlled by JavaScript frameworks.
PHP Arrays with Key-Based IDs
The scanner also extracts strings from PHP arrays and uses array keys as explicit IDs:
Framework Integration
Laravel
Use the volcy/translator-laravel package for Laravel integration:
FlightPHP
Use the volcy/translator-flight package for FlightPHP integration:
API Reference
Core Classes
- BladeDriver: Extracts translatable strings from Blade templates
- ScanRunner: Scans views and generates source locale indexes
- BuildRunner: Builds target locale indexes from source
- TranslationCatalog: Manages translation lookup and HTML application
- TranslationDriverResolver: Resolves translation driver from config
- IdStrategyResolver: Resolves ID generation strategy from config
Interfaces
- DocumentDriver: Interface for document parsing drivers
- Filesystem: Interface for filesystem operations
- IdStrategy: Interface for ID generation strategies
CLI Workflow
1. Scan Views
Extract translatable strings from your Blade templates:
2. Build Translations
Generate translations for target locales:
3. Apply Translations
Translations are automatically applied via middleware during web requests.
Configuration
The library accepts configuration arrays for:
- ID Strategy: Choose between hash, tag_path, or explicit
- Translation Driver: Select Google, Groq, or Cerebras
- API Keys: Configure API credentials for translation services
- Paths: Specify views and indexes directory paths
Testing
Run the test suite:
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions, please use the GitHub issue tracker.
For security issues, please see SECURITY.md.
Related Packages
- volcy/translator-laravel - Laravel integration
- volcy/translator-flight - FlightPHP integration
All versions of translator-core with dependencies
ext-dom Version *
ext-json Version *
ext-curl Version *
ext-mbstring Version *