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

ActiveLibrary

jeriveromartinez/php-i18n
=========================

Simple i18n class for PHP

3.1.1(8y ago)161CC BY-SA 3.0PHP

Since Feb 12Pushed 8y ago2 watchersCompare

[ Source](https://github.com/jeriveromartinez/php-i18n)[ Packagist](https://packagist.org/packages/jeriveromartinez/php-i18n)[ Docs](https://github.com/jeriveromartinez/php-i18n)[ RSS](/packages/jeriveromartinez-php-i18n/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (4)Used By (0)

PHP i18n
========

[](#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/`)
- 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 seperator: this is used to seperate the sections in the language class. If you set the seperator 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

```
