PHPackages                             atelierspierrot/internationalization - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. atelierspierrot/internationalization

AbandonedArchivedLibrary[Localization &amp; i18n](/categories/localization)

atelierspierrot/internationalization
====================================

A PHP package to manage i18n: translations, pluralization and date formats according to a localization.

v1.1.0(11y ago)23672Apache-2.0PHPPHP &gt;=5.3.0

Since Oct 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/atelierspierrot/internationalization)[ Packagist](https://packagist.org/packages/atelierspierrot/internationalization)[ Docs](http://github.com/atelierspierrot/internationalization)[ RSS](/packages/atelierspierrot-internationalization/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelogDependencies (6)Versions (7)Used By (2)

Internationalization
====================

[](#internationalization)

[![demonstration](https://camo.githubusercontent.com/860c4e475d63ab920a51c3ea609b93e1a512859be6af45734514ca88d6fbc879/687474703a2f2f696d672e6174656c696572732d70696572726f742d7374617469632e66722f7365652d7468652d64656d6f2e737667)](http://sites.ateliers-pierrot.fr/internationalization/)[![documentation](https://camo.githubusercontent.com/be7adb4ffdc11ba4b480fe936a1e0d23e2c6b3a70ffea72fa4004a30e74e1bae/687474703a2f2f696d672e6174656c696572732d70696572726f742d7374617469632e66722f726561642d7468652d646f632e737667)](http://docs.ateliers-pierrot.fr/internationalization/)[![Code Climate](https://camo.githubusercontent.com/944c672c277723c76205bd78d5e42bd98d4e2abb032d5a3f9326c51931b404fd/687474703a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6174656c6965727370696572726f742f696e7465726e6174696f6e616c697a6174696f6e2f6261646765732f6770612e737667)](http://codeclimate.com/github/atelierspierrot/internationalization)

A PHP package to manage i18n: translations, pluralization, date and number formatting according to a localization.

Usage
-----

[](#usage)

### Object creation and PHP usage

[](#object-creation-and-php-usage)

To create a new I18n instance, you need to pass it a `I18n\Loader` object:

```
// Creation of the I18n Loader
$i18n_loader = new \I18n\Loader(array(

    // this is the directory where your language strings are defined
    'language_directory' => __DIR__.'/i18n',

    // this is the list of available languages
    'available_languages' => array(
        'en' => 'en_US_USD',
        'gb' => 'en_GB_UKP',
        'fr' => 'fr_FR_EUR'
    ),
    'default_language' => 'en',

    // this is the tag construction used for replacements in strings
    // by default, "%arg%" will be replacement by the argument "arg" value
    // as this will be passed to a 'sprintf' PHP function, literal percent is written '%%'
    'arg_wrapper_mask' => "%%%s%%",
));

// Creation of the I18n instance (statically) passing it the Loader
$translator = \I18n\I18n::getInstance($i18n_loader);
```

For a full list of possible Loader options, please have a look in source code.

Any option value defining a directory path or a filename construction can contains a `%s`tag that will be replaced by the current language.

```
// for instance:
'language_directory' => __DIR__.'/i18n/%s'

// will render, for the EN language:
'language_directory' => __DIR__.'/i18n/EN'
```

As you can see, the I18n class is defined as a Singleton object: any future call of `\I18n\I18n::getInstance()` will refer to the first created object instance.

Then, to actually use the translated value of a string, use the `translate` method:

```
$translator->translate( 'string_index' [, array( arguments )] [, language code] )
```

You can use the `pluralize` method to choose a translated string depending on a number of items:

```
$indexes = array(
    0=>'test_item_zero',
    1=>'test_item_one',
    2=>'test_item_two',
    3=>'test_item_multi'
);
$translator->pluralize( $indexes, $number_of_items [, array( arguments )] [, language code] )
```

### Translation strings definition

[](#translation-strings-definition)

By default (this can be over-write in the Loader), the I18n object will load the strings defined as a PHP array like:

```
$i18n_en = array (
  'datetime_mask' => '%a %e %m %Y %H:%M:%S',
  'test' => 'Test in english',
  'test_args' => 'I received arguments : « %arg1% » and « %arg2% »',
  'test_item_zero' => 'No item',
  'test_item_one' => 'Just one item',
  'test_item_two' => 'Two items',
  'test_item_multi' => 'There are %nb% items',
);
```

This may be defined in a file called `i18n.CODE.php` where `CODE` is the two letter reference of the language. These files will be searched and loaded from the `language_directory` loader option value.

### Load multiple language files

[](#load-multiple-language-files)

The I18n object is designed to be able to load multiple language files easily with:

```
$i18n->loadFile( my file path )
```

Each file loaded is stored in the internal cache system of the object (a simple PHP array).

### Package aliases

[](#package-aliases)

A set of aliases functions, defined in the global namespace, are available and auto-loaded by Composer:

```
function _T(...) = $i18n->translate(...)
#    or
function translate(...) = $i18n->translate(...)

function _P(...) = $i18n->pluralize(...)
#    or
function pluralize(...) = $i18n->pluralize(...)

function _D(...) = $i18n->getLocalizedDateString(...)
#    or
function datify(...) = $i18n->getLocalizedDateString(...)
```

Extensions
----------

[](#extensions)

The package embeds an extension to use the class in [the Twig template engine](http://twig.sensiolabs.org/). See the [Twig Extension page](TwigExtension.md) for more infos.

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

[](#installation)

For a complete information about how to install this package and load its namespace, please have a look at [our *USAGE* documentation](http://github.com/atelierspierrot/atelierspierrot/blob/master/USAGE.md).

If you are a [Composer](http://getcomposer.org/) user, just add the package to the requirements of your project's `composer.json` manifest file:

```
"atelierspierrot/internationalization": "@stable"
```

You can use a specific release or the latest release of a major version using the appropriate [version constraint](http://getcomposer.org/doc/01-basic-usage.md#package-versions).

Please note that this package depends on the externals [PHP Patterns](http://github.com/atelierspierrot/patterns)and [PHP Library](http://github.com/atelierspierrot/library).

Author &amp; License
--------------------

[](#author--license)

> Internationalization

>

> Copyright (c) 2010-2016, Pierre Cassat and contributors

> Licensed under the Apache 2.0 license.

>

> ---

> Les Ateliers Pierrot - Paris, France

>  -

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~126 days

Total

5

Last Release

4084d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bdcad88f9577d45da703864395c687480896a757e90978502b600d9dd588c247?d=identicon)[picas](/maintainers/picas)

---

Top Contributors

[![e-picas](https://avatars.githubusercontent.com/u/1021199?v=4)](https://github.com/e-picas "e-picas (90 commits)")

---

Tags

localizationinternationalizationi18n

### Embed Badge

![Health badge](/badges/atelierspierrot-internationalization/health.svg)

```
[![Health](https://phpackages.com/badges/atelierspierrot-internationalization/health.svg)](https://phpackages.com/packages/atelierspierrot-internationalization)
```

###  Alternatives

[symfony/intl

Provides access to the localization data of the ICU library

2.6k199.8M1.1k](/packages/symfony-intl)[gettext/languages

gettext languages with plural rules

7530.3M10](/packages/gettext-languages)[aplus/language

Aplus Framework Language Library

2351.7M15](/packages/aplus-language)[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[aura/intl

The Aura Intl package provides internationalization tools, specifically message translation.

898.3M4](/packages/aura-intl)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
