Provides support for message translation and localization for dates and numbers.

Related tags

Localization i18n
Overview

Total Downloads License

CakePHP Internationalization Library

The I18n library provides a I18n service locator that can be used for setting the current locale, building translation bundles and translating messages.

Additionally, it provides the Time and Number classes which can be used to output dates, currencies and any numbers in the right format for the specified locale.

Usage

Internally, the I18n class uses Aura.Intl. Getting familiar with it will help you understand how to build and manipulate translation bundles, should you wish to create them manually instead of using the conventions this library uses.

Setting the Current Locale

use Cake\I18n\I18n;

I18n::setLocale('en_US');

Setting path to folder containing po files.

use Cake\Core\Configure;

Configure::write('App.paths.locales', ['/path/with/trailing/slash/']);

Please refer to the CakePHP Manual for details about expected folder structure and file naming.

Translating a Message

echo __(
    'Hi {0,string}, your balance on the {1,date} is {2,number,currency}',
    ['Charles', '2014-01-13 11:12:00', 1354.37]
);

// Returns
Hi Charles, your balance on the Jan 13, 2014, 11:12 AM is $ 1,354.37

Creating Your Own Translators

use Cake\I18n\I18n;
use Cake\I18n\Package;

I18n::translator('animals', 'fr_FR', function () {
    $package = new Package(
        'default', // The formatting strategy (ICU)
        'default', // The fallback domain
    );
    $package->setMessages([
        'Dog' => 'Chien',
        'Cat' => 'Chat',
        'Bird' => 'Oiseau'
        ...
    ]);

    return $package;
});

I18n::getLocale('fr_FR');
__d('animals', 'Dog'); // Returns "Chien"

Formatting Time

$time = Time::now();
echo $time; // shows '4/20/14, 10:10 PM' for the en-US locale

Formatting Numbers

echo Number::format(100100100);
echo Number::currency(123456.7890, 'EUR');
// outputs €123,456.79

Documentation

Please make sure you check the official I18n documentation.

The documentation for the Time class contains instructions on how to configure and output time strings for selected locales.

The documentation for the Number class shows how to use the Number class for displaying numbers in specific locales.

You might also like...
Laravel translation made __('simple').
Laravel translation made __('simple').

Translation.io client for Laravel 5.5+/6/7/8 Add this package to localize your Laravel application. Use the official Laravel syntax (with PHP or JSON

Manage Laravel translation files
Manage Laravel translation files

Laravel 5 Translation Manager For Laravel 4, please use the 0.1 branch! This is a package to manage Laravel translation files. It does not replace the

A GUI for managing JSON translation files in your laravel projects.
A GUI for managing JSON translation files in your laravel projects.

Laravel Language Manager Langman is a GUI for managing your JSON language files in a Laravel project. Installation Begin by installing the package thr

A Gui To Manage Laravel Translation Files
A Gui To Manage Laravel Translation Files

Lingo A file based translation manager, which unlike other Lang managers don't need a database connection to handle the translation. Installation comp

Official PHP library for the DeepL language translation API.

deepl-php Official PHP client library for the DeepL API. The DeepL API is a language translation API that allows other computer programs to send texts

French-Traduction-Pterodactyl est la traduction française de pterodactyl French-Traduction-Pterodactyl is the French translation of pterodactyl

French-Traduction-Pterodactyl Star French-Traduction-Pterodactyl est la traduction française de pterodactyl French-Traduction-Pterodactyl is the Frenc

Translation (i18n) Manager as a virion

TL Translation (i18n) Manager as a virion Translation use hook-like $t = $tl-useTranslation($player-getLocale()); $player-sendMessage($t("message-k

Composer package providing translation features for PHP apps

PHP translation This is a composer package providing translation support for PHP applications. It is similar to gettext, in usage, with these differen

Easy multilingual urls and redirection support for the Laravel framework

Linguist - Multilingual urls and redirects for Laravel This package provides an easy multilingual urls and redirection support for the Laravel framewo

Owner
CakePHP
CakePHP
Weblate translation provider for Symfony Translation.

Weblate Translation Provider This bundle provides a Weblate integration for Symfony Translation. Installation composer require m2mtech/weblate-transla

Martin Mandl 8 Sep 20, 2022
Internationalization tools, particularly message translation.

Aura.Intl The Aura.Intl package provides internationalization (I18N) tools, specifically package-oriented per-locale message translation. Installation

Aura for PHP 86 Dec 18, 2022
🗓 A library to help you work with dates in multiple languages, based on Carbon.

Date This date library extends Carbon with multi-language support. Methods such as format, diffForHumans, parse, createFromFormat and the new timespan

Jens Segers 1.8k Dec 30, 2022
Easy localization for Laravel

Laravel Localization Easy i18n localization for Laravel, an useful tool to combine with Laravel localization classes. The package offers the following

Marc Cámara 3k Jan 4, 2023
A self-hosting localization tool

Localiser A self-hosting localization tool. Requirements PHP ^7.3 Usage Fetch cached locales GET

Memo Chou 6 Mar 10, 2022
Brings localization feature to tightenco/jigsaw using JSON files

Jigsaw localization Brings localization feature to tightenco/jigsaw using JSON files. Get started Setup Bring jigsaw-localization to your Jigsaw proje

Elaborate Code 6 Nov 1, 2022
The Translation component provides tools to internationalize your application.

Translation Component The Translation component provides tools to internationalize your application. Getting Started $ composer require symfony/transl

Symfony 6.4k Jan 6, 2023
Filament Translations - Manage your translation with DB and cache

Filament Translations Manage your translation with DB and cache, you can scan your languages tags like trans(), __(), and get the string inside and tr

Fady Mondy 32 Nov 28, 2022
Better translation management for Laravel

Better localization management for Laravel Introduction Keeping a project's translations properly updated is cumbersome. Usually translators do not ha

Waavi 354 Dec 18, 2022
[virion] Language management library for automatic translation

libtranslator :: library for automatic translation ✔️ Multilingual support for plugin messages ✔️ Translation language is set according to the player

PocketMine-MP projects of PresentKim 5 Jul 29, 2022