PHP code example of codewiser / intl

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

    

codewiser / intl example snippets


intl(now())->short();
# 12/13/52 3:30pm

intl(now())->shortDate();
# 12/13/52

intl(now())->full();
# Tuesday, April 12, 1952 AD 3:30:42pm PST

intl(now())->fullTime();
# 3:30:42pm PST

$interval = now()->toPeriod(now()->addHour());
intl($interval)->long();
# January 12, 1952 from 3:30:30pm to 4:30:30pm

use \Illuminate\Database\Eloquent\Model;
use \Codewiser\Intl\Casts\AsMultiLingual;
use \Codewiser\Intl\Traits\HasLocalizations;

/**
 * @property string $name 
 */
class User extends Model
{
    use HasLocalizations;
    
    protected $casts = [
        'name' => AsMultiLingual::class
    ];
}

$user->withLocale('en', fn(User $user) => $user->name = 'Michael');
$user->withLocale('es', fn(User $user) => $user->name = 'Miguel');

$nameInEn = $user->withLocale('en', fn(User $user) => $user->name);
$nameInEs = $user->withLocale('es', fn(User $user) => $user->name);