sbs / yii2-transliterator-helper
The transliterator helper for the Yii 2 framework
Installs: 669
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 13
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpstan/phpstan: ^0.11
- phpstan/phpstan-phpunit: ^0.11
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-10-24 03:52:37 UTC
README
Transliterator Helper transliterates UTF-8 encoded text to US-ASCII.
Installation
The preferred way to install this extension is through composer.
Either run
composer require sbs/yii2-transliterator-helper
or add
"sbs/yii2-transliterator-helper": "*"
to the require section of your application's composer.json
file.
Usage
Pass to the method process()
the UTF-8 encoded string you wish to transliterate:
use sbs\helpers\TransliteratorHelper;
// will echo AAAAAAAECEEEEIIIIDNOOOOOUUUUYssaaaaaaaeceeeeiiiidnooooouuuuyy
TransliteratorHelper::process('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ', 'en'));
You can use it as application behavior:
use sbs\behaviors\SlugBehavior;
//...
public function behaviors()
{
return [
//...
[
'class' => SlugBehavior::class,
'attribute' => 'title',
'slugAttribute' => 'slug',
],
];
}
Since version 0.3 you can use SlugInput widget:
Configurations:
You need a registration controller in your main config file in section controllerMap
:
use sbs\controllers\TransliterationController; //... 'controllerMap' => [ 'transliteration' => [ 'class' => TransliterationController::class, 'lowercase' => false //provides transliteration to lower case, true by default. ] ], //...
Like a widget:
use sbs\widgets\SlugInput; echo SlugInput::widget([ 'name' => 'News[slug]', 'sourceName' => 'News[title]' ]);
Like an ActiveForm widget:
use sbs\widgets\SlugInput; echo $form->field($model, 'slug')->widget(SlugInput::class, [ 'sourceAttribute' => 'title' ]);
That's all. Enjoy.