blendbyte/laravel-crowdin-sync

Syncs Translation Data from Laravel to a Crowdin project and back.

v1.0.3 2025-01-14 07:22 UTC

This package is auto-updated.

Last update: 2025-02-03 11:42:28 UTC


README

  • Automatically syncs your translations files as source to Crowdin and also syncs back translations from Crowdin into your files
  • Can sync custom translatable content (using spatie/laravel-translatable fields) to Crowdin and back into your database
  • Can run as part of a scheduled command to ensure always up2date translations in your database

Installation

You can install the package via composer:

composer require blendbyte/laravel-crowdin-sync

You can publish the config file with:

php artisan vendor:publish --tag="crowdin-sync-config"

This is the contents of the published config file:

return [
    // Crowdin Access Token for the API
    'api_key' => env('CROWDIN_API_KEY'),

    // Project ID for Translation Files (must be "File-based project")
    'project_id_files' => env('CROWDIN_PROJECT_ID_FILES'),

    // Project ID for Content Translations (must be "String-based project")
    'project_id_content' => env('CROWDIN_PROJECT_ID_CONTENT'),

    // File Update Option, choose one of clear_translations_and_approvals, keep_translations, keep_translations_and_approvals
    'file_update_options' => env('CROWDIN_FILE_UPDATE_OPTIONS', 'clear_translations_and_approvals'),

    // Only export approved translations for translation files
    'file_export_approved_only' => env('CROWDIN_FILE_EXPORT_APPROVED_ONLY', true),

    // Content branch ID
    'content_branch_id' => env('CROWDIN_CONTENT_BRANCH_ID', -1),

    // Only apply approved translations to content translations
    'content_approved_only' => env('CROWDIN_CONTENT_APPROVED_ONLY', false),
];

Usage

LaravelCrowdinSync::make()->syncFiles(source_path: 'lang/', crowdin_path: 'laravel/');
LaravelCrowdinSync::make()->uploadFiles(source_path: 'lang/', crowdin_path: 'laravel/');
LaravelCrowdinSync::make()->downloadFiles(source_path: 'lang/', crowdin_path: 'laravel/');
LaravelCrowdinSync::make()->syncContent(\App\Models\Page::class);
LaravelCrowdinSync::make()->uploadContent(\App\Models\Page::class);
LaravelCrowdinSync::make()->downloadContent(\App\Models\Page::class);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.