PHPackages                             rafaph/twig-translation-extension - 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. [Templating &amp; Views](/categories/templating)
4. /
5. rafaph/twig-translation-extension

ActiveLibrary[Templating &amp; Views](/categories/templating)

rafaph/twig-translation-extension
=================================

Twig translate function for Illuminate\\Translation\\Translator.

1.0.0(10y ago)46.5k1MITPHPPHP &gt;=5.5

Since Mar 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/rafaph/twig-translation-extension)[ Packagist](https://packagist.org/packages/rafaph/twig-translation-extension)[ Docs](https://github.com/rafaph/twig-translation-extension#README)[ RSS](/packages/rafaph-twig-translation-extension/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

### Twig Translation Extension

[](#twig-translation-extension)

Translation functions for Twig provide by [Illuminate/translation](https://github.com/illuminate/translation).

#### Installation

[](#installation)

```
composer require rafaph/twig-translation-extension
```

#### Usage

[](#usage)

- Configure the **Illuminate\\Translation\\Translator**:

```
$langPath = __DIR__ . '/lang';
$locale = 'pt';

$translator = new \Illuminate\Translation\Translator(
    new \Illuminate\Translation\FileLoader(
        new \Illuminate\Filesystem\Filesystem(),
        $langPath
    ),
    $locale
);
$translator->setFallback('en');
```

More details about the configurations of the Translator package you can find in the [Laravel docs](https://laravel.com/docs/localization).

- Add Twig extension

```
// ...
$twig->addExtension(
	new \Raph\Twig\Extension\TranslationExtension($translator)
);
```

- Configure your messages

```
//in lang/en/messages.php

return [
	'hello' => 'Hello :name!',
	'there' => '{0} There are none|[1,19] There are some|[20,Inf] There are many'
];
```

```
//in lang/pt/messages.php

return [
	'hello' => 'Olá :name!',
	'there' => '{0} Nenhum|[1,19] Alguns|[20,Inf] Muitos'
];
```

- Use in templates

```
{{ trans('messages.hello', {'name': 'Jane Doe'}) }}
```

```
{{ trans_choice('messages.there', 2) }}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3709d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5278ae07bc31f21bf3e20163f34d0ee3b2972de8888b53856452a4538898f331?d=identicon)[rafaph](/maintainers/rafaph)

---

Top Contributors

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

---

Tags

localizationtranslatetwig

### Embed Badge

![Health badge](/badges/rafaph-twig-translation-extension/health.svg)

```
[![Health](https://phpackages.com/badges/rafaph-twig-translation-extension/health.svg)](https://phpackages.com/packages/rafaph-twig-translation-extension)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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