Lukasz Józwiak - 2016-05-31 17:27:15 -
In reply to message 1 from Gary Smith
Hi
Class work on all 5 version but only test file use features 5.4+
bellow i give working code without things like (new a)->f([b]);
<?=setlocale(LC_ALL,'en_US');?>
<?php
require_once 'system/Helpers/Intl.php';
use \System\helpers\Intl as Intl;
Intl::$strings = array(
'text' => '',
'write' => '',
'read' => '',
'forget it' => '',
'put' => '',
'up' => '',
'down' => '',
'true' => '',
'text to you'=>'text dla ciebie',
);
echo Intl::_('text to you')."<br>"; // will return 'text dla ciebie'
echo Intl::_('you')."<br>"; // will return 'you' because not exist or not translated
Intl::$langdirpath = 'languages'; // can be 'languages' for example
//Intl::jsonsave(Intl::$strings,Intl::$langdirpath.DIRECTORY_SEPARATOR.'ru.json'); // save loaded strings to json file used for russian strings
var_dump(Intl::availablelocales()); // dump available locales files
echo Intl::autoloadlocale()."<br>"; // detect and load translated files if exist
echo Intl::defaultlocale()."<br>"; // return browser default language
echo Intl::_('text to me %hey',array('hey'))."<br>"; // return 'tekst dla mnie hejka też' before was ['hey'] and give errors on php less than 5.4, Sorry
echo Intl::_('text to you')."<br>"; // return 'tekst dla ciebie'
echo Intl::loadlocale('ru')."<br>"; // load locale file php, json or both and merge it with Intl::$strings loaded have priority php->json->first definied strings
class a{
function f()
{
echo Intl::_('text to me %hey',array('hey'))."<br>"; // return 'текст мне привет' before was ['hey']
echo Intl::_('text to you')."<br>"; // return 'text dla ciebie' because is definied in strings on top of this file
}
}
$a=new a;
$a->f(); // call class to test return retun strings
?>