PHP code example of atelierspierrot / internationalization
1. Go to this page and download the library: Download atelierspierrot/internationalization 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/ */
atelierspierrot / internationalization example snippets
// Creation of the I18n Loader
$i18n_loader = new \I18n\Loader(array(
// this is the directory where your language strings are defined
'language_directory' => __DIR__.'/i18n',
// this is the list of available languages
'available_languages' => array(
'en' => 'en_US_USD',
'gb' => 'en_GB_UKP',
'fr' => 'fr_FR_EUR'
),
'default_language' => 'en',
// this is the tag construction used for replacements in strings
// by default, "%arg%" will be replacement by the argument "arg" value
// as this will be passed to a 'sprintf' PHP function, literal percent is written '%%'
'arg_wrapper_mask' => "%%%s%%",
));
// Creation of the I18n instance (statically) passing it the Loader
$translator = \I18n\I18n::getInstance($i18n_loader);
// for instance:
'language_directory' => __DIR__.'/i18n/%s'
// will render, for the EN language:
'language_directory' => __DIR__.'/i18n/EN'
$translator->translate( 'string_index' [, array( arguments )] [, language code] )
$i18n_en = array (
'datetime_mask' => '%a %e %m %Y %H:%M:%S',
'test' => 'Test in english',
'test_args' => 'I received arguments : « %arg1% » and « %arg2% »',
'test_item_zero' => 'No item',
'test_item_one' => 'Just one item',
'test_item_two' => 'Two items',
'test_item_multi' => 'There are %nb% items',
);
$i18n->loadFile( my file path )
function _T(...) = $i18n->translate(...)
# or
function translate(...) = $i18n->translate(...)
function _P(...) = $i18n->pluralize(...)
# or
function pluralize(...) = $i18n->pluralize(...)
function _D(...) = $i18n->getLocalizedDateString(...)
# or
function datify(...) = $i18n->getLocalizedDateString(...)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.