PHPackages                             darkcat/twig-translation-bundle - 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. darkcat/twig-translation-bundle

ActiveSymfony-bundle[Localization &amp; i18n](/categories/localization)

darkcat/twig-translation-bundle
===============================

Symfony 4 bundle for performance translation in twig

001[2 PRs](https://github.com/namth0712/twig-translation-bundle/pulls)PHP

Since Dec 3Pushed 3y agoCompare

[ Source](https://github.com/namth0712/twig-translation-bundle)[ Packagist](https://packagist.org/packages/darkcat/twig-translation-bundle)[ RSS](/packages/darkcat-twig-translation-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

TwigTranslationBundle
=====================

[](#twigtranslationbundle)

Symfony 4 bundle for performance translation in twig, use this bundle only for **the project has multiple languages but provides one language only**. Example: Your project has two languages: en, fr and deploy to different domains.

- en.example.com
- fr.example.com

Same source code but has different language for display. If you're using Twig Translations to translate like

```
{{ 'Strangle Things'|trans }}

{{ 'Hello %name%'|trans({'%name%': 'Walter'}) }}
```

then when your project create cached files for twig, it will become:

```
echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Strangle Things"), "html", null, true);

echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Hello %name%", ["%name%" => "Walter"]), "html", null, true);
```

in twig cached files, so every `trans` will take time to translate every time cached files called, it does not depend on your environment(production or development). This causes huge performance when compare with your one language version(plain text only).

This bundle will print plain text to twig cached files. Translate process while creating cached files.

```
echo "Strangle Things";

echo strtr('Hello %name%', ["%name%" => "Walter"]);
```

Hence, this process improves a lot of performance.

Introduction
------------

[](#introduction)

This Bundle extends [Twig Translations](https://symfony.com/doc/current/translation.html) and provides the following features:

- Print plain translated text into twig cache files(instead of extension functions)
- Translate text with twig tags, filters, and functions.

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

[](#installation)

### Composer

[](#composer)

Run command: `composer require "darkcat/twig-translation-bundle"`

Or add to `composer.json` in your project to `require` section:

```
{
  "darkcat/twig-translation-bundle": "1.0.*"
}
```

and run command: `php composer.phar update`

### Add this bundle to your application's kernel

[](#add-this-bundle-to-your-applications-kernel)

> In a default Symfony application that uses Symfony Flex, bundles are enabled/disabled automatically for you when installing/removing them, so you don't need to look at or edit this bundles.php file.

```
// config/bundles.php
return [
    // ...
    DarkCat\TwigTranslationBundle\TwigTranslationBundle::class => ['all' => true],
];
```

Using Translation in Templates
------------------------------

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

### Use Twig Tags

[](#use-twig-tags)

```
{% statictrans with {'%name%': 'Jesse'} from 'messsages' %}Hello %name%{% endstatictrans %}

{% statictrans with {'%name%': 'Jesse'} from 'messsages' into 'fr' %}Hello %name%{% endstatictrans %}
```

### Use Twig Filters

[](#use-twig-filters)

The `t` and `statictrans` filters can be used to translate variable texts and complex expressions:

```
{{ message|statictrans(params, domain, locale, count) }}

{{ 'Strangle Things'|t }}
{{ 'Strangle Things'|statictrans }}
{{ 'Hello %name%'|statictrans({'%name%': 'Walter White'}, 'messsages') }}
```

### Use Twig Functions

[](#use-twig-functions)

```
{{ statictrans(message, params, domain, locale, count) }}

{{ t('Strangle Things') }}
{{ statictrans('Strangle Things') }}
{{ statictrans('Hello %name%', {'%name%': 'Walter White'}) }}
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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://www.gravatar.com/avatar/d06165848af6f9296472ad46d0dfd4338b5fb9c157fa2fe8f156d82b05b655a4?d=identicon)[namth0712](/maintainers/namth0712)

---

Top Contributors

[![namth0712](https://avatars.githubusercontent.com/u/44791771?v=4)](https://github.com/namth0712 "namth0712 (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

### Embed Badge

![Health badge](/badges/darkcat-twig-translation-bundle/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.0k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M491](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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