PHP code example of abeliani / translated-slug-helper

1. Go to this page and download the library: Download abeliani/translated-slug-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abeliani / translated-slug-helper example snippets


$slug = new TranslatedSlugHelper(
    new Settings('ru'),
    new TranslatedBy(Translit::class)
);

print $slug->from('Привет мир!', 'en'); // privet-mir

$slug = new TranslatedSlugHelper(
    new Settings('ru', ['a', 'an']), // to remove words from slug (eg. a, an) we can pass them by array
    new TranslatedBy(MyMemory::class, ['apiKey' => 'someapikey'])
);

print $slug->from('Привет мир!', 'en'); // hello-world


$chain = [
   new TranslatedBy(MyMemory::class, ['apiKey' => 'someapikey']),
   new TranslatedBy(Translit::class),
];

$slug = new TranslatedSlugHelper(
    new Settings('ru'),
    ...$chain,
);

print $slug->from('Привет мир!', 'en'); // if MyMemory service is available: hello-world | otherwise by transilt driver: privet-mir

// Passing new divider +
new Settings('ru', [], '+')