PHPackages                             saeven/zf2-circlical-trans - 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. saeven/zf2-circlical-trans

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

saeven/zf2-circlical-trans
==========================

ZF3 module that glues Twig's {% trans %} and the standard translator together

1.1.1(4y ago)216.6k↓50%2MITPHPPHP &gt;=7.4

Since Jun 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Saeven/zf3-twig-trans)[ Packagist](https://packagist.org/packages/saeven/zf2-circlical-trans)[ Docs](https://github.com/Saeven/zf3-twig-trans)[ RSS](/packages/saeven-zf2-circlical-trans/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (8)Used By (0)

zf3-twig-trans
==============

[](#zf3-twig-trans)

[![Build Status](https://camo.githubusercontent.com/d73dd66025473b615c2d8dac3d2a6b949bcc39ca64cad7a3b32eba277686aeb7/68747470733a2f2f7472617669732d63692e6f72672f53616576656e2f7a66332d747769672d7472616e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Saeven/zf3-circlical-user)[![Codacy Badge](https://camo.githubusercontent.com/e0c1be8ae233e5b0c13a6bad6cd9d2662b50f3f57d85f4c095da2ec4fa3e5f49/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6539623830616531633463393431353961626537626362343962383531636163)](https://www.codacy.com/app/saeven/zf3-twig-trans?utm_source=github.com&utm_medium=referral&utm_content=Saeven/zf3-twig-trans&utm_campaign=Badge_Grade)[![Codacy Badge](https://camo.githubusercontent.com/c5d4aabe0af3387cee04d6996aaa22cd6dba8c6f7b9cf087bb0b2600d0ff1c44/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f6539623830616531633463393431353961626537626362343962383531636163)](https://www.codacy.com/app/saeven/zf3-twig-trans?utm_source=github.com&utm_medium=referral&utm_content=Saeven/zf3-twig-trans&utm_campaign=Badge_Coverage)[![Total Downloads](https://camo.githubusercontent.com/fd94850be67663026c47e0ee300ec475c511b87530c38785fe8fff2966a5e1e3/68747470733a2f2f706f7365722e707567782e6f72672f73616576656e2f7a66322d636972636c6963616c2d7472616e732f646f776e6c6f616473)](https://packagist.org/packages/saeven/zf2-circlical-trans)

Magic glue to create the expected experience when developing with ZfcTwig, the MvcTranslator (e.g., from within your controllers), and your twig templates using a custom {% trans %} that this module provides. Usage is very simple! With this package included, "trans" becomes available in your templates.

> New! This module supports text domains!

Inspired by ZfcTwig and its extensions project at

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

[](#requirements)

ItemVersionPHP7+Zend Framework3.\*Gettext PHP Module\*Installation
------------

[](#installation)

```
composer require "saeven/zf3-twig-trans"
```

Configuration
-------------

[](#configuration)

#### Loading the module: application.config.php

[](#loading-the-module-applicationconfigphp)

In your module's application.config.php, make sure you've got these modules loaded:

```
'ZfcTwig',
'CirclicalTwigTrans'

```

By loading CirclicalTwigTrans, you will be setting an alias from 'translator' to 'MvcTranslator'. If you have an existing translator alias in your system, please remove it.

#### Managing Locale: Your Application's Module.php

[](#managing-locale-your-applications-modulephp)

It's assumed that you are managing locale in your app's bootstrap. For example, in your Application module's onBootstrap:

```
public function onBootstrap(MvcEvent $e)
{

    $translator = $e->getApplication()->getServiceManager()->get('translator');
    $translator
        ->setLocale( 'fr_CA' )
        ->setFallbackLocale( 'en_US' );
}
```

#### Proper Language File Setup

[](#proper-language-file-setup)

gettext imposes a certain file structure; language folders for a module would look like so:

```
module/
    Application/
        language/
            en_US/
                LC_MESSAGES/
                    default.mo
                    default.po
                    errors.mo
                    errors.po
            fr_CA/
                LC_MESSAGES/
                    default.mo
                    default.po
                    errors.mo
                    errors.po

```

The .mo files are truly the ones that matter. The .po files, are the source files that are used to compile the .mo files with msgfmt.

The nomenclature, default.mo, indicates that that file contains text strings for the 'default' text domain. In other words, the name of the files is vital to proper functionality.

You need to tweak your translator configuration to support this file structure, it's very simple. Per module:

```
'translator' => [

    'translation_file_patterns' => [
        [
            'locale'        => 'en_US',
            'type'          => 'gettext',
            'base_dir'      => __DIR__ . '/../language',
            'pattern'       => '%s/LC_MESSAGES/default.mo',
            'text_domain'   => 'default',
        ],
        [
            'locale'        => 'en_US',
            'type'          => 'gettext',
            'base_dir'      => __DIR__ . '/../language',
            'pattern'       => '%s/LC_MESSAGES/errors.mo',
            'text_domain'   => 'errors',
        ],
    ],
],
```

Very important: there's a critical difference between Zend's translator implementations, and gettext's implementation. The Zend translator will allow you to use multiple .mo files for a same domain, but gettext does not support this behavior. To ensure that both the Twig translations, and your in-app translations (e.g., `$translator->translate('foo')`) work properly, your domain names must be unique. A good practice is to name your domain, after your module.

Usage
-----

[](#usage)

Included tests support all flavors of trans, adding direct support for domain overrides from within the template. These syntax structures all work:

#### Translate 'Sorry' from text-domain 'errors'

[](#translate-sorry-from-text-domain-errors)

```
{% trans from "errors" %}Sorry{% endtrans %}
```

#### Translate 'Home' from the 'default' domain

[](#translate-home-from-the-default-domain)

```
{% trans %}Home{% endtrans %}
```

#### Translate "A 404 error occurred" from the 'default' domain

[](#translate-a-404-error-occurred-from-the-default-domain)

```
{% trans "A 404 error occurred" %}
```

#### Translate with pluralization from the 'default' domain

[](#translate-with-pluralization-from-the-default-domain)

```
{% set birds = 422 %}
{% trans %}
    There is one bird
{% plural birds %}
    There are {{ birds }} birds
{% endtrans %}
```

#### Translate with pluralization from the 'errors' domain

[](#translate-with-pluralization-from-the-errors-domain)

```
{% set birds = 422 %}
{% trans from "errors" %}
    There is one bird
{% plural birds %}
    There are {{ birds }} birds
{% endtrans %}
```

#### Translate with notes

[](#translate-with-notes)

```
{% trans %}
    Hello User!
{% notes %}
    This is used in the greeting area.
{% endtrans %}
```

#### Controllers

[](#controllers)

Usage in controllers doesn't change.

```
/** @var Laminas\I18n\Translator\Translator $tr */
$tr = $sm->get('translator');

$tr->translate( 'Home' );
$tr->translate( 'Sorry', 'errors' );

$num = 422;
sprintf( $tr->translatePlural( "There is one bird", "There are %d birds", 422 ), $num );
sprintf( $tr->translatePlural( "There is one bird", "There are %d birds", 422, 'errors' ), $num );
```

You can test it with the ZF3 Skeleton, by translating "Home" to "fr\_CA" which becomes "Acceuil" (good test).

Enjoy!
------

[](#enjoy)

Let me know if you find any issues. I use this module as well in production, so definitely want to hunt bugs down!

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

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 ~378 days

Recently: every ~447 days

Total

6

Last Release

1714d ago

Major Versions

0.9.2 → 1.0.02019-05-01

PHP version history (3 changes)0.9PHP &gt;=5.5

0.9.2PHP &gt;=7.1

1.1.1PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/887224?v=4)[Alexandre Lemaire](/maintainers/Saeven)[@Saeven](https://github.com/Saeven)

---

Top Contributors

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

---

Tags

i18ntwigtranslatorzf2trans

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/saeven-zf2-circlical-trans/health.svg)

```
[![Health](https://phpackages.com/badges/saeven-zf2-circlical-trans/health.svg)](https://phpackages.com/packages/saeven-zf2-circlical-trans)
```

###  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)[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)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)

PHPackages © 2026

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