PHPackages                             niyko/transpicious - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. niyko/transpicious

ActiveLibrary[Localization &amp; i18n](/categories/localization)

niyko/transpicious
==================

Transpicious converts yours website's content in any language you want, automatically, You can also give custom translations if needed. Transpicious supports is Laravel, Codeigniter and Normal PHP

1.0.0(6y ago)8231MITPHPPHP &gt;=5.4.0

Since Jan 7Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Niyko/Transpicious)[ Packagist](https://packagist.org/packages/niyko/transpicious)[ RSS](/packages/niyko-transpicious/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

[![Transpicious logo](https://camo.githubusercontent.com/395599d6d1a6c71199a04b990a0918445801587c9d451dd61ee349a3115c91a5/68747470733a2f2f692e696d6775722e636f6d2f746561506a4a772e706e67)](https://camo.githubusercontent.com/395599d6d1a6c71199a04b990a0918445801587c9d451dd61ee349a3115c91a5/68747470733a2f2f692e696d6775722e636f6d2f746561506a4a772e706e67)

### Transpicious converts yours website's content in any language you want, automatically.

[](#transpicious-converts-yours-websites-content-in-any-language-you-want-automatically)

Yea, You heard it right, Now you can write the content of the website in any language and the user can change it to any other language on wish. Transpicious automatically converts the website's contents to any one of the 90 supported language on the fly. Transpicious supports is Laravel, Codeigniter and core PHP. This is a very useful package to integrate multi language (multi locale) functionality to your code. You can also give custom translations if needed.

🌀 Simple Installation, Even a baby 👶 can do it
----------------------------------------------

[](#cyclone-simple-installation-even-a-baby-baby-can-do-it)

**You can install via `Composer` or by downloading the `Source zip`.**You can install Transpicious via Composer or by downloading the source code from the github repository, Continue reading for knowing more about installing Transpicious. Don't worry its super super easy.

### If you are using `Laravel`

[](#if-you-are-using-laravel)

#### 1. Open the terminal from the project folder and Run this command in your command line:

[](#1-open-the-terminal-from-the-project-folder-and-run-this-command-in-your-command-line)

```
    composer require niyko/transpicious

```

#### 2. Add this line in to your `config/app.php` in the `aliases` array like this

[](#2-add-this-line-in-to-your-configappphp-in-the-aliases-array-like-this)

```
    'Transpicious' => Niyko\Transpicious\Transpicious::class
```

> Don't remove the other classes in the array, just add the above line in to it

After adding the line to the file, the array `aliases` in `config/app.php` may look like this.

##### Eg :

[](#eg-)

```
'aliases' => [
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facade.................
        .......
        .......
        'Transpicious' => Niyko\Transpicious\Transpicious::class
],
```

#### 3. Writing the content with Transpicious

[](#3-writing-the-content-with-transpicious)

##### Using Transpicious in `Laravel View`

[](#using-transpicious-in-laravel-view)

```

        {!! Transpicious::translate('hello') !!}
        {!! Transpicious::translate('world') !!}

```

##### Or using Transpicious in `Laravel Controller`

[](#or-using-transpicious-in-laravel-controller)

```
     return Transpicious::translate('world');
```

#### 4. Changing the language from user part

[](#4-changing-the-language-from-user-part)

```
     Transpicious::set_translate_to('es');   // es is the language code
```

> You can find the full list of language code, [CLICK HERE](https://github.com/Niyko/Transpicious/blob/master/supported_language_codes.md).

### If you are using `Codeigniter`

[](#if-you-are-using-codeigniter)

#### 1. Open the terminal from the `application` folder inside your project, and Run this command in your command line:

[](#1-open-the-terminal-from-the-application-folder-inside-your-project-and-run-this-command-in-your-command-line)

```
    composer require niyko/transpicious

```

#### 2. Open `YOUR PROJECT/application/config.php` and change the value of `$config['composer_autoload']` to `TRUE`

[](#2-open-your-projectapplicationconfigphp-and-change-the-value-of-configcomposer_autoload-to-true)

Like shown here :

```
    $config['composer_autoload'] = TRUE;
```

> This line will be seen right around line number 140

#### 3. Writing the content with Transpicious

[](#3-writing-the-content-with-transpicious-1)

##### Using Transpicious in `Codeigniter View`

[](#using-transpicious-in-codeigniter-view)

In the top of the View add this line

```

```

And use Transpicious in the view's html like

```

```

##### Or using Transpicious in `Codeigniter Controller`

[](#or-using-transpicious-in-codeigniter-controller)

In the top of the View add this line

```
     use Niyko\Transpicious\Transpicious;
```

And in the controller use Transpicious like

```
     return Transpicious::translate('world');
```

#### 4. Changing the language from user part

[](#4-changing-the-language-from-user-part-1)

In the top of the View add this line

```
     use Niyko\Transpicious\Transpicious;
```

And to change the language use,

```
     Transpicious::set_translate_to('es');   // es is the language code
```

> You can find the full list of language code, [CLICK HERE](https://github.com/Niyko/Transpicious/blob/master/supported_language_codes.md).

### If you are using `Core PHP`

[](#if-you-are-using-core-php)

##### 1. Download the .zip version of Transpicious from this link,[CLICK HERE](https://github.com/Niyko/Transpicious/archive/1.0.0.zip).

[](#1-download-the-zip-version-of-transpicious-from-this-linkclick-here)

##### 2. Unzip the file and extract it to your project's folder

[](#2-unzip-the-file-and-extract-it-to-your-projects-folder)

##### 3. In the top of your php file, add this line

[](#3-in-the-top-of-your-php-file-add-this-line)

```
     use Niyko\Transpicious\Transpicious;
```

##### 4. And to use Transpicious, to print content, use like

[](#4-and-to-use-transpicious-to-print-content-use-like)

```

```

#####

[](#)

[![](https://camo.githubusercontent.com/8673e012a67dced99aabe2ae6743b1c119d3822ab4d71f9a99cc7fc6a5b9aa60/68747470733a2f2f692e696d6775722e636f6d2f647531774262452e706e67)](https://camo.githubusercontent.com/8673e012a67dced99aabe2ae6743b1c119d3822ab4d71f9a99cc7fc6a5b9aa60/68747470733a2f2f692e696d6775722e636f6d2f647531774262452e706e67)

#####

[](#-1)

⚙️ Configuring Transpicious
---------------------------

[](#gear-configuring-transpicious)

There is not that much configurations in Transpicious, All the configuration are given in the file `Transpicious-1.0.0/config.php` (if you are using `composer` then it will be `vendor/niyko/transpicious/config.php`). The configuration file will look like this :

```

```

#### configuration definition

[](#configuration-definition)

VariableDescriptionValue typeExample`$_DEFAULT_CONVERT_FROM`Language code of the language which is used to write the content of the website`String` - Language code`'en'`, `'sp'`, `'hi'``$_DEFAULT_CONVERT_TO`Language code of the defualt language of the website, The content will be shown in this lanuage when the user is firstly enters the website`String` - Language code`'en'`, `'sp'`, `'hi'`What if some of the automatically gentrated translation is wrong?
-----------------------------------------------------------------

[](#what-if-some-of-the-automatically-gentrated-translation-is-wrong)

If any translation that is automatically gentrated is worng, then you can define the correct on in the `custom translation`. To know more about how to add custom translations, keep reading the next topic.

📝 Adding custom translations
----------------------------

[](#pencil-adding-custom-translations)

#### `Method 1` Adding it in the custom translation file

[](#method-1-adding-it-in-the-custom-translation-file)

Inside the `Transpicious` folder (if you are using `composer` then it will be `vendor/niyko/transpicious`), there is a folder called `custom_translations`, inside that there is a file called `custom_translations.json`. You can add your custom translations in this file using the below syntax.

```
     {
        "LANGUAGE CODE OF CONVERTED FROM" : {
            "CONTENT 1" : {
                "1ST LANGUAGE CODE OF CONVERTED TO" : "TRANSLATION",
                "2ND LANGUAGE CODE OF CONVERTED TO" : "TRANSLATION",
            },
            "CONTENT 2" : {
                "1ST LANGUAGE CODE OF CONVERTED TO" : "TRANSLATION",
                "2ND LANGUAGE CODE OF CONVERTED TO" : "TRANSLATION",
            }
        }
    }
```

##### Didn't got it? Look at an example

[](#didnt-got-it-look-at-an-example)

If I am using `Transpicious::translate('hello, I'm Lilly')` in the content, And if you want to change the automatic translation of this content in the `spanish` language, the the `custom_translations.json` file will look like this :

```
     {
        "en" : {
            "hello, I'm Lilly" : {
                "es" : "hola soy lilly"
            }
        }
    }
```

📚 API
-----

[](#books-api)

### Transpicious::translate();

[](#transpicioustranslate)

This function is used to give the content of the website. `translate()` function supports three parameters which all of them are string, Which are :

```
     Transpicious::translate('CONTENT', 'TRANSLATE TO', 'TRANSLATE FROM');
```

#### Function definition

[](#function-definition)

ParametersDescriptionRequredValue typeExample`CONTENT`Content that needs to be translated`YES``String``'hello'`, `'world'``TRANSLATE TO`The content will be translated to this language, Overidding the language given in `$_DEFAULT_CONVERT_TO` in `config.php`,
 ***Note: This will only be applied to this `CONTENT`, the rest on the website will be translated based on `config.php` if this parameter is absent***`NO``String` - Language code`'en'`, `'sp'`, `'hi'``TRANSLATE FROM`The content will be recognized as this language, Overidding the language given in `$_DEFAULT_CONVERT_FROM` in `config.php`,
 ***Note: This will only be applied to this `CONTENT`, the content on rest of the website will be recognized based on `config.php` if this parameter is absent***`NO``String` - Language code`'en'`, `'sp'`, `'hi'`##### Example usage :

[](#example-usage-)

*If the `config.php` is set as `$_DEFAULT_CONVERT_FROM = "en"` and `$_DEFAULT_CONVERT_TO = "en"`*

```
     Transpicious::translate('Friends don’t lie');                      // Returns Friends don’t lie
     Transpicious::translate('Friends don’t lie', 'es');                // Returns Los amigos no mienten
     Transpicious::translate('Los amigos no mienten', 'ch', 'es');      // Returns 朋友不撒谎
     Transpicious::translate('Los amigos no mienten', null, 'es');      // Returns Friends don’t lie
```

### Transpicious::set\_translate\_to();

[](#transpiciousset_translate_to)

This function is used to change the current language of the website. All the content of the website will be translated to the language that is given as the parameter of this function

```
     Transpicious::set_translate_to('TRANSLATE TO');
```

#### Function definition

[](#function-definition-1)

ParametersDescriptionRequredValue typeExample'TRANSLATE TO'The whole website's content will be translated to this language`YES``String` - Language code`NO`##### Example usage :

[](#example-usage--1)

###### Example (1)

[](#example-1)

*If the `config.php` is set as `$_DEFAULT_CONVERT_FROM = "en"` and `$_DEFAULT_CONVERT_TO = "en"`*

```
     Transpicious::set_translate_to('es');
     echo Transpicious::translate('She‘s our friend and she‘s crazy.');

     // The output will be : Ella es nuestra amiga y está loca
```

###### Example (2)

[](#example-2)

*If the `config.php` is set as `$_DEFAULT_CONVERT_FROM = "en"` and `$_DEFAULT_CONVERT_TO = "en"`*

```
     Transpicious::set_translate_to('es');
     echo Transpicious::translate('Mornings are for coffee and contemplation');
     echo Transpicious::translate('Mornings are for coffee and contemplation', 'ar');   //
