Download the PHP package imponeer/smarty-translate without Composer
On this page you can find all versions of the php package imponeer/smarty-translate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download imponeer/smarty-translate
More information about imponeer/smarty-translate
Files in imponeer/smarty-translate
Package smarty-translate
Short Description Library that provides trans modifier and block smarty extensions based on Symfony Translations contracts
License MIT
Informations about the package 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 compatible library. It allows you to easily translate your Smarty templates using the powerful Symfony translation system.
Installation
The recommended way to install this package is through Composer:
Alternatively, you can manually include the files from the src/
directory in your project.
Setup
Basic Setup
To register the translation extension with Smarty, add the extension class to your Smarty instance:
Using with Symfony Container
To integrate with Symfony, you can leverage autowiring, which is the recommended approach for modern Symfony applications:
Then in your application code, you can simply retrieve the pre-configured Smarty instance:
For more information about Symfony's Dependency Injection Container, see the official documentation.
Using with PHP-DI
With PHP-DI container, you can take advantage of autowiring for a very simple configuration:
Then in your application code, you can retrieve the Smarty instance:
For more information about PHP-DI Container, see the official documentation.
Using with League Container
If you're using League Container, you can register the extension like this:
Then in your application code, you can retrieve the Smarty instance:
For more information about League Container, see the official documentation.
Usage
Once the extension is registered, you can use it in your Smarty templates in two ways:
1. Using the Block Function
The block function allows you to translate blocks of text:
2. Using the Variable Modifier
The variable modifier allows for inline translations:
Supported Attributes
Both the block function and variable modifier support the following attributes:
Attribute | Description | Default Value |
---|---|---|
parameters | Key/value pairs to replace placeholders in translated strings | [] |
domain | Translation domain (usually corresponds to translation file) | system default |
locale | Specific locale to use for translation | current system locale |
For the variable modifier, the syntax is: trans:PARAMETERS:DOMAIN:LOCALE
Testing
This package includes a comprehensive test suite. To run the tests:
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.
Contributing
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature-name
- 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.