PHPackages                             michaelspiss/translation - 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. michaelspiss/translation

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

michaelspiss/translation
========================

A file based translation component without dependencies.

v0.1.4(8y ago)024MITPHPPHP &gt;=7.0

Since Aug 17Pushed 7y ago1 watchersCompare

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

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

Translation
===========

[](#translation)

A file based translation component without dependencies.

[![Build Status](https://camo.githubusercontent.com/495a81e44c02c3fa50a2ee9ec2a2a3bdf47d7ba2b4b781779196147e7c82d9b1/68747470733a2f2f7472617669732d63692e6f72672f6d69636861656c73706973732f7472616e736c6174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/michaelspiss/translation)[![Coverage Status](https://camo.githubusercontent.com/2a43c90cd2030d6dc94210bfeaafba9c521977bc2ea86c40d3302f5e75e6f891/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d69636861656c73706973732f7472616e736c6174696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/michaelspiss/translation?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/13814d83a4ebc9d022c99845e00393a0f277687b533c07ec41244eed0c37c3d7/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c73706973732f7472616e736c6174696f6e2f762f737461626c65)](https://packagist.org/packages/michaelspiss/translation)[![License](https://camo.githubusercontent.com/5b77641e9d35a3cf095e0462ebada77df17e026dfede31e0ef5e542de44cc7ca/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c73706973732f7472616e736c6174696f6e2f6c6963656e7365)](https://packagist.org/packages/michaelspiss/translation)

It supports **every file format** you throw at it, **pluralization**, **placeholders**, is **fully tested** and **documented**.

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

[](#installation)

To install the package with Composer, simply run the following command:

```
$ composer require michaelspiss/translation

```

Basic usage
-----------

[](#basic-usage)

Instantiating a new Translator is easy: Simply pass it the default locale ('en' in this case) and the path to your translations directory!

```
require 'vendor/autoload.php'; // composer autoloader

use MichaelSpiss\Translation\Translator;

$translator = new Translator('en', 'path/to/translations');
```

The component uses keys in the dot-notation to identify which string to load. To get a string in a specific language use the trans() method and pass it the key:

```
$translator->trans('message.hello_world');
```

In this case the string would be found in `path/to/translations/en/message.php`. The file itself would look like "message.php" below.

Folder structure
----------------

[](#folder-structure)

Language strings are stored in files in the directory you passed the Translator during initialization. Within this directory each subfolder represents a supported language and holds the translation files.

```
translations/
 |- en/
 |   |- message.php
 |- de/
 |- fr/

```

A translation file would simply look like the following:

###### message.php

[](#messagephp)

```
