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.
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.
composer require niyko/transpicious
'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.
'aliases' => [
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facade.................
.......
.......
'Transpicious' => Niyko\Transpicious\Transpicious::class
],
<body>
<h1>{!! Transpicious::translate('hello') !!}</h1>
<p>{!! Transpicious::translate('world') !!}</p>
</body>
return Transpicious::translate('world');
Transpicious::set_translate_to('es'); // es is the language code
You can find the full list of language code, CLICK HERE.
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
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>
In the top of the View add this line
use Niyko\Transpicious\Transpicious;
And in the controller use Transpicious like
return Transpicious::translate('world');
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.
1. Download the .zip version of Transpicious from this link,CLICK HERE.
use Niyko\Transpicious\Transpicious;
<body>
<h1><?php echo Transpicious::translate('hello') ?></h1>
<p><?php echo Transpicious::translate('world') ?></p>
</body>
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 :
<?php
$_DEFAULT_CONVERT_FROM = "en";
$_DEFAULT_CONVERT_TO = "en";
?>
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' |
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.
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",
}
}
}
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"
}
}
}
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');
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' |
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
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');
Parameters | Description | Requred | Value type | Example |
---|---|---|---|---|
'TRANSLATE TO' | The whole website's content will be translated to this language | YES |
String - Language code |
NO |
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
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.
الصباح لتناول القهوة والتأمل
*/
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();
CLICK HERE to check out all the language codes supported in Transpicious for automatic translation.
Transpicious is licensed under the GNU GENERAL PUBLIC LICENSE, And this repo is made for educational purpose.