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 [
    'keyDelimiter' => '.',          // Separator used in nested translation keys

    'fileNames' => ['messages'],    // PHP file names to sync (without .php extension)
    'locales'   => ['en', 'it'],    // Supported locales

    // Default import/export direction
    'defaultImportFrom' => TranslationOptions::PHP,
    'defaultImportTo'   => TranslationOptions::DB,
    'defaultExportFrom' => TranslationOptions::DB,
    'defaultExportTo'   => TranslationOptions::PHP,

    'phpPath'      => lang_path(),          // Path to PHP language files
    'csvDelimiter' => ';',                  // CSV column delimiter
    'csvFileName'  => 'translations',       // Default CSV file name
    'csvPath'      => storage_path('lang'), // Directory for CSV files
    'jsonPath'     => lang_path(),          // Path to JSON language files
];
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 php db

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