PHPackages                             imponeer/smarty-translate - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. imponeer/smarty-translate

ActiveLibrary[Localization &amp; i18n](/categories/localization)

imponeer/smarty-translate
=========================

Library that provides trans modifier and block smarty extensions based on Symfony Translations contracts

v3.0.4(5mo ago)120.6k↓33.3%MITPHPPHP ^8.3CI passing

Since Jan 31Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/imponeer/smarty-translate)[ Packagist](https://packagist.org/packages/imponeer/smarty-translate)[ RSS](/packages/imponeer-smarty-translate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (18)Used By (0)

[![License](https://camo.githubusercontent.com/c99f896190172905095dd609d18866bb6d85056f56f4a97e93346ca0d774cb66/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d706f6e6565722f736d617274792d7472616e736c6174652e737667)](LICENSE)[![GitHub release](https://camo.githubusercontent.com/295e5c694dd33125e9f649f74e48b76f1e0691e254304886442162813645b0d9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696d706f6e6565722f736d617274792d7472616e736c6174652e737667)](https://github.com/imponeer/smarty-translate/releases)[![PHP](https://camo.githubusercontent.com/ab99fa68d968c0fe69b6b46e237a5168ba6ec70b299ce6c75958ea4030dd37d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696d706f6e6565722f736d617274792d7472616e736c6174652e737667)](http://php.net)[![Packagist](https://camo.githubusercontent.com/54ac4da56791cc18338cbd918056cf84825b92fae4835e0c847262801979baa4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696d706f6e6565722f736d617274792d7472616e736c6174652e737667)](https://packagist.org/packages/imponeer/smarty-translate)[![Smarty version requirement](https://camo.githubusercontent.com/d6a8e952ebbb79767e78da0daeed3bb95ebc84391a132da1ad136b22ed576ab6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f696d706f6e6565722f736d617274792d7472616e736c6174652f736d61727479253246736d61727479)](https://smarty-php.github.io)

Smarty Translate
================

[](#smarty-translate)

> Seamlessly integrate Symfony Translation with Smarty templates

This 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.

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

[](#installation)

The recommended way to install this package is through [Composer](https://getcomposer.org):

```
composer require imponeer/smarty-translate
```

Alternatively, you can manually include the files from the `src/` directory in your project.

Setup
-----

[](#setup)

### Basic Setup

[](#basic-setup)

To register the translation extension with Smarty, add the extension class to your Smarty instance:

```
// Create a Symfony Translator instance
$translator = new \Symfony\Component\Translation\Translator('en');
// ... configure your translator ...

// Create a Smarty instance
$smarty = new \Smarty();

// Register the translation extension
$smarty->addExtension(
    new \Imponeer\Smarty\Extensions\Translate\TranslationSmartyExtension($translator)
);
```

### Using with Symfony Container

[](#using-with-symfony-container)

To integrate with Symfony, you can leverage autowiring, which is the recommended approach for modern Symfony applications:

```
# config/services.yaml
services:
    # Enable autowiring and autoconfiguration
    _defaults:
        autowire: true
        autoconfigure: true

    # Register your application's services
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Tests,Kernel.php}'

    # Configure Smarty with the extension
    # The TranslationSmartyExtension will be autowired automatically
    \Smarty\Smarty:
        calls:
            - [addExtension, ['@Imponeer\Smarty\Extensions\Translate\TranslationSmartyExtension']]
```

Then in your application code, you can simply retrieve the pre-configured Smarty instance:

```
// Get the Smarty instance with the translation extension already added
$smarty = $container->get(\Smarty\Smarty::class);
```

For more information about Symfony's Dependency Injection Container, see the [official documentation](https://symfony.com/doc/current/service_container.html).

### Using with PHP-DI

[](#using-with-php-di)

With PHP-DI container, you can take advantage of autowiring for a very simple configuration:

```
use function DI\create;
use function DI\get;

return [
    // Register the translator (assuming you have a translator factory elsewhere)
    // \Symfony\Contracts\Translation\TranslatorInterface::class => factory(...),

    // The Translation Extension is autowired by default when using class names

    // Configure Smarty with the extension
    \Smarty\Smarty::class => create()
        ->method('addExtension', get(\Imponeer\Smarty\Extensions\Translate\TranslationSmartyExtension::class))
];
```

Then in your application code, you can retrieve the Smarty instance:

```
// Get the configured Smarty instance
$smarty = $container->get(\Smarty\Smarty::class);
```

For more information about PHP-DI Container, see the [official documentation](https://php-di.org/doc/).

### Using with League Container

[](#using-with-league-container)

If you're using League Container, you can register the extension like this:

```
// Create the container
$container = new \League\Container\Container();

// Register the translator
$container->add(\Symfony\Contracts\Translation\TranslatorInterface::class, function() {
    $translator = new \Symfony\Component\Translation\Translator('en');
    // Configure translator...
    return $translator;
});

// Register Smarty with the translation extension
$container->add(\Smarty\Smarty::class, function() use ($container) {
    $smarty = new \Smarty\Smarty();
    // Configure Smarty...

    // Create and add the translation extension directly
    $extension = new \Imponeer\Smarty\Extensions\Translate\TranslationSmartyExtension(
        $container->get(\Symfony\Contracts\Translation\TranslatorInterface::class)
    );
    $smarty->addExtension($extension);

    return $smarty;
});
```

Then in your application code, you can retrieve the Smarty instance:

```
// Get the configured Smarty instance
$smarty = $container->get(\Smarty\Smarty::class);
```

For more information about League Container, see the [official documentation](https://container.thephpleague.com/).

Usage
-----

[](#usage)

Once the extension is registered, you can use it in your Smarty templates in two ways:

### 1. Using the Block Function

[](#1-using-the-block-function)

The block function allows you to translate blocks of text:

```
{* Basic usage *}
Hello, world!

{* With a specific domain *}
_ADMIN_WELCOME

{* With parameters *}
 'John']}>Hello, {name}!

{* With domain and locale *}
 'John']}>Hello, {name}!
```

### 2. Using the Variable Modifier

[](#2-using-the-variable-modifier)

The variable modifier allows for inline translations:

```
{* Basic usage *}

{* With parameters *}
 "John"]}>

{* With domain *}

{* With domain and locale *}
 "John"]:'messages':'fr'}>
```

### Supported Attributes

[](#supported-attributes)

Both the block function and variable modifier support the following attributes:

AttributeDescriptionDefault ValueparametersKey/value pairs to replace placeholders in translated strings`[]`domainTranslation domain (usually corresponds to translation file)*system default*localeSpecific locale to use for translation*current system locale*For the variable modifier, the syntax is: `trans:PARAMETERS:DOMAIN:LOCALE`

Testing
-------

[](#testing)

This package includes a comprehensive test suite. To run the tests:

```
composer test
```

Documentation
-------------

[](#documentation)

API 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).

Contributing
------------

[](#contributing)

Contributions are welcome! Here's how you can contribute:

1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin feature-name`
5. Submit a pull request

Please make sure your code follows the PSR-12 coding standard and include tests for any new features or bug fixes.

If you find a bug or have a feature request, please create an issue in the [issue tracker](https://github.com/imponeer/smarty-translate/issues).

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% 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 ~117 days

Recently: every ~60 days

Total

16

Last Release

159d ago

Major Versions

v1.1.6 → v2.0.02023-02-01

v2.0.2 → v3.0.02025-04-03

PHP version history (3 changes)v1.0.0PHP &gt;=7.2.5

v2.0.0PHP ^7.3 || ^8.0

v3.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dba53e399a507d1f60626164c8b1e340a5cc0dc4f0637f4c6aaff8fc239fdaee?d=identicon)[fiammybe](/maintainers/fiammybe)

![](https://www.gravatar.com/avatar/7255f306e0ca27292c50cdd9644c1c04e0d7b0f54bf35e0cdd79dc55c83b4923?d=identicon)[MekDrop](/maintainers/MekDrop)

![](https://www.gravatar.com/avatar/79009323fafcd4974bb1713b12eea0a610f01c4fb21cc5e85d446c4cb66453d4?d=identicon)[skenow](/maintainers/skenow)

---

Top Contributors

[![MekDrop](https://avatars.githubusercontent.com/u/342641?v=4)](https://github.com/MekDrop "MekDrop (50 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![fiammybe](https://avatars.githubusercontent.com/u/3736946?v=4)](https://github.com/fiammybe "fiammybe (2 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

hacktoberfestsmartysmarty-pluginssymfony-translationssymfonytranslatesmartysmarty-plugins

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imponeer-smarty-translate/health.svg)

```
[![Health](https://phpackages.com/badges/imponeer-smarty-translate/health.svg)](https://phpackages.com/packages/imponeer-smarty-translate)
```

###  Alternatives

[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[itsmattburgess/laravel-translate

Populate laravel translation files using services such as Google Translate

222.5k](/packages/itsmattburgess-laravel-translate)

PHPackages © 2026

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