PHP code example of romeoz / rock-i18n

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

    

romeoz / rock-i18n example snippets


use rock\i18n\i18n;

$i18n = new i18n;

$i18n->add('hello', 'Hello {{placeholder}}');

$i18n->translate('hello', ['placeholder' => 'world!']); // output: Hello world!

// or 

i18n::t('hello', ['placeholder' => 'Rock!']); // output: Hello Rock!

use rock\i18n\i18n;

$i18n = new i18n;

$i18n->addMulti([
    'en' => [                // locale
        'lang' => [         // category
            'hello' => 'Hello world!'
        ]
    ],
    'ru' => [
        'lang' => [
            'hello' => 'Привет мир!'
        ]
    ]
]);

use rock\i18n\i18n;

$config = [
    'pathDicts' => [ 
        'en' => [
                'path/to/en/lang.php',
                'path/to/en/validate.php',
            ]
        ]
     ]   
];
$i18n = new i18n($config);

// or

$paths = [ 
    'en' => [
         'path/to/en/lang.php',
         'path/to/en/validate.php',
     ]
];
$i18n->addDicts($paths);

$i18n->translate('hello');

i18n::t('hello');

use rock\i18n\i18n;

$i18n = new i18n;
$i18n->locale('fr');
$i18n->translate('hello');

use rock\i18n\i18n;

$i18n = new i18n;
$i18n->locale('fr')->category('validate');
$i18n->translate('