{"id":23489928,"url":"https://github.com/roydejong/twig-gettext-extractor","last_synced_at":"2026-04-27T11:31:54.880Z","repository":{"id":62537681,"uuid":"87313786","full_name":"roydejong/Twig-Gettext-Extractor","owner":"roydejong","description":"The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates. Supports Twig v2.","archived":false,"fork":false,"pushed_at":"2017-07-14T10:19:44.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T11:16:05.595Z","etag":null,"topics":["composer","gettext","php","poedit","poeditor","twig"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roydejong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-05T13:40:19.000Z","updated_at":"2017-05-03T11:23:47.000Z","dependencies_parsed_at":"2022-11-02T15:16:33.766Z","dependency_job_id":null,"html_url":"https://github.com/roydejong/Twig-Gettext-Extractor","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydejong%2FTwig-Gettext-Extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydejong%2FTwig-Gettext-Extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydejong%2FTwig-Gettext-Extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydejong%2FTwig-Gettext-Extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roydejong","download_url":"https://codeload.github.com/roydejong/Twig-Gettext-Extractor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248907788,"owners_count":21181398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","gettext","php","poedit","poeditor","twig"],"created_at":"2024-12-25T00:12:37.603Z","updated_at":"2026-04-27T11:31:54.852Z","avatar_url":"https://github.com/roydejong.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Twig Gettext Extractor [![Build Status](https://secure.travis-ci.org/umpirsky/Twig-Gettext-Extractor.svg?branch=master)](http://travis-ci.org/umpirsky/Twig-Gettext-Extractor)\n======================\n\nThe Twig Gettext Extractor is [Poedit](http://www.poedit.net/download.php)\nfriendly tool which extracts translations from twig templates.\n\n## This fork\nHello. Here's some things this fork offers:\n\n- This fork has been designed for **compatibility with version 2 of twig**. It's a bit of a hack, but it works.\n- Removed symfony dependencies which might make it a bit easier to install.\n- 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).\n- If extraction fails for whatever reason, a log file will be dumped to the directory in which the gettext extractor library lives.\n\nThis fork is available on Packagist as a composer package for your convenience:\n\n    composer require roydejong/twig-gettext-extractor\n    \nOr, to install globally (to your home directory) - recommended:\n\n    composer global require roydejong/twig-gettext-extractor\n\n\n# Original documentation\n\n## Installation\n\n### Manual\n\n#### Local\n\nDownload the ``twig-gettext-extractor.phar`` file and store it somewhere on your computer.\n\n#### Global\n\nYou can run these commands to easily access ``twig-gettext-extractor`` from anywhere on\nyour system:\n\n```bash\n$ 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\n$ sudo chmod a+x /usr/local/bin/twig-gettext-extractor\n```\nThen, just run ``twig-gettext-extractor``.\n\n### Composer\n\n#### Local\n\n```bash\n$ composer require umpirsky/twig-gettext-extractor\n```\n\n#### Global\n\n```bash\n$ composer global require umpirsky/twig-gettext-extractor\n```\n\nMake sure you have ``~/.composer/vendor/bin`` in your ``PATH`` and\nyou're good to go:\n\n```bash\n$ export PATH=\"$PATH:$HOME/.composer/vendor/bin\"\n```\nDon't forget to add this line in your `.bashrc` file if you want to keep this change after reboot.\n\n## Setup\n\nBy default, Poedit does not have the ability to parse Twig templates.\nThis can be resolved by adding an additional parser (Edit \u003e Preferences \u003e Parsers)\nwith the following options:\n\n- Language: `Twig`\n- List of extensions: `*.twig`\n- Invocation:\n    - Parser command: `\u003cproject\u003e/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F` (replace `\u003cproject\u003e` with absolute path to your project)\n    - An item in keyword list: `-k%k`\n    - An item in input file list: `%f`\n    - Source code charset: `--from-code=%c`\n\n\u003cimg src=\"http://i.imgur.com/f9px2.png\" /\u003e\n\nNow you can update your catalog and Poedit will synchronize it with your twig\ntemplates.\n\n## Custom extensions\n\nTwig-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`\n\nNow you may add your custom extensions [here](https://github.com/umpirsky/Twig-Gettext-Extractor/blob/master/twig-gettext-extractor#L41):\n\n```php\n$twig-\u003eaddFunction(new \\Twig_SimpleFunction('myCustomExtension', true));\n$twig-\u003eaddFunction(new \\Twig_SimpleFunction('myCustomExtension2', true));\n```\n\n## Custom filters (in this fork)\n\nIf you're using custom, user-defined twig filters, the extractor will break when it encounters them.  \n\nYou can modify the parser command in Poedit if you want to register custom filters.\n\nDoing so will create a dummy filter that will return the input as output without modifying it.\n\nFor example, if you have a `currency` filter, modify your parser command as follows:\n\n    twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --filters currency --files %F\n    \nThe `--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.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froydejong%2Ftwig-gettext-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froydejong%2Ftwig-gettext-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froydejong%2Ftwig-gettext-extractor/lists"}