Skip to content
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
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
custom_translations
src
LICENSE
README.md
composer.json
config.php
supported_language_codes.md

README.md

Transpicious logo

Transpicious converts yours website's 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 any other language on wish. Transpicious automatically converts the website's content to any one of 90 supported language on the fly. Transpicious supports is Laravel, Codeigniter and Normal 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

You can install via Composer or 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

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

    '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 :

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

3. Writing the content with Transpicious

Using Transpicious in Laravel View

    <body>
        <h1>{!! Transpicious::translate('hello') !!}</h1>
        <p>{!! Transpicious::translate('world') !!}</p>
    </body>

Or using Transpicious in Laravel Controller

     return Transpicious::translate('world');

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.

If you are using Codeigniter

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

Like shown here :

    $config['composer_autoload'] = TRUE;

This line will be seen right around line number 140

3. Writing the content with Transpicious

Using Transpicious in Codeigniter View

In the top of the View add this line

    <?php
        use Niyko\Transpicious\Transpicious;
    ?>

And use Transpicious in the view's html like

    <body>
        <h1><?php echo Transpicious::translate('hello') ?></h1>
        <p><?php echo Transpicious::translate('world') ?></p>
    </body>

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

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.

If you are using Normal PHP, Like me

1. Download the .zip version of Transpicious from this link,CLICK HERE.

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

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

    <body>
        <h1><?php echo Transpicious::translate('hello') ?></h1>
        <p><?php echo Transpicious::translate('world') ?></p>
    </body>

 

 

Configuring Transpicious

There is not that much configuration 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 :

<?php
    $_DEFAULT_CONVERT_FROM = "en";	
    $_DEFAULT_CONVERT_TO = "en";
?>

configuration definition

Variable Description Value type Example
$_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?

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

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

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

Transpicious::translate();

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

Parameters Description Requred Value type Example
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 :

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();

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

Parameters Description Requred Value type Example
'TRANSLATE TO' The whole website's content will be translated to this language YES String - Language code NO

Example usage :

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)

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');   // <= Note that translate() has a 2nd parameter
     
     /* The output will be :-
        Las mañanas son para el café y la contemplación.
        الصباح لتناول القهوة والتأمل
     */

Transpicious::clear_cache();

Used to clear the cached translations files, Note: After clearing the cache, the site will take sometime to render on first run

     Transpicious::clear_cache();

All supported language codes

CLICK HERE to check out all the language codes supported in Transpicious for automatic translation.

License

Transpicious is licensed under the GNU GENERAL PUBLIC LICENSE, And this repo is made for educational purpose.

You can’t perform that action at this time.