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

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

bckp/translator-core
====================

Simple and fast PHP translator

v2.0.0(1y ago)44.1k1BSD-3-ClausePHPPHP ^8.2CI passing

Since May 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bckp/translator-core)[ Packagist](https://packagist.org/packages/bckp/translator-core)[ Docs](https://github.com/bckp/translator-core)[ RSS](/packages/bckp-translator-core/feed)WikiDiscussions main Synced today

READMEChangelog (8)DependenciesVersions (9)Used By (1)

Bckp\\Translator
================

[](#bckptranslator)

[![Downloads this Month](https://camo.githubusercontent.com/41b9659b01ebf9b22308786d34add8e3f27dce05b3dd6a52ab4e434548d4544d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f62636b702f7472616e736c61746f722d636f72652e737667)](https://packagist.org/packages/bckp/translator-core)[![Build Status](https://github.com/bckp/translator-core/actions/workflows/tests.yaml/badge.svg)](https://github.com/bckp/translator-core/actions/workflows/tests.yaml)[![Coverage Status](https://camo.githubusercontent.com/382e333b0a708000522d2fc9ea2a4c93a49e91da97af4068760ba2942edc08c6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62636b702f7472616e736c61746f722d636f72652f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/bckp/translator-core?branch=main)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6208fd47c0cf9596d8536b802f12f48abf2b7f335e2dd790305cfda2154f5da0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62636b702f7472616e736c61746f722d636f72652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/bckp/translator-core/?branch=main)[![Latest Stable Version](https://camo.githubusercontent.com/ad50de7443fbc3764623a314de631edc0d720de633b2e5e284d393faefd8c48b/68747470733a2f2f706f7365722e707567782e6f72672f62636b702f7472616e736c61746f722d636f72652f762f737461626c65)](https://packagist.org/packages/bckp/translator-core)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/nette/application/blob/master/license.md)

Simple and fast PHP translator

Usage
-----

[](#usage)

For each language, we create Catalogue, that will compile PHP cache file with translations.

```
$catalogue = new CatalogueBuilder(new PluralProvider(), './path/to/cache', 'cs');
$catalogue->addFile('./path/to/locales/errors.cs.neon');
$catalogue->addFile('./path/to/locales/messages.cs.neon');

// Enable debug mode, disabled by default
$catalogue->setDebugMode(true);

$compiledCatalogue = $catalogue->compile();
$translator = new Translator($compiledCatalogue);

$translator->translate('errors.error.notFound'); // Will output "Soubor nenalezen"
$translator->translate('messages.plural', 4); // Will output "4 lidé"
$translator->translate('messages.withArgs', 'Honza', 'poledne'); // Will output "Ahoj, já jsem Honza, přeji krásné poledne"
$translator->translate('messages.withArgsRev', 'Honza', 'poledne'); // Will output "Krásné poledne, já jsem Honza"
```

You can add your own source of text by callback

```
$catalogue = new CatalogueBuilder(new PluralProvider(), './path/to/cache', 'cs');
$catalogue->addDynamic('errors', function(array &$messages, string $resource, string $locale){
    $messages['common'] = 'Common error translation';
    $messages['critical'] = $this->database->fetchAll('translations')->where('resource = ? and locale = ?', $resource, $locale);
});
$catalogue->addFile('./path/to/locales/messages.cs.neon');
// if you add new file errors.cs.neon, it will be overwritten by dynamic, as they is processed later

// Enable debug mode, disabled by default
$catalogue->setDebugMode(true);

// You can even add events for onCheck
// $timestamp contains timestamp of last file generation
// but remember, this will called only on debug mode!
$catalogue->addCheckCallback(function(int $timestamp){
    if ($timestamp < $this->database->fetchSingle('select last_update from settings where caption = ?', 'translations')){
        throw new BuilderException('rebuild required');
    }
});

// And events for onCompile
// this will occur when app have prepared all translations into single
// big array, and you want to modify it
$catalogue->addCompileCallback(function(array &$messages, string $locale){
    // in messages, we have all the translations
    $messages['errors.common'] = 'Modify common error translation';
});

$compiledCatalogue = $catalogue->compile();
$translator = new Translator($compiledCatalogue);

$translator->translate('errors.common'); // Will output "Modify common error translation"
```

Debug mode will made translator slower, it will check every time you call compile() if some of language files did change or not, and if they do, automaticly recompile cache, this is Good for development, but BAD on production mode.

Or you can use TranslatorProvider

```
$catalogue = new CatalogueBuilder(new PluralProvider(), './path/to/cache', 'cs');
$catalogue->addFile('./path/to/locales/errors.cs.neon');
$catalogue->addFile('./path/to/locales/messages.cs.neon');

$provider = new TranslatorProvider(['cs','en']);
$provider->addCatalogue('cs', $catalogue);

$translator = $provider->getTranslator('cs');
```

Great about this approach is, if you use more then one language, and switch between them, translator provider will compile catalogue only on first use, then use the compiled one.

Translation file format
-----------------------

[](#translation-file-format)

Translation files are written in NEON format. Plural strings are in ARRAY, otherwise STRING.

```
welcome: 'Vítejte'
withArgs: 'Ahoj, já jsem %s, přeji krásné %s'
withArgsRev: 'Krásné %2$s, já jsem %1$s'
plural:
	zero: 'žádný člověk'
	one: 'jeden člověk'
	few: '%d lidé'
	other: '%d lidí'
next: 'This is next translation'
```

If you want more structure, you can use DOT as character, so lets say we want 3 error messages, we will create structure like this

```
error.notFound: 'Soubor nenalezen'
error.notMatch: 'Soubor neodpovídá zadání'
error.typeMismatch: 'Neplatný typ souboru'
```

Diagnostics
-----------

[](#diagnostics)

You can use simple diagnostics (or implement one), if you want to know, what is wrong with your translations, this is primary for framework integration (like Nette one).

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance47

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity77

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~308 days

Recently: every ~398 days

Total

8

Last Release

392d ago

Major Versions

v1.1.1 → v2.0.0-rc12025-04-07

PHP version history (4 changes)v1.0.0PHP &gt;=7.1 &lt;7.4

v1.0.2PHP ^7.1

v1.1.0PHP ^7.1|^8.0

v2.0.0-rc1PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/179652?v=4)[Radovan Kepák](/maintainers/bckp)[@bckp](https://github.com/bckp)

---

Top Contributors

[![bckp](https://avatars.githubusercontent.com/u/179652?v=4)](https://github.com/bckp "bckp (7 commits)")

---

Tags

translator

### Embed Badge

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

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

###  Alternatives

[stichoza/google-translate-php

Free Google Translate API PHP Package

2.0k7.6M124](/packages/stichoza-google-translate-php)[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[waavi/translation

A Translation package for Laravel 5 with database and cache support

367437.9k6](/packages/waavi-translation)[vsch/laravel-translation-manager

Enhanced Laravel Translation Manager

184190.9k2](/packages/vsch-laravel-translation-manager)[phpmyadmin/motranslator

Translation API for PHP using Gettext MO files

591.8M8](/packages/phpmyadmin-motranslator)[kargnas/laravel-ai-translator

AI-powered translation tool for Laravel language files

24838.8k1](/packages/kargnas-laravel-ai-translator)

PHPackages © 2026

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