Download the PHP package blackstone/laravel-model-translations-sync without Composer
On this page you can find all versions of the php package blackstone/laravel-model-translations-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blackstone/laravel-model-translations-sync
More information about blackstone/laravel-model-translations-sync
Files in blackstone/laravel-model-translations-sync
Package laravel-model-translations-sync
Short Description Synchronize Laravel model translations between models, language_lines, files and external translation flows.
License MIT
Informations about the package laravel-model-translations-sync
blackstone/laravel-model-translations-sync
Laravel package for synchronizing translations between:
- translatable Eloquent model JSON attributes via
spatie/laravel-translatable language_linesviaspatie/laravel-translation-loader- local Laravel
langfiles - external translation services such as Crowdin, Lokalise or custom project commands
Pipeline target:
Models -> DB (language_lines) -> external service -> DB -> Models -> Files
Requirements
- PHP 8.3, 8.4+
- Laravel 11 or 12
spatie/laravel-translatablespatie/laravel-translation-loader
Installation
Publish config:
Model setup
Add HasTranslations from Spatie and the package trait:
Default behavior:
getModelTranslationNamespace()returns snake_case model basenamegetTranslatableAttributesForSync()returns$this->translatable
You can override both methods in the model if needed.
Storage format in language_lines
Model translations are stored as:
group = models.{namespace}key = {id}.{attribute}text = {"en":"...", "fr":"..."}
Example:
Configuration
Published config file: config/model-translations.php
Main options:
models.auto_discover: discover models from configured pathsmodels.paths: directories for model discoverymodels.list: explicit model class listmodels.namespace_map: manual namespace to model mappinglocales: supported locales for syncdefault_locale: fallback localeignore_groups: groups ignored during file exportexport_path: destination for generated lang filesexport.overwrite,export.pretty_print,export.sort_keyssync.stop_on_error: stop or continue when a pipeline step failssync.pipeline: ordered list of artisan commands for the sync pipeline
Commands
Export models to language_lines:
Import model translations from language_lines:
Export DB translations to local files:
Import local files back into DB:
Run the full pipeline:
Pipeline is config-driven. Example:
translations:sync executes enabled commands in order, warns about missing or failing steps, and stops only when sync.stop_on_error is true.
Generating translatable JSON migrations
The package can generate a snapshot-based Laravel migration for safely converting existing scalar/text translatable columns into JSON columns without runtime model scanning inside the migration.
Available options:
The command:
- discovers models using
Spatie\Translatable\HasTranslations - filters only real DB columns
- writes a fixed snapshot of models, tables, primary keys and translatable attributes
- generates a self-contained migration in
database/migrations
The generated migration:
- creates
__json_tmpcolumns inup() - wraps old scalar values as
{"<locale>":"value"} - renames temp JSON columns back to the original names
- restores values back to
textcolumns indown()using the chosen locale
Source of truth
translations:export-models: models are source of truthtranslations:import-models:language_linesis source of truthtranslations:export-files:language_linesis source of truthtranslations:import-files: lang files are source of truth
File formats
Supported export/import targets:
resources/lang/{locale}/*.phpresources/lang/{locale}.jsonresources/lang/{locale}/models.php
Model translations in models.php are structured as:
Testing
All versions of laravel-model-translations-sync with dependencies
illuminate/contracts Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/filesystem Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
spatie/laravel-translatable Version ^6.11
spatie/laravel-translation-loader Version ^2.8