PHP code example of brunoscode / twill-translation-handler

1. Go to this page and download the library: Download brunoscode/twill-translation-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brunoscode / twill-translation-handler example snippets


'legacy-twill-navigation' => false,

use A17\Twill\Facades\TwillNavigation;
use A17\Twill\View\Components\Navigation\NavigationLink;

TwillNavigation::addLink(
    NavigationLink::make()->title('Translations')
        ->forModule('translations')
        ->doNotAddSelfAsFirstChild()
        ->setChildren([
            NavigationLink::make()->title('Translations')->forModule('translations'),
            NavigationLink::make()->title('Groups')->forModule('translationGroups'),
            NavigationLink::make()->title('Import / Export')->forRoute('twill.translations.translationTools.index'),
        ])
);

NavigationLink::make()->title('Import / Export')
    ->forRoute(config('twill.admin_route_name_prefix', 'twill.') . 'translations.translationTools.index'),

// config/twill-navigation.php

return [
    'dashboard' => [
        'title' => 'Dashboard',
        'route' => 'admin.dashboard',
    ],

    // Placeholder — position is preserved, structure is filled in by the package
    'translations' => [],

    'pages' => [
        'title' => 'Pages',
        'route' => 'admin.pages.index',
    ],
];

// config/translation-handler.php

return [
    'legacy-twill-navigation' => true,  // Register the menu via twill-navigation (see Navigation)

    'keyDelimiter' => '.',              // Separator used in nested translation keys

    'fileNames' => ['messages'],        // Lang files managed from the admin (without .php)
    'locales'   => ['en', 'it'],        // Locales exported to the lang files

    // The database is the source of truth
    'defaultImportFrom' => TranslationOptions::PHP,
    'defaultImportTo'   => TranslationOptions::DB,
    'defaultExportFrom' => TranslationOptions::DB,
    'defaultExportTo'   => TranslationOptions::PHP,

    'dbHandlerClass' => DatabaseHandler::class, // Twill handler: also creates the groups

    'phpPath'           => lang_path(),          // Path to PHP language files
    'csvDelimiter'      => ';',                  // Default CSV column delimiter
    'csvEscapeFormulas' => true,                 // Neutralise spreadsheet formulas in CSV exports
    'csvFileName'       => 'translations',       // Download name of the admin CSV export
    'csvPath'           => storage_path('lang'), // Must be writable by the web server
    // ... plus the JSON and `check` options of the core
];
bash
php artisan migrate
bash
php artisan vendor:publish --tag="twill-translation-handler-config"
bash
php artisan vendor:publish --tag="twill-translation-handler-views"
bash
php artisan migrate

# Add new keys and locales from PHP files to the DB, without overwriting existing DB values
php artisan translation-handler:sync php db

# Overwrite PHP files with the authoritative DB values
php artisan translation-handler:sync db php --force
bash
> php artisan translation-handler:sync php db --force
> 
bash
php artisan translation-handler:sync csv php --force