PHP code example of shypes / language-translator

1. Go to this page and download the library: Download shypes/language-translator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shypes / language-translator example snippets


use Shypes\language;

$Language = new language();

use Shypes\language;

$Language = new language([
    "__basedir" => "./",
    "langFolder" => 'lang'
]);

use Shypes\language;

$Language = new language([
    "default_lang" => "en",
    "ext" => ".json",
    "__basedir" => "./",
    "langFolder" => 'lang'
]);

// set your base directory
$Language->setBaseDir("./"));

// set your base directory
$Language->setLanguageDir('src/lang');

// set your default language
$Language->setDefaultLang('en');

// set the extention for yout language file, default is .json
$Language->setExtention(".txt");

// set the language in which you need

$Language->setActiveLang('ar');

// get the text base on the defined language key

$translated = $Language->get('email_phone_validation');

var_dump($translated);

// get the text base on the defined language key

$translated = Language.get('email_phone_validation', 'ar');

var_dump($translated);

use Shypes\language;

$Language = new language();

function testTranslate($language, $message) {

    global $Language;

    $translated =  $LangParser->translate($message, $language);
    $data = [
        "message" => $translated,
        "language" => $language
    ];

    var_dump($data);
}

testTranslate('ar','something_went_wrong');

testTranslate('en','missing_


$data = array(
    "success"=> "نجاح",
    "email_phone_validation"=> "لا يمكن أن يكون البريد الإلكتروني والهاتف فارغين",
    "something_went_wrong"=> "هناك خطأ ما!",
    "missing_

$translated = $Language->get('deliver_code', 'ar',  array('name'=>"John", 'code'=> 343923));

var_dump($translated);
$