Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imponeer/smarty-translate
Library that provides trans modifer and block smarty extensions based on Symfony Translations contracts
https://github.com/imponeer/smarty-translate
hacktoberfest smarty smarty-plugins symfony-translations
Last synced: 2 months ago
JSON representation
Library that provides trans modifer and block smarty extensions based on Symfony Translations contracts
- Host: GitHub
- URL: https://github.com/imponeer/smarty-translate
- Owner: imponeer
- License: mit
- Created: 2021-01-31T20:31:37.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-01T09:05:28.000Z (5 months ago)
- Last Synced: 2024-10-03T00:18:41.363Z (3 months ago)
- Topics: hacktoberfest, smarty, smarty-plugins, symfony-translations
- Language: PHP
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![License](https://img.shields.io/github/license/imponeer/smarty-translate.svg)](LICENSE)
[![GitHub release](https://img.shields.io/github/release/imponeer/smarty-translate.svg)](https://github.com/imponeer/smarty-translate/releases) [![Maintainability](https://api.codeclimate.com/v1/badges/79f89e2fe21c0076c29a/maintainability)](https://codeclimate.com/github/imponeer/smarty-translate/maintainability) [![PHP](https://img.shields.io/packagist/php-v/imponeer/smarty-translate.svg)](http://php.net)
[![Packagist](https://img.shields.io/packagist/dm/imponeer/smarty-translate.svg)](https://packagist.org/packages/imponeer/smarty-translate)# Smarty Translate
This library adds new smarty block and var modifier `trans` for using with [Symfony Translation](https://github.com/symfony/translation) compatible library.
## Installation
To install and use this package, we recommend to use [Composer](https://getcomposer.org):
```bash
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](https://www.smarty.net/docs/en/api.register.plugin.tpl) from [Smarty](https://www.smarty.net). For example:
```php
$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:
```smarty
<{trans domain='admin'}>_AD_INSTALLEDMODULES<{/trans}>
```
...with modifier:
```smarty
<{"_AD_INSTALLEDMODULES"|trans:[]:'admin'}>
```Block function supports such attributes:
| Atribute | What it does? | Default value |
|----------|-----------------|----------------|
| parameters | Key/value lists that should be replaced in translated string | [] |
| domain | Domain from where to get translation string (in most cases same as translation file) | *(system default value)* |
| locale | Translate in specific locale | *(current system locale)* |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](https://skills.github.com).
If you found any bug or have some questions, use [issues tab](https://github.com/imponeer/smarty-translate/issues) and write there your questions.