PHP code example of kg-bot / laravel-localization-to-vue

1. Go to this page and download the library: Download kg-bot/laravel-localization-to-vue 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/ */

    

kg-bot / laravel-localization-to-vue example snippets


KgBot\LaravelLocalization\LaravelLocalizationServiceProvider::class

"ExportLocalization" => "KgBot\\LaravelLocalization\\Facades\\ExportLocalizations"

php artisan vendor:publish --provider="KgBot\LaravelLocalization\LaravelLocalizationServiceProvider" --tag=config

paths => [lang_path(), app_path('lang'), app_path('Modules/Blog/lang')]

// helpers/functions.php

if (! function_exists('testExport')) {
    /**
     * Change all instances of :argument to {argument}
     *
     * @param $string
     * @return void
     *
     */
    function testExport($string) {
        array_walk_recursive($string, function (&$v, $k) { $v = preg_replace('/:(\w+)/', '{$1}', $v); });

        return $string;
    }
}


// composer.json
....
"autoload": {
        "files": [
            "helpers/functions.php"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
....

// config/laravel-localization.php
...
'export_callback' => 'testExport',
...

// inside ServiceProvider

// With alias
use ExportLocalization;

// Without alias
use KgBot\LaravelLocalization\Facades\ExportLocalizations as ExportLocalization;


View::composer( 'view.file', function ( $view ) {

    return $view->with( [
        'messages' => ExportLocalization::export()->toArray(),
    ] );
} );

// Call toFlat() instead of toArray()
ExportLocalization::export()->toFlat()

or

// For CLI usage
php artisan export:messages-flat

` php artisan export:messages