Skip to content
Uzbek latin <=> cyrillic transliterator
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
tests
.editorconfig
.gitattributes
.gitignore
.scrutinizer.yml
.styleci.yml
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

Uzbek transliterator

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Uzbek latin <=> cyrillic transliterator. Under the hood it uses some online transliteration services. But it's extendable!

Navigation by sections

Install

Via Composer

$ composer require zvermafia/uzbek-transliterator

Usage

Out of the box there are two implementations for your choice:

  1. Zvermafia\Transliteration\AlifTransliterator which uses an alif.uz online transliteration service's API;
  2. Zvermafia\Transliteration\LotinTransliterator which uses a lotin.uz online transliteration service's API;

Also you can implement your own class which will use another service's API or won't use any services' API and does all the job by itself.

require __DIR__ . "/vendor/autoload.php";

// Initialize the object
$transliterator = new Zvermafia\Transliteration\AlifTransliterator(); // or you can use LotinTransliterator

$transliterator->setText("Salom, dunyo!")
    ->toCyrillic()
    ->translit();

echo $transliterator->getResult(); // it will output: Салом, дунё!

Make your own implementation (extending)

If these two already exist implementations aren't enough for you, then you can extend functionalities of this package by implementing your own transliterator class. If so there are three possible ways:

  1. Create a class by implementing a Zvermafia\Transliteration\Interfaces\TransliteratorInterface interface. In this case you must realize all the methods defined in the interface from scratch by yourself;
  2. This is the recommended way (if you're not going to use third party APIs with HTTP). Create a class by extending Zvermafia\Transliteration\Abstracts\TransliteratorAbstract abstract class. In this case you must realize only that methods which aren't already realized by the abstract class. The abstract class already realized common methods of the interface;
  3. This one is similar to the previous way. Because in this case you'll use a Zvermafia\Transliteration\Abstracts\HttpTransliteratorAbstract abstract class which is extends by the Zvermafia\Transliteration\Abstracts\TransliteratorAbstract. But what is the difference? The difference is in this abstract class realized some common methods which will work with the HTTP through the cURL extension. So you must only configure some specific HTTP request parameters to work with an API.

So here are examples by the points.

An example for the point number 1:

<?php

namespace Whatever\Namespace;

use Zvermafia\Transliteration\Interfaces\TransliteratorInterface;

// point #1
class MyTransliterator implements TransliteratorInterface
{
    // realize all the methods defined in the interface (
}

An example for the point number 2:

<?php

namespace Whatever\Namespace;

use Zvermafia\Transliteration\Abstracts\TransliteratorAbstract;
use Zvermafia\Transliteration\Interfaces\TransliteratorInterface;

// point #1
class MyTransliterator extends TransliteratorAbstract
{
    public function translit(): : TransliteratorInterface
    {
        $text = $this->getText();
        // $result = ... // here translit the text
        $this->setResult($result);

        return $this;
    }
}

An example for the point number 3:

As examples for this point you can see source codes of Zvermafia\Transliteration\AlifTransliterator and Zvermafia\Transliteration\LotinTransliterator.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email mohirjon@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.