PHPackages                             davidecesarano/embryo-translate - 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. davidecesarano/embryo-translate

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

davidecesarano/embryo-translate
===============================

PHP library that provides a simple way to retrieve strings in various languages.

110811PHP

Since Feb 5Pushed 6y ago2 watchersCompare

[ Source](https://github.com/davidecesarano/Embryo-Translate)[ Packagist](https://packagist.org/packages/davidecesarano/embryo-translate)[ RSS](/packages/davidecesarano-embryo-translate/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (1)

Embryo Translate
================

[](#embryo-translate)

PSR compatible PHP library that provides a simple way to retrieve strings in various languages.

Requirement
-----------

[](#requirement)

- PHP &gt;= 7.1
- A [PSR-7](https://www.php-fig.org/psr/psr-7/) http message implementation and [PSR-17](https://www.php-fig.org/psr/psr-17/) http factory implementation (ex. [Embryo-Http](https://github.com/davidecesarano/Embryo-Http))
- A [PSR-15](https://www.php-fig.org/psr/psr-15/) http server request handlers implementation (ex. [Embryo-Middleware](https://github.com/davidecesarano/Embryo-Middleware))
- A PSR-15 session middleware (Ex. [Embryo-Session](https://github.com/davidecesarano/Embryo-Session))
- A PSR response emitter (ex. [Embryo-Emitter](https://github.com/davidecesarano/Embryo-Emitter))

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

[](#installation)

Using Composer:

```
$ composer require davidecesarano/embryo-translate

```

Example
-------

[](#example)

You may quickly test this using the built-in PHP server going to .

```
$ cd example
$ php -S localhost:8000

```

Usage
-----

[](#usage)

### Create and set messages from files

[](#create-and-set-messages-from-files)

You may store language strings in files within, for example, lang directory. Within this directory there should be a subdirectory for each language supported by the application:

```
/lang
    /en
        messages.php
    /it
        messages.php

```

All language files return an array of keyed strings. For example:

```
return [
    'hello' => 'Hello World!'
];
```

Create a `Translate` object and pass it the language directory path and the default language. The `setMessages` method creates an array with all messages.

```
$translate = new Translate('/path/lang', 'en');
$translate->setMessages();
```

### Set the locale

[](#set-the-locale)

Store the default language in `Embryo\Translate\Middleware\SetLocaleMiddleware`. You may also change the active language at runtime using the query parameter in the uri:

```
//...
$middleware = new RequestHandler;

// session
$middleware->add(
    (new SessionMiddleware)
        ->setSession(new Session)
        ->setOptions([
            'use_cookies'      => false,
            'use_only_cookies' => true
        ])
);

// set locale
$middleware->add(
    (new SetLocaleMiddleware)
        ->setLanguage('en')
        ->setSessionRequestAttrbiute('session')
        ->setLanguageQueryParam('language')
        ->setSessionKey('language')
);
//...
```

The middleware stored the language value in session. For to change it, you may use `language` query parameter in uri:

```
example.com/hello-world?language=it

```

### Determining the current locale

[](#determining-the-current-locale)

You may use the session to determine the current locale:

```
$session = $request->getAttribute('session');
return $session->get('language');
```

### Retriving translation strings

[](#retriving-translation-strings)

First, you must use the `getMessages` method to determine the current language messages. Later, you may retrieve lines from language files using the `get` method:

```
$session = $request->getAttribute('session');
$language = $session->get('language');
$messages = $translate->getMessages($language);
echo $messages->get('hello'); // Hello World!
```

### Replacing parameters in translation strings

[](#replacing-parameters-in-translation-strings)

You may define placeholders in your translation strings. All placeholders are prefixed with `{` and `}`. For example:

```
'hello' => 'Hello {name}'
```

You may replace `{name}` with an array of replacements as the second argument to the `get` method:

```
echo $messages->get('hello', ['name' => 'David']); // Hello David
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16277144?v=4)[Davide Cesarano](/maintainers/davidecesarano)[@davidecesarano](https://github.com/davidecesarano)

---

Top Contributors

[![davidecesarano](https://avatars.githubusercontent.com/u/16277144?v=4)](https://github.com/davidecesarano "davidecesarano (9 commits)")

### Embed Badge

![Health badge](/badges/davidecesarano-embryo-translate/health.svg)

```
[![Health](https://phpackages.com/badges/davidecesarano-embryo-translate/health.svg)](https://phpackages.com/packages/davidecesarano-embryo-translate)
```

###  Alternatives

[php-translation/translator

Translator services

25224.8k5](/packages/php-translation-translator)[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
