{"id":15489435,"url":"https://github.com/imponeer/smarty-translate","last_synced_at":"2025-10-07T04:11:42.797Z","repository":{"id":38011974,"uuid":"334750666","full_name":"imponeer/smarty-translate","owner":"imponeer","description":"Seamlessly integrate Symfony Translation with Smarty templates","archived":false,"fork":false,"pushed_at":"2025-10-01T09:03:21.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-01T11:12:19.967Z","etag":null,"topics":["hacktoberfest","smarty","smarty-plugins","symfony-translations"],"latest_commit_sha":null,"homepage":"","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/imponeer.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-01-31T20:31:37.000Z","updated_at":"2025-10-01T09:03:23.000Z","dependencies_parsed_at":"2024-05-21T22:31:37.358Z","dependency_job_id":"07dfb51d-14c7-4e4a-9589-f5d5079e5e05","html_url":"https://github.com/imponeer/smarty-translate","commit_stats":{"total_commits":26,"total_committers":3,"mean_commits":8.666666666666666,"dds":"0.34615384615384615","last_synced_commit":"ae400faaa422e39703a9918b4556ca2e6f3fa7b3"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/imponeer/smarty-translate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imponeer%2Fsmarty-translate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imponeer%2Fsmarty-translate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imponeer%2Fsmarty-translate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imponeer%2Fsmarty-translate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imponeer","download_url":"https://codeload.github.com/imponeer/smarty-translate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imponeer%2Fsmarty-translate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278717654,"owners_count":26033574,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["hacktoberfest","smarty","smarty-plugins","symfony-translations"],"created_at":"2024-10-02T07:05:39.241Z","updated_at":"2025-10-07T04:11:42.765Z","avatar_url":"https://github.com/imponeer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/github/license/imponeer/smarty-translate.svg)](LICENSE)\n[![GitHub release](https://img.shields.io/github/release/imponeer/smarty-translate.svg)](https://github.com/imponeer/smarty-translate/releases)\n[![PHP](https://img.shields.io/packagist/php-v/imponeer/smarty-translate.svg)](http://php.net)\n[![Packagist](https://img.shields.io/packagist/dm/imponeer/smarty-translate.svg)](https://packagist.org/packages/imponeer/smarty-translate)\n[![Smarty version requirement](https://img.shields.io/packagist/dependency-v/imponeer/smarty-translate/smarty%2Fsmarty)](https://smarty-php.github.io)\n\n# Smarty Translate\n\n\u003e Seamlessly integrate Symfony Translation with Smarty templates\n\nThis library adds a new Smarty block function and variable modifier called `trans` that integrates with any [Symfony Translation Contracts](https://github.com/symfony/translation-contracts) compatible library. It allows you to easily translate your Smarty templates using the powerful Symfony translation system.\n\n## Installation\n\nThe recommended way to install this package is through [Composer](https://getcomposer.org):\n\n```bash\ncomposer require imponeer/smarty-translate\n```\n\nAlternatively, you can manually include the files from the `src/` directory in your project.\n\n## Setup\n\n### Basic Setup\n\nTo register the translation extension with Smarty, add the extension class to your Smarty instance:\n\n```php\n// Create a Symfony Translator instance\n$translator = new \\Symfony\\Component\\Translation\\Translator('en');\n// ... configure your translator ...\n\n// Create a Smarty instance\n$smarty = new \\Smarty();\n\n// Register the translation extension\n$smarty-\u003eaddExtension(\n    new \\Imponeer\\Smarty\\Extensions\\Translate\\TranslationSmartyExtension($translator)\n);\n```\n\n### Using with Symfony Container\n\nTo integrate with Symfony, you can leverage autowiring, which is the recommended approach for modern Symfony applications:\n\n```yaml\n# config/services.yaml\nservices:\n    # Enable autowiring and autoconfiguration\n    _defaults:\n        autowire: true\n        autoconfigure: true\n\n    # Register your application's services\n    App\\:\n        resource: '../src/*'\n        exclude: '../src/{DependencyInjection,Entity,Tests,Kernel.php}'\n\n    # Configure Smarty with the extension\n    # The TranslationSmartyExtension will be autowired automatically\n    \\Smarty\\Smarty:\n        calls:\n            - [addExtension, ['@Imponeer\\Smarty\\Extensions\\Translate\\TranslationSmartyExtension']]\n```\n\nThen in your application code, you can simply retrieve the pre-configured Smarty instance:\n\n```php\n// Get the Smarty instance with the translation extension already added\n$smarty = $container-\u003eget(\\Smarty\\Smarty::class);\n```\n\nFor more information about Symfony's Dependency Injection Container, see the [official documentation](https://symfony.com/doc/current/service_container.html).\n\n### Using with PHP-DI\n\nWith PHP-DI container, you can take advantage of autowiring for a very simple configuration:\n\n```php\nuse function DI\\create;\nuse function DI\\get;\n\nreturn [\n    // Register the translator (assuming you have a translator factory elsewhere)\n    // \\Symfony\\Contracts\\Translation\\TranslatorInterface::class =\u003e factory(...),\n\n    // The Translation Extension is autowired by default when using class names\n\n    // Configure Smarty with the extension\n    \\Smarty\\Smarty::class =\u003e create()\n        -\u003emethod('addExtension', get(\\Imponeer\\Smarty\\Extensions\\Translate\\TranslationSmartyExtension::class))\n];\n```\n\nThen in your application code, you can retrieve the Smarty instance:\n\n```php\n// Get the configured Smarty instance\n$smarty = $container-\u003eget(\\Smarty\\Smarty::class);\n```\n\nFor more information about PHP-DI Container, see the [official documentation](https://php-di.org/doc/).\n\n### Using with League Container\n\nIf you're using League Container, you can register the extension like this:\n\n```php\n// Create the container\n$container = new \\League\\Container\\Container();\n\n// Register the translator\n$container-\u003eadd(\\Symfony\\Contracts\\Translation\\TranslatorInterface::class, function() {\n    $translator = new \\Symfony\\Component\\Translation\\Translator('en');\n    // Configure translator...\n    return $translator;\n});\n\n// Register Smarty with the translation extension\n$container-\u003eadd(\\Smarty\\Smarty::class, function() use ($container) {\n    $smarty = new \\Smarty\\Smarty();\n    // Configure Smarty...\n\n    // Create and add the translation extension directly\n    $extension = new \\Imponeer\\Smarty\\Extensions\\Translate\\TranslationSmartyExtension(\n        $container-\u003eget(\\Symfony\\Contracts\\Translation\\TranslatorInterface::class)\n    );\n    $smarty-\u003eaddExtension($extension);\n\n    return $smarty;\n});\n\n```\n\nThen in your application code, you can retrieve the Smarty instance:\n\n```php\n// Get the configured Smarty instance\n$smarty = $container-\u003eget(\\Smarty\\Smarty::class);\n```\n\nFor more information about League Container, see the [official documentation](https://container.thephpleague.com/).\n\n## Usage\n\nOnce the extension is registered, you can use it in your Smarty templates in two ways:\n\n### 1. Using the Block Function\n\nThe block function allows you to translate blocks of text:\n\n```smarty\n{* Basic usage *}\n\u003c{trans}\u003eHello, world!\u003c{/trans}\u003e\n\n{* With a specific domain *}\n\u003c{trans domain='admin'}\u003e_ADMIN_WELCOME\u003c{/trans}\u003e\n\n{* With parameters *}\n\u003c{trans parameters=['name' =\u003e 'John']}\u003eHello, {name}!\u003c{/trans}\u003e\n\n{* With domain and locale *}\n\u003c{trans domain='messages' locale='fr' parameters=['name' =\u003e 'John']}\u003eHello, {name}!\u003c{/trans}\u003e\n```\n\n### 2. Using the Variable Modifier\n\nThe variable modifier allows for inline translations:\n\n```smarty\n{* Basic usage *}\n\u003c{\"Hello, world!\"|trans}\u003e\n\n{* With parameters *}\n\u003c{\"Hello, {name}!\"|trans:[\"name\" =\u003e \"John\"]}\u003e\n\n{* With domain *}\n\u003c{\"_ADMIN_WELCOME\"|trans:[]:'admin'}\u003e\n\n{* With domain and locale *}\n\u003c{\"Hello, {name}!\"|trans:[\"name\" =\u003e \"John\"]:'messages':'fr'}\u003e\n```\n\n### Supported Attributes\n\nBoth the block function and variable modifier support the following attributes:\n\n| Attribute  | Description                                                   | Default Value         |\n|------------|---------------------------------------------------------------|----------------------|\n| parameters | Key/value pairs to replace placeholders in translated strings  | `[]`                 |\n| domain     | Translation domain (usually corresponds to translation file)   | *system default*     |\n| locale     | Specific locale to use for translation                         | *current system locale* |\n\nFor the variable modifier, the syntax is: `trans:PARAMETERS:DOMAIN:LOCALE`\n\n## Testing\n\nThis package includes a comprehensive test suite. To run the tests:\n\n```bash\ncomposer test\n```\n\n## Documentation\n\nAPI documentation is automatically generated and available in the project's wiki. For more detailed information about the classes and methods, please refer to the [project wiki](https://github.com/imponeer/smarty-translate/wiki).\n\n## Contributing\n\nContributions are welcome! Here's how you can contribute:\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature-name`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin feature-name`\n5. Submit a pull request\n\nPlease make sure your code follows the PSR-12 coding standard and include tests for any new features or bug fixes.\n\nIf you find a bug or have a feature request, please create an issue in the [issue tracker](https://github.com/imponeer/smarty-translate/issues).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimponeer%2Fsmarty-translate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimponeer%2Fsmarty-translate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimponeer%2Fsmarty-translate/lists"}