Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boshurik/twig-petrovich-extension
https://github.com/boshurik/twig-petrovich-extension
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/boshurik/twig-petrovich-extension
- Owner: BoShurik
- License: mit
- Created: 2020-06-17T16:48:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-25T10:40:06.000Z (over 4 years ago)
- Last Synced: 2024-10-12T23:11:08.092Z (3 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Petrovich Twig Extension
![Petrovich](https://raw.github.com/rocsci/petrovich/master/petrovich.png)
## Installation
```bash
composer req boshurik/twig-petrovich-extension
``````php
use Staticall\Petrovich\Petrovich;
use Staticall\Petrovich\Petrovich\Loader;
use BoShurik\Petrovich\Twig\Extension\PetrovichExtension;
use Twig\Environment;$petrovich = new Petrovich(Loader::load('/path/to/rules.json'));
$extension = new PetrovichExtension($petrovich);
$twig = new Environment($loader);
$twig->addExtension($extension);
```You can use callable to lazy loading `Petrovich` instance
```php
use Staticall\Petrovich\Petrovich;
use Staticall\Petrovich\Petrovich\Loader;
use BoShurik\Petrovich\Twig\Extension\PetrovichExtension;$factory = function () {
return new Petrovich(Loader::load('/path/to/rules.json'));
};
$extension = new PetrovichExtension($factory);
```## Usage
```twig
{{ 'Тестов Тест Тестович' | inflect_full_name('genitive', 'male') }}
{{ 'Тестов Тест Тестович' | inflect_full_name('dative') }}
{{ 'Тестов Тест Тестович' | inflect_full_name_accusative }}
{{ 'Тестов Тест Тестович' | inflect_full_name_instrumental_male }}{{ inflect_full_name('Тестов Тест Тестович', 'genitive', 'male') }}
{{ inflect_full_name('Тестов Тест Тестович', 'dative') }}
{{ inflect_full_name_accusative('Тестов Тест Тестович') }}
{{ inflect_full_name_instrumental_male('Тестов Тест Тестович') }}
```