PHPackages                             o80/i18n - 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. o80/i18n

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

o80/i18n
========

Easy library to manage i18n with PHP.

0.4(10y ago)1131.2k↓33.3%5[2 PRs](https://github.com/olivierperez/o80-i18n/pulls)Apache License 2.0PHPPHP &gt;=5.3.0CI failing

Since Mar 19Pushed 3y ago3 watchersCompare

[ Source](https://github.com/olivierperez/o80-i18n)[ Packagist](https://packagist.org/packages/o80/i18n)[ Docs](https://github.com/olivierperez/o80-i18n)[ RSS](/packages/o80-i18n/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

o80-i18n
========

[](#o80-i18n)

**o80-i18n** is a small PHP tool to manage i18n (internationalization). By default it uses `json` format for language files, you can define your own provider if you prefer another format. See below how the usage is simple.

[![Build Status](https://camo.githubusercontent.com/8b5d1cc8519a902982234fe188bfe8581e70c73fc3c82f665defbad6fd69547b/68747470733a2f2f7472617669732d63692e6f72672f6f6c6976696572706572657a2f6f38302d6931386e2e737667)](https://travis-ci.org/olivierperez/o80-i18n)[![Latest Unstable Version](https://camo.githubusercontent.com/4210fb845d4897f6ffeb5399e6478441d089651ca44f4ecdacdbe3221f6b0a91/68747470733a2f2f706f7365722e707567782e6f72672f6f38302f6931386e2f762f756e737461626c652e737667)](https://packagist.org/packages/o80/i18n)[![License](https://camo.githubusercontent.com/61790e820f426fbcfb49fbfce4403c116667e94d2be94978670bc1a0c7881cd0/68747470733a2f2f706f7365722e707567782e6f72672f6f38302f6931386e2f6c6963656e73652e737667)](https://tldrlegal.com/l/apache2)

How-to
======

[](#how-to)

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

[](#installation)

With [Composer](http://getcomposer.org/), you simply need to require [`o80/i18n`](https://packagist.org/packages/o80/i18n):

```
{
...
    "require": {
        "o80/i18n": "~0.2"
    }
...
}
```

Usage
-----

[](#usage)

### Dictionaries

[](#dictionaries)

For instance, put your language files in 'lang' directory :

- `langs`
    - `en.json`
    - `en_US.json`
    - `fr.json`

Example of language file `en.json` :

```
{
    "Generic" : {
        "Welcome": "Welcome",
        "Hello": "Hello %s!",
        "submit": "submit"
    }
}
```

Example of language file `fr.json` :

```
{
    "Generic" : {
        "Welcome": "Bienvenue",
        "Hello": "Bonjour %s !",
        "submit": "valider"
    }
}
```

### Configure the i18n instance

[](#configure-the-i18n-instance)

#### Way 1 - Singleton

[](#way-1---singleton)

```
$i18n = I18N::instance();
$i18n->setPath(__DIR__ . '/langs');
$i18n->setDefaultLang('en');
```

#### Way 2 - New instance

[](#way-2---new-instance)

```
$i18n = new I18N();
$i18n->setPath(__DIR__ . '/langs');
$i18n->setDefaultLang('en');
```

### Usage

[](#usage-1)

#### Way 1 - Singleton

[](#way-1---singleton-1)

```
