PHP code example of initphp / translator

1. Go to this page and download the library: Download initphp/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/ */

    

initphp / translator example snippets



use \InitPHP\Translator\Translator;

$lang = new Translator();
$lang->setDir(__DIR__ . '/languages/')
    ->setDefault('en');

$lang->change('tr'); // Set Current Language

echo $lang->_r('hello');


return [
    'hello'     => 'Hello {user}',
    'today'     => 'It\'s {day}',
];


use \InitPHP\Translator\Translator;

$lang = new Translator;
$lang->useFile(); // Note that it is used first of all.
$lang->setDir(__DIR__ . '/languages/')
    ->setDefault('en');

echo $lang->_r('hello');


use \InitPHP\Translator\Translator;

$lang = new Translator;
$lang->useDirectory(); // Note that it is used first of all.
$lang->setDir(__DIR__ . '/languages/')
    ->setDefault('en');

// The filename and keyname are separated by dots.
// Example : "filename.key"
echo $lang->_r('user.hello');

public function setDir(string $dir): self

public function setDefault(string $default): self

public function useFile(): self;

public function useDirectory(): self;

public function change(string $current): self

public function _r(string $key, ?string $default = null, array $context = []): string

public function _e(string $key, ?string $default = null, array $context = []): void

/languages/
    en.php
    tr.php
    fr.php

/languages/
    en/
        user.php
        admin.php
        profile.php
    tr/
        user.php
        admin.php
        profile.php