PHPackages                             that0n3guy/transliteration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. that0n3guy/transliteration

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

that0n3guy/transliteration
==========================

Transliteration provides one-way string transliteration (romanization) and cleans text by replacing unwanted characters.

2.0.9(1y ago)1296.5k↓21.1%4[1 issues](https://github.com/that0n3guy/transliteration/issues)[1 PRs](https://github.com/that0n3guy/transliteration/pulls)4MITPHPPHP &gt;=5.3.0

Since Apr 14Pushed 1y ago2 watchersCompare

[ Source](https://github.com/that0n3guy/transliteration)[ Packagist](https://packagist.org/packages/that0n3guy/transliteration)[ RSS](/packages/that0n3guy-transliteration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (18)Used By (4)

Transliteration - Laravel 4, 5, 6, 7, 8, 9 &amp; 10 text cleaning Package
=========================================================================

[](#transliteration---laravel-4-5-6-7-8-9--10-text-cleaning-package)

Transliteration provides one-way string transliteration (romanization) and cleans text by replacing unwanted characters.

> ...it takes Unicode text and tries to represent it in US-ASCII characters (universally displayable, unaccented characters) by attempting to transliterate the pronunciation expressed by the text in some other writing system to Roman letters.

This adapts the module from  for use with Laravel.

Features
--------

[](#features)

- Transliterate text to US-ASCII characters

Why use this?
-------------

[](#why-use-this)

- I use this for filename on uploads. See this image:

[![](https://camo.githubusercontent.com/9ba3f75375060cccb50f5a7503183288b3850a6680cb6d8acd134337e86a95f5/68747470733a2f2f64727570616c2e6f72672f66696c65732f7374796c65732f677269642d332f7075626c69632f696d616765732f7472616e736c69745f302e706e673f69746f6b3d43774b4150427442)](https://camo.githubusercontent.com/9ba3f75375060cccb50f5a7503183288b3850a6680cb6d8acd134337e86a95f5/68747470733a2f2f64727570616c2e6f72672f66696c65732f7374796c65732f677269642d332f7075626c69632f696d616765732f7472616e736c69745f302e706e673f69746f6b3d43774b4150427442)\*

- I use this with [Andrew Elkins's Cabinet](https://github.com/andrewelkins/cabinet)

Quick start
-----------

[](#quick-start)

Install the package via Composer:

```
composer require that0n3guy/transliteration

```

Depending on your version of Laravel, you should install a different version of the package.

Laravel VersionPackage Version10.0^2.09.0^2.08.0^2.07.0^2.06.0^2.05.0^2.04.0^1.0In your `config/app.php` add `'That0n3guy\Transliteration\TransliterationServiceProvider'` to the end of the `$providers` array

```
'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'That0n3guy\Transliteration\TransliterationServiceProvider',

),
```

### How to use

[](#how-to-use)

Simply call the Transliteration class:

```
Route::get('/test', function(){
  echo Transliteration::clean_filename('test& ® is true');
});
```

This would return `test_r_is_true`

### Set a language

[](#set-a-language)

You can optionally set a [Optional ISO 639 language code](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). Do it like so:

```
Route::get('/test', function(){
  echo Transliteration::clean_filename('testing Japanese 日本語', 'jpn');
});
```

This would return `testing_Japanese_Ri_Ben_Yu_`.

How to use to rename file uploads (sanitize them)
-------------------------------------------------

[](#how-to-use-to-rename-file-uploads-sanitize-them)

This is an old example, but still relevant. It uses [Cabinet](https://github.com/andrewelkins/cabinet) which I don't really recommend using anymore since there are better options.

Add something like:

```
// if using transliteration
if (class_exists( 'That0n3guy\Transliteration\Transliteration' )) {
  $file->fileSystemName = Transliteration::clean_filename($file->getClientOriginalName());  // You can see I am cleaning the filename
}
```

To your Upload controller. For example. I added it to my UploadController.php and my store() method looks like so:

```
/**
 * Stores new upload
 *
 */
public function store()
{
    $file = Input::file('file');

    // if using transliteration
    if (class_exists( 'That0n3guy\Transliteration\Transliteration' )) {
      $file->fileSystemName = Transliteration::clean_filename($file->getClientOriginalName());
    }

    $upload = new Upload;

    try {
        $upload->process($file);
    } catch(Exception $exception){
        // Something went wrong. Log it.
        Log::error($exception);
        $error = array(
            'name' => $file->getClientOriginalName(),
            'size' => $file->getSize(),
            'error' => $exception->getMessage(),
        );
        // Return error
        return Response::json($error, 400);
    }

    // If it now has an id, it should have been successful.
    if ( $upload->id ) {
      ...
```

Example how to use with octobercms
==================================

[](#example-how-to-use-with-octobercms)

- Create a plugin, for this example I'll call it `that0n3guy.drivers`. You can see documentation here:
- Add a bootPackages method to your `Plugin.php` as per the instructions here (copy/paste it straight from that page):
- Add `that0n3guy/transliteration` to your plugins composer.json file:

```
    "require": {
        "that0n3guy/transliteration": "^2.0"
    }

```

Create a config file in your plugins config folder (create this folder) just like . File structure example:

```
that0n3guy
    drivers
        config
            config.php
        Plugin.php

```

The config file should contain:

```
