{"id":17369621,"url":"https://github.com/jblond/twig-trans","last_synced_at":"2025-05-07T04:44:12.313Z","repository":{"id":42691449,"uuid":"234270980","full_name":"JBlond/twig-trans","owner":"JBlond","description":"Twig 3 translation extension","archived":false,"fork":false,"pushed_at":"2025-02-25T09:24:17.000Z","size":74,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T04:43:59.060Z","etag":null,"topics":["gettext","i18n","i18nextension","intl","multitype","translation","twig","twig-extension","twig-templates","twig-trans"],"latest_commit_sha":null,"homepage":"https://github.com/JBlond/twig-trans","language":"PHP","has_issues":true,"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/JBlond.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-16T08:25:50.000Z","updated_at":"2025-02-24T11:11:06.000Z","dependencies_parsed_at":"2024-05-29T11:14:32.496Z","dependency_job_id":"9ed9b784-44ab-4823-bc46-c60335d05aea","html_url":"https://github.com/JBlond/twig-trans","commit_stats":{"total_commits":51,"total_committers":3,"mean_commits":17.0,"dds":0.196078431372549,"last_synced_commit":"981c40deac49fc677f9f8392c2445edc0dc3fde4"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JBlond%2Ftwig-trans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JBlond%2Ftwig-trans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JBlond%2Ftwig-trans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JBlond%2Ftwig-trans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JBlond","download_url":"https://codeload.github.com/JBlond/twig-trans/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816519,"owners_count":21808702,"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":["gettext","i18n","i18nextension","intl","multitype","translation","twig","twig-extension","twig-templates","twig-trans"],"created_at":"2024-10-16T00:05:55.018Z","updated_at":"2025-05-07T04:44:12.298Z","avatar_url":"https://github.com/JBlond.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig Trans\n\n[![Latest Version](https://img.shields.io/github/release/JBlond/twig-trans.svg?style=flat-square\u0026label=Release)](https://github.com/JBlond/twig-trans/releases) \n[![Packagist Installs](https://badgen.net/packagist/dt/jblond/twig-trans)](https://packagist.org/packages/jblond/twig-trans)\n\n## Introduction\n\nThis is the replacement for the old **Twig** Extensions **I18n** / **Intl** / **I18nExtension** for the translation with po / mo \n**gettext** files.\n\nI didn't want to install Symfony, but Twig only. Symfony seemed to be too much overhead.\n\nThis extension enables Twig templates to use `|trans` and `{% trans %}` + `{% endtrans %}` again\n\n## Install\n\n```shell\ncomposer require jblond/twig-trans\n```\n\n## Example Use\n\n```PHP\n\u003c?php\n\nuse jblond\\TwigTrans\\Translation;\nuse Twig\\Environment;\nuse Twig\\Loader\\FilesystemLoader;\nuse Twig\\TwigFilter;\n\nrequire '../vendor/autoload.php';\n\n$langCode = 'de_DE';\nputenv(\"LC_ALL=$langCode.UTF-8\");\nif (setlocale(LC_ALL, \"$langCode.UTF-8\") === false) {\n    echo sprintf('Language Code %s not found', $langCode);\n}\n\n// set the path to the translation\nbindtextdomain(\"Web_Content\", \"./locale\");\n\n// choose Domain\ntextdomain(\"Web_Content\");\n\n$twigConfig = [\n    'cache' =\u003e false,\n    'debug' =\u003e true,\n    'auto_reload' =\u003e true\n];\n\n$twigLoader = new FilesystemLoader('./tpl/');\n$twig = new Environment($twigLoader, $twigConfig);\n// if you need  {{ dump() }} in the twig templates add\n//$twig-\u003eaddExtension(new DebugExtension());\n// and use Twig\\Extension\\DebugExtension;  // at the top of the file\n\n// this is for the filter |trans\n$filter = new TwigFilter(\n    'trans', \n    function ($context, $string) {\n        return Translation::transGetText($string, $context);\n    }, \n    ['needs_context' =\u003e true]\n);\n$twig-\u003eaddFilter($filter);\n\n// load the i18n extension for using the translation tag for twig\n// {% trans %}my string{% endtrans %}\n$twig-\u003eaddExtension(new Translation());\n\ntry {\n    $tpl = $twig-\u003eload('default.twig');\n} catch (Exception $exception) {\n    echo $exception-\u003egetMessage();\n    die();\n}\n\n// the array parameter (context) is optional for the render function\necho $tpl-\u003erender(['key1' =\u003e 'value1', 'key2' =\u003e 'value2']);\n```\n\n\n## Requirements\n\n* PHP 7.2 or greater\n* PHP Multibyte String \n* 'gettext'\n* Twig \u003e= 3.0\n\n### Optional Requirements\n\n* xgettext for Extract / generating po files.\n\n### License (MIT License)\n\nsee [License](LICENSE)\n\n## Tests\n\n```bash\ncomposer run-script php_src\ncomposer run-script php_test\ncomposer run-script phpunit\n```\n\n## Contribution, wishes and bug\n\nRaise an [issue](https://github.com/JBlond/twig-trans/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjblond%2Ftwig-trans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjblond%2Ftwig-trans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjblond%2Ftwig-trans/lists"}