PHPackages                             roydejong/twig-gettext-extractor - 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. roydejong/twig-gettext-extractor

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

roydejong/twig-gettext-extractor
================================

(Updated for Twig 2.2) The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.

v2.1(8y ago)0143MITPHPPHP &gt;=5.5.9

Since Aug 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/roydejong/Twig-Gettext-Extractor)[ Packagist](https://packagist.org/packages/roydejong/twig-gettext-extractor)[ RSS](/packages/roydejong-twig-gettext-extractor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (14)Used By (0)

Twig Gettext Extractor [![Build Status](https://camo.githubusercontent.com/10aad5045ae1dc415be269d7f5ed4f9b60e9c64a6eb76e98508f5937767a6057/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f756d706972736b792f547769672d476574746578742d457874726163746f722e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/umpirsky/Twig-Gettext-Extractor)
================================================================================================================================================================================================================================================================================================================================================================

[](#twig-gettext-extractor-)

The Twig Gettext Extractor is [Poedit](http://www.poedit.net/download.php)friendly tool which extracts translations from twig templates.

This fork
---------

[](#this-fork)

Hello. Here's some things this fork offers:

- This fork has been designed for **compatibility with version 2 of twig**. It's a bit of a hack, but it works.
- Removed symfony dependencies which might make it a bit easier to install.
- You can add "dummy filters" via a `--filter` parameter to prevent the extractor from breaking when it encounters user-defined filters that would cause template parsing to break (HINT: add this *before* the `--files` part of the extractor command).
- If extraction fails for whatever reason, a log file will be dumped to the directory in which the gettext extractor library lives.

This fork is available on Packagist as a composer package for your convenience:

```
composer require roydejong/twig-gettext-extractor

```

Or, to install globally (to your home directory) - recommended:

```
composer global require roydejong/twig-gettext-extractor

```

Original documentation
======================

[](#original-documentation)

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

[](#installation)

### Manual

[](#manual)

#### Local

[](#local)

Download the `twig-gettext-extractor.phar` file and store it somewhere on your computer.

#### Global

[](#global)

You can run these commands to easily access `twig-gettext-extractor` from anywhere on your system:

```
$ sudo wget https://github.com/umpirsky/Twig-Gettext-Extractor/releases/download/1.2.0/twig-gettext-extractor.phar -O /usr/local/bin/twig-gettext-extractor
$ sudo chmod a+x /usr/local/bin/twig-gettext-extractor
```

Then, just run `twig-gettext-extractor`.

### Composer

[](#composer)

#### Local

[](#local-1)

```
$ composer require umpirsky/twig-gettext-extractor
```

#### Global

[](#global-1)

```
$ composer global require umpirsky/twig-gettext-extractor
```

Make sure you have `~/.composer/vendor/bin` in your `PATH` and you're good to go:

```
$ export PATH="$PATH:$HOME/.composer/vendor/bin"
```

Don't forget to add this line in your `.bashrc` file if you want to keep this change after reboot.

Setup
-----

[](#setup)

By default, Poedit does not have the ability to parse Twig templates. This can be resolved by adding an additional parser (Edit &gt; Preferences &gt; Parsers) with the following options:

- Language: `Twig`
- List of extensions: `*.twig`
- Invocation:
    - Parser command: `/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F` (replace `` with absolute path to your project)
    - An item in keyword list: `-k%k`
    - An item in input file list: `%f`
    - Source code charset: `--from-code=%c`

[![](https://camo.githubusercontent.com/60219b9af4599255341ef6c470d9b2a920c6fdfe0d129b8617ad434f7ef9e9aa/687474703a2f2f692e696d6775722e636f6d2f66397078322e706e67)](https://camo.githubusercontent.com/60219b9af4599255341ef6c470d9b2a920c6fdfe0d129b8617ad434f7ef9e9aa/687474703a2f2f692e696d6775722e636f6d2f66397078322e706e67)

Now you can update your catalog and Poedit will synchronize it with your twig templates.

Custom extensions
-----------------

[](#custom-extensions)

Twig-Gettext-Extractor registers some default twig extensions. However, if you are using custom extensions, you need to register them first before you can extract the data. In order to achieve that, copy the binfile into some custom place. A common practice would be: `cp vendor/bin/twig-gettext-extractor bin/twig-gettext-extractor`

Now you may add your custom extensions [here](https://github.com/umpirsky/Twig-Gettext-Extractor/blob/master/twig-gettext-extractor#L41):

```
$twig->addFunction(new \Twig_SimpleFunction('myCustomExtension', true));
$twig->addFunction(new \Twig_SimpleFunction('myCustomExtension2', true));
```

Custom filters (in this fork)
-----------------------------

[](#custom-filters-in-this-fork)

If you're using custom, user-defined twig filters, the extractor will break when it encounters them.

You can modify the parser command in Poedit if you want to register custom filters.

Doing so will create a dummy filter that will return the input as output without modifying it.

For example, if you have a `currency` filter, modify your parser command as follows:

```
twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --filters currency --files %F

```

The `--filters` command must be added after the gettext parameters but before the `--files` declaration to work correctly. You can add multiple filters by delimiting them with a space.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 74.4% 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 ~178 days

Recently: every ~217 days

Total

11

Last Release

3222d ago

Major Versions

v1.2.1 → v2.02017-04-05

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

v1.2.1PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a6873ef39d8543fca22ac4bbc6ceded1454067f2d82d2b51cdd2642d7f14bed?d=identicon)[roydejong](/maintainers/roydejong)

---

Top Contributors

[![umpirsky](https://avatars.githubusercontent.com/u/208957?v=4)](https://github.com/umpirsky "umpirsky (58 commits)")[![roydejong](https://avatars.githubusercontent.com/u/6772638?v=4)](https://github.com/roydejong "roydejong (12 commits)")[![bjornpost](https://avatars.githubusercontent.com/u/48628?v=4)](https://github.com/bjornpost "bjornpost (4 commits)")[![sobolevn](https://avatars.githubusercontent.com/u/4660275?v=4)](https://github.com/sobolevn "sobolevn (1 commits)")[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (1 commits)")[![cheplv](https://avatars.githubusercontent.com/u/4574587?v=4)](https://github.com/cheplv "cheplv (1 commits)")[![eisberg](https://avatars.githubusercontent.com/u/9015003?v=4)](https://github.com/eisberg "eisberg (1 commits)")

---

Tags

composergettextphppoeditpoeditortwig

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/roydejong-twig-gettext-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/roydejong-twig-gettext-extractor/health.svg)](https://phpackages.com/packages/roydejong-twig-gettext-extractor)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M648](/packages/sylius-sylius)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M309](/packages/easycorp-easyadmin-bundle)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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