imponeer / smarty-translate
Library that provides trans modifier and block smarty extensions based on Symfony Translations contracts
Installs: 19 646
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- imponeer/smarty-extensions-contracts: ^3.0
- symfony/translation-contracts: ^2.3
Requires (Dev)
- phpunit/phpunit: ^8.0 || ^9.0
- symfony/translation: ^5.1 || ^6.2
README
Smarty Translate
This library adds new smarty block and var modifier trans
for using with Symfony Translation compatible library.
Installation
To install and use this package, we recommend to use Composer:
composer require imponeer/smarty-translate
Otherwise, you need to include manually files from src/
directory.
Registering in Smarty
If you want to use these extensions from this package in your project you need register them with registerPlugin
function from Smarty. For example:
$smarty = new \Smarty(); $transBlockPlugin = new \Imponeer\Smarty\Extensions\Translate\TransBlock($translator); $transModifierPlugin = new \Imponeer\Smarty\Extensions\Translate\TransVarModifier($translator); $smarty->registerPlugin('block', $transBlockPlugin->getName(), [$transBlockPlugin, 'execute']); $smarty->registerPlugin('modifier', $transModifierPlugin->getName(), [$transModifierPlugin, 'execute']);
Using from templates
Translations can be done from templates...
....with block function:
<{trans domain='admin'}>_AD_INSTALLEDMODULES<{/trans}>
...with modifier:
<{"_AD_INSTALLEDMODULES"|trans:[]:'admin'}>
Block function supports such attributes:
Var modifier also supports these attributes, but syntax is a bit different - trans:PARAMETERS:DOMAIN:LOCALE
How to contribute?
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try interactive GitHub tutorial.
If you found any bug or have some questions, use issues tab and write there your questions.