LaraTransManager

website·Indexed 30 days ago

https://laratransmanager.netlify.app

A translation management tool for Laravel. Requires PHP 8.2 and Laravel 11.x. Features include a translations dashboard available at the /translations route and configuration options for managing translations.

Tokens
1.4K
Snippets
10
Records
14
Agent score
71%

What's inside LaraTransManager

  1. Overview of LaraTransManager for Laravel

    LaraTransManager is a Laravel package designed to replace the manual editing of Laravel localization files with a centralized management dashboard. It allows developers and staff to manage translations across multiple languages, store them in a database, and utilize caching for performance.
  2. Overview of LaraTransManager for Laravel

    LaraTransManager is a Laravel package designed to replace the manual editing of Laravel localization files with a dedicated management dashboard. It allows developers and administrators to manage translations for multiple languages via a database-backed system, enabling non-technical staff or users to translate website content. Key features include database storage for translations and caching support to maintain performance.
  3. Install LaraTransManager in a Laravel project

    Follow these steps to install LaraTransManager:

    1. Install the package via Composer.
    2. Publish the configuration and migration files using the service provider.
    3. Publish the public assets.
    4. Register the LaraTransManagerServiceProvider in the bootstrap/providers.php file.
    5. Run database migrations.
    6. Initialize and export translations to the database using the laratransmanager:init command.
    # 1. Install package
    composer require soufian212/laratransmanager
    
    # 2. Publish config and migrations
    php artisan vendor:publish --provider="Soufian212\LaraTransManager\LaraTransManagerServiceProvider"
    
    # 3. Publish assets
    php artisan vendor:publish --tag=public --force
    
    # 5. Run migrations
    php artisan migrate
    
    # 6. Initialize translations
    php artisan laratransmanager:init
    // 4. bootstrap/providers.php
    return [
        App\Providers\AppServiceProvider::class,
        Soufian212\LaraTransManager\LaraTransManagerServiceProvider::class,
    ];
  4. Install and configure LaraTransManager

    Follow these steps to install LaraTransManager into your Laravel project:

    1. Install the package via Composer.
    2. Publish the configuration and migration files using the service provider.
    3. Publish the public assets (using --force to ensure they are updated).
    4. Register the LaraTransManagerServiceProvider in your bootstrap/providers.php file.
    5. Run database migrations to create the necessary tables.
    6. Initialize the package and export translations to the database using the laratransmanager:init command.

    Once completed, the translations dashboard is accessible at the /translations URL.

    # 1. Install package
    composer require soufian212/laratransmanager
    
    # 2. Publish config and migrations
    php artisan vendor:publish --provider="Soufian212\LaraTransManager\LaraTransManagerServiceProvider"
    
    # 3. Publish assets
    php artisan vendor:publish --tag=public --force
    
    # 5. Run migrations
    php artisan migrate
    
    # 6. Initialize translations
    php artisan laratransmanager:init
    // 4. Add to bootstrap/providers.php
    return [
        App\Providers\AppServiceProvider::class,
        Soufian212\LaraTransManager\LaraTransManagerServiceProvider::class,
    ];
  5. Enable LaraTransManager dashboard access in production

    The Translations dashboard is located at the /translations route. By default, access is restricted to the local environment. To allow access in production, you must define a custom access callback using the CheckDashboardAccess middleware within the boot method of your AppServiceProvider.
    use Soufian212
    LaraTransManager
    Http
    Middleware
    CheckDashboardAccess;
    
    public function boot(): void
    {
        CheckDashboardAccess::setAccessCallback(function () {
            // Custom logic here (e.g., check if user is admin)
            return true; // Return true to grant access
        });
    }
  6. Configure translation caching in LaraTransManager

    LaraTransManager provides two configuration options to manage translation performance. Enabling cache_translations prevents the application from fetching translations from the database on every request. The cache_lifetime defines how long the translations remain cached in seconds.
    'cache_translations' => true, // Enable caching for better performance
    'cache_lifetime' => 3600,    // Cache duration in seconds
  7. Configure translation caching in LaraTransManager

    LaraTransManager provides two configuration options to manage translation performance. Enabling cache_translations prevents the application from fetching translations from the database on every request, improving performance. The cache_lifetime defines how long the translations remain cached in seconds.
    'cache_translations' => true,
    'cache_lifetime' => 3600,