PHPackages                             pyrsmk/translator - 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. pyrsmk/translator

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

pyrsmk/translator
=================

Simple translation tool for CLI/HTTP environments

2.0.4(5y ago)0324MITPHPPHP &gt;=5.3.0

Since Nov 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/pyrsmk/Translator)[ Packagist](https://packagist.org/packages/pyrsmk/translator)[ RSS](/packages/pyrsmk-translator/feed)WikiDiscussions master Synced 1mo ago

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

Translator 2.0.4
================

[](#translator-204)

Translator is a small I18N/L10N library, based on [Chernozem](https://github.com/pyrsmk/Chernozem) (we advise you to read its documentation). Here's the available options through Chernozem :

- client\_locales : the client's locales
- delimiters : set the start/end delimiter for string replacement (default : `['start' => '{', 'end' => '}']`)
- translations : the loaded translations

Install
-------

[](#install)

Pick up the source or install it with [Composer](https://getcomposer.org/) :

```
composer require pyrsmk/translator

```

Basics
------

[](#basics)

Translator is available for a website (`Translator\Http`) and a CLI application (`Translator\Cli`). For the next examples, we'll use `Translator\Http`.

First, we need to define the default locale at instantiation. This locale will be used when no client's locale is supported by your application.

```
$translator = new Translator\Http('en_EN');
```

Translator will find what locale to use by comparing the client's locales and the defined available locales (based on the loaded translations)

If needed, you can force Translator to use a specific locale :

```
$translator->setLocale('fr');
```

And you can retrieve what locale Translator will use for its translations with :

```
$translator->getLocale();
```

Load your translations files
----------------------------

[](#load-your-translations-files)

Translator doesn't implement adapters to load your files, it just expect the name of the locale and the translation strings. Then you can use any library you want to load your files or do it by hand. Here's how to do it with JSON :

```
/* fr_FR.json */
{
	"cat": "chat",
	"dog": "chien",
	"turtle": "tortue"
}
```

```
// Load the JSON file
$translator->load('fr_FR', json_decode(file_get_contents('fr_FR.json')));
```

Translate!
----------

[](#translate)

Simply :

```
// Prints 'chien'
echo $translator->translate('dog');
```

Translator can also replace strings in your translations :

```
/* fr_FR.json */
{
	"hello": "Bonjour, M. {name}!"
}
```

```
// Prints 'Bonjour, M. Philippe!'
echo $translator->translate('hello', [
	'name' => 'Philippe'
]);
```

Normalize a locale
------------------

[](#normalize-a-locale)

If needed, you can normalize any locale you want with :

```
// Prints 'sl_IT'
echo $translator->normalizeLocale('sl_Latn-IT_nedis');
```

License
-------

[](#license)

This library is released under the [MIT license](http://dreamysource.mit-license.org).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity64

Established project with proven stability

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.

###  Release Activity

Cadence

Every ~210 days

Recently: every ~360 days

Total

9

Last Release

2148d ago

Major Versions

1.2.1 → 2.0.02016-07-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f97d81cfd6d30587cdae24925bc0899331394d723d04ee4b76eb9435a565fe9?d=identicon)[pyrsmk](/maintainers/pyrsmk)

---

Tags

internationalizationi18nlanguagel10ntranslatetranslationlocationregioninternationalisationchernozem

### Embed Badge

![Health badge](/badges/pyrsmk-translator/health.svg)

```
[![Health](https://phpackages.com/badges/pyrsmk-translator/health.svg)](https://phpackages.com/packages/pyrsmk-translator)
```

###  Alternatives

[gettext/languages

gettext languages with plural rules

7530.3M10](/packages/gettext-languages)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

3191.1k2](/packages/fisharebest-localization)[delight-im/i18n

Internationalization and localization for PHP

625.2k3](/packages/delight-im-i18n)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)

PHPackages © 2026

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