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

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

szakalq/php-i18n
================

PHP Internationalization

56.8kPHP

Since Jan 20Pushed 11y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

### Original project:

[](#original-project-httpsgithubcomphilipp15bphp-i18n)

CHANGE LOG
----------

[](#change-log)

- add composer support
- add autoload spyc library ()
- L:: change to Lang::

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:

- Translations in ini-files
- File caching
- Simple API (`Lang::category_stringname`)
- Automatic finding out what language to use
- Simplicity ;)

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

[](#requirements)

- Write permissions in cache directory
- PHP 5.2 (only tested with this version, it maybe runs with other versions too)
- PHP SPL extension (installed by default)

Install
-------

[](#install)

```
"require": {
    "szakalq/php-i18n": "dev-master"
}
```

Setup
-----

[](#setup)

To use the i18n class, look at the example.php. You will find there a simple tutorial for this class in the file. Otherwise follow these easy five steps:

### 1. Create language files

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

To use this class, you have to use ini files for the translated strings. 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 like the filePath setting, where '{LANGUAGE}' will be replaced by the chosen 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 (the ini files) (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 forced language, if you want to force a language (default: none)
- The ini 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 `Lang::category_abc_stringname` if you use categories in your ini. (default: `_`)

```
