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

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

philipp15b/php-i18n
===================

Simple i18n class for PHP

v4.0.1(8y ago)320124.4k—1.6%110[9 issues](https://github.com/Philipp15b/php-i18n/issues)[2 PRs](https://github.com/Philipp15b/php-i18n/pulls)5MITPHPPHP &gt;= 5.3

Since Feb 12Pushed 2y ago24 watchersCompare

[ Source](https://github.com/Philipp15b/php-i18n)[ Packagist](https://packagist.org/packages/philipp15b/php-i18n)[ Docs](https://github.com/Philipp15b/php-i18n)[ RSS](/packages/philipp15b-php-i18n/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (5)

PHP i18n
========

[](#php-i18n)

[![Latest Stable Version](https://camo.githubusercontent.com/12b433428081311a8dec6d99427fa9213863a2b6a62009b3fa535f9a9b49d4fe/68747470733a2f2f706f7365722e707567782e6f72672f7068696c6970703135622f7068702d6931386e2f762f737461626c65)](https://packagist.org/packages/philipp15b/php-i18n) [![Build Status](https://camo.githubusercontent.com/77012901c1ee76ece58e95ea131b6dc2a27d76e1b5c7c39dc66dbee793ee9002/68747470733a2f2f7472617669732d63692e6f72672f5068696c6970703135622f7068702d6931386e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Philipp15b/php-i18n)

This is a simple i18n class for PHP. Nothing fancy, but fast, because it uses caching and it is easy to use. Try it out!

Some of its features:

- Translation strings in `.ini`/`.properties`, `.json` or `.yaml` format
- Caching
- Simple API: `L::category_stringname`
- Built-in support for [vsprintf](http://php.net/manual/en/function.vsprintf.php) formatting: `L::name($par1)`
- Automatic user language detection
- Simplicity ;)

Requirements
------------

[](#requirements)

- Write permissions in cache directory
- PHP 5.2 and above
- PHP SPL extension (installed by default)

Setup
-----

[](#setup)

There's a usable example in the `example.php` file. You just have to follow these easy five steps:

### 1. Create language files

[](#1-create-language-files)

To use this class, you need to create translation files with your translated strings. They can be `.ini`/`.properties`, `.json` or `.yaml` files. This could look like this:

`lang_en.ini` (English)

```
greeting = "Hello World!"

[category]
somethingother = "Something other..."
```

`lang_de.ini` (German)

```
greeting = "Hallo Welt!"

[category]
somethingother = "Etwas anderes..."
```

Save both files in the directory you will set in step 4. The files must be named according to the filePath setting, where '{LANGUAGE}' will be replaced by the user's language, e.g. 'en' or 'de'.

### 2. Include the class

[](#2-include-the-class)

```

```

### 3. Initialize the class

[](#3-initialize-the-class)

```

```

### 4. Set some settings if necessary

[](#4-set-some-settings-if-necessary)

The possible settings are:

- Language file path (default: `./lang/lang_{LANGUAGE}.ini`)
- Cache file path (default: `./langcache/`)
- Preserve language region variants: if set to true, region variants in language code strings such as en-us and en-gb will be preserved, otherwise will be trimmed to en (default: `false`)
- The fallback language, if no one of the user languages is available (default: `en`)
- A 'prefix', the compiled class name (default `L`)
- A forced language, if you want to force a language (default: none)
- The section separator: this is used to seperate the sections in the language class. If you set the separator to `_abc_` you could access your localized strings via `L::category_abc_stringname` if you use categories in your ini. (default: `_`)
- Merge keys from the fallback language into the current language

```
