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\Multilingual;
use Illuminate\Support\Traits\Localizable;

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

// Set value in default locale
$user->name = 'Michael';

// Set value with explicit locale
$user->withLocale('en', fn() => $user->name = 'Michael');
$user->withLocale('es', fn() => $user->name = 'Miguel');

// Set values as array
$user->name = [
    'en' => 'Michael',
    'es' => 'Miguel',
];

// Get value in default locale
$nameInCurrentLocale = (string) $user->name;
$nameInCurrentLocale = $user->name->toString();

// Get value in given locale
$nameInEn = $user->withLocale('en', fn() => $user->name);
$nameInEs = $user->withLocale('es', fn() => $user->name);

// Get all values
$user->name->toArray();