PHP code example of gboquizosanchez / icu-i18n

1. Go to this page and download the library: Download gboquizosanchez/icu-i18n 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/ */

    

gboquizosanchez / icu-i18n example snippets


// config/icu.php

return [
    'regionals' => [
        /*
         * Allowlisted Namespaces.
         * These will use the full regional locale (e.g. es_MX).
         * '*' represents your application's local files (lang/es_MX/...).
         * Vendor packages are excluded by default to prevent missing translation errors.
         */
        'namespaces' => [
            '*',
        ],

        /*
         * Blocklisted Files.
         * These will ALWAYS force the base locale (e.g. es).
         * Useful for standard Laravel files that usually come in generic locale folders.
         */
        'files' => [
            // 'validation',
            // 'auth',
            // 'passwords',
        ],
    ],
];

return [
    'welcome' => 'Hello, {name}.',
    'balance' => 'Your balance is {amount, number, currency}',
    'apples'  => '{count, plural, =0{No apples} one{One apple} other{# apples}}',
    'gender'  => '{gender, select, male{Welcome, sir} female{Welcome, ma\'am} other{Welcome}}',
    'audit'   => '{user} performed an action on {date, date, long}',
];

// lang/ru/messages.php
'items' => 'Dimitri купил {count, plural, one{# товар} few{# товара} other{# товаров}}.',

// lang/ar/messages.php
'products' => '{count, plural, =1{منتج واحد} =2{منتجان} few{# منتجات} many{# منتجاً} other{# منتج}}',

// lang/pl/messages.php
'products' => '{count, plural, one{# produkt} few{# produkty} many{# produktów} other{# produktu}}',

// lang/sl/messages.php
'items' => '{count, plural, one{# izdelek} two{# izdelka} few{# izdelki} other{# izdelkov}}',

$user = new User(['name' => 'Alice']); // implements __toString
$date = new DateTime('2023-10-01');

echo __('messages.audit', ['user' => $user, 'date' => $date]);
// Output (en_US): Alice performed an action on October 1, 2023
// Output (es_ES): Alice realizó una acción el 1 de octubre de 2023
// Output (ar_SA): أجرت Alice إجراءً في ١ أكتوبر ٢٠٢٣
bash
php artisan vendor:publish --provider="Boquizo\IcuI18n\I18nServiceProvider"