PHP Classes

intl 1.0

Recommend this page to a friend!

      Intl like gettext  >  All threads  >  intl 1.0  >  (Un) Subscribe thread alerts  
Subject:intl 1.0
Summary:Package details states php 5 but has errors for php 5.3
Messages:2
Author:Gary Smith
Date:2016-05-30 23:54:20
 

  1. intl 1.0   Reply   Report abuse  
Picture of Gary Smith Gary Smith - 2016-05-30 23:54:20
Package details states php 5 but has errors for php 5.3

The following error occurs for php 5.3:
Parse error: syntax error, unexpected '[' in X:\test.php on line 31

It would be helpful if the code worked for all versions of php 5 as claimed. Where I wanted to test it out does not have a different version.

  2. Re: intl 1.0   Reply   Report abuse  
Picture of Lukasz Józwiak 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&#380;' 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 '&#1090;&#1077;&#1082;&#1089;&#1090; &#1084;&#1085;&#1077; &#1087;&#1088;&#1080;&#1074;&#1077;&#1090;' 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

?>