ProductPromotion
Logo

PHP

made by https://0x3d.site

GitHub - cakephp/i18n: [READ-ONLY] Provides support for message translation and localization for dates and numbers. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp
[READ-ONLY] Provides support for message translation and localization for dates and numbers. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp - cakephp/...
Visit Site

GitHub - cakephp/i18n: [READ-ONLY] Provides support for message translation and localization for dates and numbers. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

GitHub - cakephp/i18n: [READ-ONLY] Provides support for message translation and localization for dates and numbers. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

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.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory