PHPackages                             bakame/laravel-intl-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. bakame/laravel-intl-formatter

ActiveLibrary[Templating &amp; Views](/categories/templating)

bakame/laravel-intl-formatter
=============================

Global helpers for internalization in Laravel application

0.3.0(3y ago)661MITPHPPHP ^7.4 || ^8.0

Since Jun 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/bakame-php/laravel-intl-formatter)[ Packagist](https://packagist.org/packages/bakame/laravel-intl-formatter)[ GitHub Sponsors](https://github.com/sponsors/nyamsprod)[ RSS](/packages/bakame-laravel-intl-formatter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (4)Used By (0)

Laravel Intl Formatter
======================

[](#laravel-intl-formatter)

[![Author](https://camo.githubusercontent.com/8227017ba73e8c0c93fa2c9c653cf702644a5af5d422e7f612b31d45efc180a1/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406e79616d7370726f642d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/nyamsprod)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build](https://github.com/bakame-php/laravel-intl-formatter/workflows/build/badge.svg)](https://github.com/bakame-php/laravel-intl-formatter/actions?query=workflow%3A%22build%22)[![Latest Version](https://camo.githubusercontent.com/9ea8048a0651fe6e303ece63ac3e30f054a2a9624990ef10bd7b1bcf74807a17/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62616b616d652d7068702f6c61726176656c2d696e746c2d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/bakame-php/laravel-intl-formatter/releases)[![Total Downloads](https://camo.githubusercontent.com/ca30e772f0ec236e62cdb97ae8afa71828776ef89f9f8693e15f08a3a04ee26a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62616b616d652f6c61726176656c2d696e746c2d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bakame/laravel-intl-formatter)[![Sponsor development of this project](https://camo.githubusercontent.com/2e662697b46a37233abdd7e45373397aab0bd5206336533151cdf42455d81048/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f72253230746869732532307061636b6167652d2545322539442541342d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://github.com/sponsors/nyamsprod)

This is a Laravel port of the [Twig Intl Extension](https://github.com/twigphp/intl-extra) package.

The package can be used in any Laravel based application to quickly handle internationalization by providing helper functions in Blade templates or Laravel codebase.

System Requirements
-------------------

[](#system-requirements)

- Laravel 8 and/or 9
- Symfony Intl component

Installation
------------

[](#installation)

Use composer:

```
composer require bakame/laravel-intl-formatter

```

Configuration
-------------

[](#configuration)

In order to edit the default configuration you need to publish the package configuration to your application config directory:

```
php artisan vendor:publish --provider="Bakame\Laravel\Intl" --tag=config
```

The configuration file will be published to `config/bakame-intl-formatter.php` in your application directory.

Please refer to the config file for an overview of the available options.

Documentation
-------------

[](#documentation)

Once installed the package provides the following global helper functions:

### Country Name

[](#country-name)

Returns the country name given its two-letter/five-letter code;

```
country name: {{ country_name($country, $locale) }}
```

```
echo view($templatePath, ['country' => 'FR', 'locale' => 'NL'])->render();
// country name: Frankrijk
```

### Currency Name

[](#currency-name)

Returns the currency name given its three-letter code;

```
currency name: {{ currency_name($currency, $locale) }}
```

```
echo view($templatePath, ['currency' => 'JPY', 'locale' => 'PT'])->render();
// currency name: Iene japonês
```

### Currency Symbol

[](#currency-symbol)

Returns the currency symbol given its three-letter code;

```
currency symbol: {{ currency_symbol($currency, $locale) }}
```

```
echo view($templatePath, ['currency' => 'JPY', 'locale' => 'PT'])->render();
// currency symbol: JP¥
```

### Language name

[](#language-name)

Returns the currency symbol given its three-letter code;

```
language name: {{ language_name($language, $locale) }}
```

```
echo view($templatePath, ['language' => 'it', 'locale' => 'nl'])->render();
// language name: Italiaans
```

### Locale name

[](#locale-name)

Returns the currency symbol given its three-letter code;

```
locale name: {{ locale_name($data, $locale) }}
```

```
echo view($templatePath, ['data' => 'sw', 'locale' => 'nl'])->render();
// locale name: Swahili
```

### Timezone name

[](#timezone-name)

Returns the timezone name given its identifier;

```
timezone name: {{ locale_name($data, $locale) }}
```

```
echo view($templatePath, ['timezone' => 'Asia/Tokyo', 'locale' => 'es'])->render();
// timezone name: hora de Japón (Tokio)
```

### Country Timezones

[](#country-timezones)

Returns the timezone identifiers of the given country code;

```
country timezones: {{ implde(", ", country_timezones($country)) }}
```

```
$content = view($templatePath, ['country' => 'CD', 'locale' => 'es'])->render();
echo $content, PHP_EOL; // country timezones: Africa/Kinshasa, Africa/Lubumbashi
```

### Format Currency

[](#format-currency)

Formats a number as a currency;

```
format currency: {{ format_currency($amount, $currency, $attrs, $locale) }}
```

```
$templateData = [
    'amount' => 100.356,
    'currency' => 'USD',
    'locale' => 'ES',
    'attrs' => [
        'fraction_digit' => 1,
        'rounding_mode' => 'floor',
    ]
];
echo view($templatePath, $templateData)->render();
// format currency: 100,3 US$
```

### Format Number

[](#format-number)

Formats a number;

```
format number: {{ format_number($number, $locale, $attrs) }}
```

```
$templateData = [
    'number' => 100.356,
    'locale' => 'nl',
    'style' => 'spellout',
    'type' => 'double',
    'attrs' => [
        'fraction_digit' => 1,
        'rounding_mode' => 'floor',
    ]
];
echo view($templatePath, $templateData)->render();
// format number: honderd komma drie
```

### Format DateTime

[](#format-datetime)

Formats a date and time;

```
format datetime: {{ format_datetime($date, $locale, $timezone, $dateFormat, $timeFormat, $pattern, $calendar) }}
```

```
$templateData = [
    'date' => 'yesterday',
    'dateFormat' => 'full',
    'timeFormat' => 'full',
    'pattern' => '' ,
    'timezone' => 'Africa/Lubumbashi',
    'calendar' => 'gregorian' ,
    'locale' => 'sw',
];
echo view($templatePath, $templateData)->render();
// format datetime: Alhamisi, 2 Juni 2022 00:00:00 Saa za Afrika ya Kati
```

### Format Date

[](#format-date)

Formats a the date portion of a datetime;

```
format date: {{ format_date($date, $locale, $timezone, $dateFormat, $pattern, $calendar) }}
```

```
$templateData = [
    'date' => 'yesterday',
    'dateFormat' => 'long',
    'pattern' => '' ,
    'timezone' => 'Africa/Lubumbashi',
    'calendar' => 'gregorian' ,
    'locale' => 'sw',
];
echo view($templatePath, $templateData)->render();
// format date: 2 Juni 2022
```

### Format Time

[](#format-time)

Formats the time portion of a datetime;

```
format time: {{ format_time($date, $locale, $timezone, $timeFormat, $pattern, $calendar) }}
```

```
$templateData = [
    'date' => 'yesterday',
    'dateFormat' => 'full',
    'pattern' => '' ,
    'timezone' => 'Africa/Lubumbashi',
    'calendar' => 'gregorian' ,
    'locale' => 'sw',
];
echo view($templatePath, $templateData)->render();
// format time: 00:00:00 Saa za Afrika ya Kati
```

Each function uses the same arguments in the same order as the Twig Extra package filters/functions.

### Locale specification

[](#locale-specification)

If no `locale` is specified in function calls, the function will use the result of `Illuminate\Support\Facades\App::currentLocale()`as the locale value to use.

### functions signature

[](#functions-signature)

In PHP8+, you can use named parameters to improve functions usages as they tend to have a lot of arguments:

**In PHP7.4**

```
