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

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

drago-ex/translator
===================

Lightweight translator for Nette Framework using NEON files, supporting global and module-specific translations.

v3.2.0(1w ago)23.2k5MITPHPPHP &gt;=8.3 &lt;9CI passing

Since Oct 9Pushed 6d ago1 watchersCompare

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

READMEChangelog (10)Dependencies (40)Versions (20)Used By (5)

Drago Translator
================

[](#drago-translator)

Lightweight translator for Nette Framework using NEON files, supporting global and module-specific translations.

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://github.com/drago-ex/translator/blob/master/license)[![PHP version](https://camo.githubusercontent.com/2a8170606af2c9b364f35b5a728c804a62b5f510710760cc0cc6cc3387253cc7/68747470733a2f2f62616467652e667572792e696f2f70682f647261676f2d65782532467472616e736c61746f722e737667)](https://badge.fury.io/ph/drago-ex%2Ftranslator)[![Tests](https://github.com/drago-ex/translator/actions/workflows/tests.yml/badge.svg)](https://github.com/drago-ex/translator/actions/workflows/tests.yml)[![Coding Style](https://github.com/drago-ex/translator/actions/workflows/coding-style.yml/badge.svg)](https://github.com/drago-ex/translator/actions/workflows/coding-style.yml)

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

[](#requirements)

- PHP &gt;= 8.3
- Nette Framework
- Composer

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

[](#installation)

```
composer require drago-ex/translator

```

Extension Registration
----------------------

[](#extension-registration)

Register the DI extension in your NEON configuration.

```
extensions:
	translator: Drago\Localization\DI\TranslatorExtension(%appDir%, %tempDir%)
```

Optional configuration
----------------------

[](#optional-configuration)

```
translator:
	autoFinder: false
	translateDirs:
		- %appDir%/First/Translate
		- %appDir%/Second/Translate
	exclude:
		- %appDir%/Temp
		- %appDir%/Legacy
```

Translator Behavior
-------------------

[](#translator-behavior)

- All directories listed in translateDirs are loaded in order.
- Later directories override translations from earlier ones.
- If autoFinder is enabled, the entire application directory is scanned for NEON files.
- Directories listed in exclude are skipped during automatic scanning.

Translation files must be named by language code:

```
cs.neon
en.neon

```

Translation File Format
-----------------------

[](#translation-file-format)

```
"Hello, world!": "Hello, world!"
```

Using Translator in Presenters
------------------------------

[](#using-translator-in-presenters)

Add the TranslatorAdapter trait to your presenter:

```
use Drago\Localization\TranslatorAdapter;
```

The trait provides:

- persistent language parameter ($lang)
- automatic translator initialization
- template integration

Accessing the Current Language
------------------------------

[](#accessing-the-current-language)

You can access the currently set language using the following property:

```
$this->lang;
```

Getting Translator Instance
---------------------------

[](#getting-translator-instance)

To get the initialized translator for the current language:

```
$this->getTranslator()
```

Using Translations in Templates
-------------------------------

[](#using-translations-in-templates)

The translator is automatically registered in templates. Example usage in Latte:

```
{_"Hello, world!"}
{$label|translate}
```

Using Translator in Forms
-------------------------

[](#using-translator-in-forms)

To enable translations in forms, set the translator explicitly:

```
$form->setTranslator($this->getTranslator());
```

Routing for Language Switching
------------------------------

[](#routing-for-language-switching)

To support language prefixes, configure your routes accordingly:

```
$router->addRoute('[/]/', 'Presenter:action');
```

Switching Languages in Templates
--------------------------------

[](#switching-languages-in-templates)

You can switch languages by passing the lang parameter:

```
Czech
English
```

Language Switch Widget
----------------------

[](#language-switch-widget)

The package provides a reusable Latte widget for language switching. When project file copying is handled by `drago-ex/project-tools`, the widget is copied to:

```
app/Presentation/Accessory/Widget/@lang-switch.latte

```

Import the widget in your layout:

```
{import 'path/to/@lang-switch.latte'}
```

Render language links:

```
{include lang-switch, lang: 'cs', name: 'Czech'}
|
{include lang-switch, lang: 'en', name: 'English'}
```

The current language link automatically receives the `current` class.

Available options:

- `lang` - target language code.
- `name` - visible translated label.
- `class` - optional class added to the link.
- `tag` - optional wrapper tag: `li`, `div`, or `span`.
- `tagClass` - optional class added to the wrapper tag.

Use `class` when the link needs a custom class:

```
{include lang-switch, lang: 'cs', name: 'Czech', class: 'nav-link'}
```

Use `tag` when the link must be wrapped, for example in a dropdown menu:

```
{include lang-switch, lang: 'cs', name: 'Czech', tag: 'li'}
{include lang-switch, lang: 'en', name: 'English', tag: 'li'}
```

Use `tagClass` when the wrapper needs styling:

```
{include lang-switch, lang: 'cs', name: 'Czech', tag: 'li', tagClass: 'item-wrapper'}
```

Notes
-----

[](#notes)

- Translator loads translations lazily on first use
- Translations are loaded once per request
- Missing keys return the original message

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance99

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.7% 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 ~135 days

Recently: every ~7 days

Total

19

Last Release

13d ago

Major Versions

v1.0.12 → v2.0.02026-01-08

v2.0.1 → v3.0.02026-05-23

PHP version history (6 changes)v1.0.0PHP &gt;=7.1

v1.0.5PHP &gt;=7.4

v1.0.6PHP &gt;=8.0

v1.0.8PHP &gt;=8.1

v1.0.10PHP &gt;=8.1 &lt;8.4

v1.0.11PHP &gt;=8.3 &lt;9

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5998929?v=4)[Zdeněk Papučík](/maintainers/accgit)[@accgit](https://github.com/accgit)

---

Top Contributors

[![accgit](https://avatars.githubusercontent.com/u/5998929?v=4)](https://github.com/accgit "accgit (300 commits)")[![codacy-badger](https://avatars.githubusercontent.com/u/23704769?v=4)](https://github.com/codacy-badger "codacy-badger (1 commits)")

---

Tags

nettetranslator

### Embed Badge

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

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

###  Alternatives

[nette/web-project

Nette: Standard Web Project

10993.3k](/packages/nette-web-project)[contributte/translation

Symfony/Translation integration for Nette Framework.

781.9M60](/packages/contributte-translation)

PHPackages © 2026

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