PHP code example of m1sh0u / laravel-polyglot-translator

1. Go to this page and download the library: Download m1sh0u/laravel-polyglot-translator 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/ */

    

m1sh0u / laravel-polyglot-translator example snippets


trans('Hello, %{placeholder}', ['placeholder' => 'World']);
trans('1 vote %{period} |||| %{smart_count} votes %{period}', ['smart_count' => 4, 'period' => 'today'])

trans_choice('1 vote %{period} |||| %{smart_count} votes %{period}', 4, ['period' => 'today']);

return [
    // @see https://github.com/M1Sh0u/polyglot.php for the meaning of each polyglot configuration parameter
    'polyglot' => [
        
        'allowMissing' => true,
        'delimiter' => '||||',
        'interpolation' => [
            'prefix' => '%{',
            'suffix' => '}'
        ],
        'pluralRules' => [],

        // Set a callback function to be called whenever a missing key is found.
        // It could be useful if you need to store the missing keys into the database or to do something else.
        // Please note that the return of this callback will be the actual string returned by the translator. @see https://github.com/M1Sh0u/polyglot.php
        'onMissingKey' => null,
        'onMissingKeyEnvs' => ['local', 'staging']
    ]
];

php artisan vendor:publish --provider="LaravelPolyglot\Providers\TranslationServiceProvider" --tag="config"