PHP code example of philasearch / i18n

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

    

philasearch / i18n example snippets




use Philasearch\I18n\I18n as Lang;

$lang = new Lang( dirname(__FILE__) . '/config/locales' );



use Philasearch\I18n\I18n as Lang;

$lang = new Lang( dirname(__FILE__) . 'config/locales' );

/**
 * normal translated string
 *
 * @param string $locale
 * @param string $key
 */
$lang->get( 'en', 'example.foo' ); // returns 'bar'


/**
 * nested translated strings
 *
 * @param string $locale
 * @param string $key
 */
$lang->get( 'en', 'example.nested.foo' ); // returns 'bar'

/**
 * Variable translated string
 *
 * @param string $locale
 * @param string $key
 */
$lang->get( 'en', 'example.var', ['var' => 'bar']); // returns 'foo bar'

/**
 * Plural tranlated strings
 *
 * @param string $locale
 * @param string $key
 * @param int    $count
 */
$lang->get( 'en', 'example.plural', ['color' => 'red'], 1); // returns 'A red apple'
$lang->get( 'en', 'example.plural', ['color' => 'red'], 2); // returns '2 red apples'

/**
 * Dialect translated strings
 */
$lang->get( 'en_US', 'example.foo' );         // returns 'murica'
$lang->get( 'en_US', 'example.nested.foo' );  // returns 'bar' as it falls back to en