{"id":14968532,"url":"https://github.com/miyagi-dev/twig-drupal-string","last_synced_at":"2026-02-10T06:31:54.029Z","repository":{"id":229035373,"uuid":"775479786","full_name":"miyagi-dev/twig-drupal-string","owner":"miyagi-dev","description":"Twig.js extension for Drupal String module filter support","archived":false,"fork":false,"pushed_at":"2025-02-12T06:47:28.000Z","size":163,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-21T20:13:04.589Z","etag":null,"topics":["drupal","string","translation","twig"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/miyagi-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2024-03-21T13:20:27.000Z","updated_at":"2025-02-12T06:47:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"ca5f92de-6eb2-40e7-89eb-8dacd0b769cd","html_url":"https://github.com/miyagi-dev/twig-drupal-string","commit_stats":null,"previous_names":["miyagi-dev/twig-drupal-string"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/miyagi-dev/twig-drupal-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyagi-dev%2Ftwig-drupal-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyagi-dev%2Ftwig-drupal-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyagi-dev%2Ftwig-drupal-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyagi-dev%2Ftwig-drupal-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miyagi-dev","download_url":"https://codeload.github.com/miyagi-dev/twig-drupal-string/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyagi-dev%2Ftwig-drupal-string/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29292092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T03:42:42.660Z","status":"ssl_error","status_checked_at":"2026-02-10T03:42:41.897Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["drupal","string","translation","twig"],"created_at":"2024-09-24T13:40:04.536Z","updated_at":"2026-02-10T06:31:54.016Z","avatar_url":"https://github.com/miyagi-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig Drupal String\n\nAdd support for the Drupal [Twig `t` and `trans` filters](https://symfony.com/doc/current/translation.html#translation-filters) in combination with the [String module](https://www.drupal.org/project/string) and [Twig.js](https://github.com/twigjs/twig.js/).\n\n## Installation\n\nAdd the package to your dependencies:\n\n```sh\nnpm install --save-dev twig twig-drupal-string\n```\n\n## Example\n\nCrate a file called `strings.yaml` with the following content:\n\n```yaml\nwelcome:\n  default: Welcome\n```\n\nThen create `render-template.mjs`:\n\n```js\nimport Twig from \"twig\";\nimport { twigDrupalString } from \"twig-drupal-string\";\n\ntwigDrupalString({\n  Twig,\n  files: [\"strings.yaml\"],\n});\n\nconst data = `\u003ch1\u003e{{ 'welcome'|t }}\u003c/h1\u003e`;\nconst template = Twig.twig({ data });\nconst output = template.render();\n\nconsole.log(output);\n```\n\nRun the example with:\n\n```sh\nnode render-template.mjs\n\n# The output is:\n# \u003ch1\u003eWelcome\u003c/h1\u003e\n```\n\n## Placeholders\n\nThe filter also supports placeholders inside the strings that will be replaced with dynamic data during template rendering.\n\nAdd the following to `strings.yaml`:\n\n```yaml\ngreeting:\n  default: Hello @name\n```\n\nThen adjust the template inside `render-template.mjs`:\n\n```js\nconst data = `\u003ch1\u003e{{ 'greeting'|t({'@name': 'world'}) }}\u003c/h1\u003e`;\nconst template = Twig.twig({ data });\nconst output = template.render();\n\n// Output will be:\n// \u003ch1\u003eHello world\u003c/h1\u003e\n```\n\n## Custom filter names\n\nBy default, the filter names `t` and `trans` are supported. You can overwrite or extend these names with the `filterNames` option:\n\n```js\ntwigDrupalString({\n  Twig,\n  files: [\"strings.yaml\"],\n  filterNames: [\"t\", \"trans\", \"tc\"],\n});\n```\n\n## Watch mode\n\nFor development purposes, a watch mode can be enabled that reloads the translation strings from disk if any of the referenced files change.\n\nSet the `watch` options:\n\n```js\ntwigDrupalString({\n  Twig,\n  files: [\"strings.yaml\"],\n  watch: true,\n});\n```\n\n## Options\n\nThe `twigDrupalString` method receives an options object with the following properties:\n\n| Property      | Type       | Description                                            |\n| ------------- | ---------- | ------------------------------------------------------ |\n| `Twig`        | `Twig`     | Twig.js engine instance                                |\n| `files`       | `string[]` | Array of paths to translation string files             |\n| `filterNames` | `string[]` | Array of filter name strings, default `[\"t\", \"trans\"]` |\n| `watch`       | `boolean`  | Enable or disable watch mode, default `false`          |\n\n## Contributing\n\nSee [contributing documentation](CONTRIBUTING.md) for more information.\n\n## Sponsors\n\n\u003ca href=\"https://factorial.io/\" title=\"Factorial GmbH\"\u003e\n  \u003cimg src=\"https://logo.factorial.io/sq/white-on-black.svg\" width=\"100\" height=\"100\" alt=\"Factorial GmbH\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyagi-dev%2Ftwig-drupal-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiyagi-dev%2Ftwig-drupal-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyagi-dev%2Ftwig-drupal-string/lists"}