PHP code example of eklundkristoffer / js-localization

1. Go to this page and download the library: Download eklundkristoffer/js-localization 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/ */

    

eklundkristoffer / js-localization example snippets


    'providers' => [
        /* ... */
        JsLocalization\JsLocalizationServiceProvider::class
    ]



return [
    // Set the locales you use
    'locales' => ['en'],

    // Set the keys of the messages you want to use in javascript
    'messages' => [
        'passwords' => [
            'password', 'user', 'token'
        ]
    ],

    /*
     * in short:
     * 'messages' => ['passwords']
     *
     *
     * you could also use:
     *
     * 'messages' => [
     *     'passwords.password',
     *     'passwords.user',
     *     'passwords.token'
     * ]
     */
     
    // Set the keys of config properties you want to use in javascript.
    // Caution: Do not expose any configuration values that should be kept privately!
    'config' => [
        'app.debug'
    ],
     
    // Disables the config cache if set to true, so you don't have to run `php artisan js-localization:refresh`
    // each time you change configuration files.
    // Attention: Should not be used in production mode due to decreased performance.
    'disable_config_cache' => false,

    // Split up the exported messages.js file into separate files for each locale.
    // This is to ensue faster loading times so one doesn't have to load translations for _all_ languages.
    'split_export_files' => true,
];



use Illuminate\Support\ServiceProvider;
use JsLocalization\Facades\JsLocalizationHelper;

class MyServiceProvider extends ServiceProvider
{
    /* ... */

    public function register()
    {
        Event::listen('JsLocalization.registerMessages', function()
        {
            JsLocalizationHelper::addMessagesToExport([
                // list the keys of the messages here, similar
                // to the 'messages' array in the config file
            ]);
        });
    }

    /* ... */
}

    'split_export_files' => true,