jLanguage
is a class for implement a multi-language system based in JSON, fast and easy in your web site.
Require the class:
require_once 'src\jLanguage\jLanguage.php';
Create new instance of class:
$jLang = new jLanguage(array(
'lang_default' => 'en' // necessary.
));
Select the sections to use:
$jLang->set_section('index');
// or
$jLang->set_section(array('index', 'home'));
Create a json file in your folder json data whit the name of language:
/*en.json*/
{
"index":
{
"hello": "Hello world."
}
}
In your output file write:
[[hello]]
And jLanguage returns:
Hello world.
The configuration is the following concepts:
$config = array(
'auto_shutdown' => true, // (bool) Execute a function at the end of the script to translate the text automatically.
'auto_load' => true, // (bool) Load json files automatically.
'lang_default' => null, // (string) Language file to be charged.
'auto_location' => true, // (bool) Automatically load the language of language, as the language of the user's browser.
'base_dir' => dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data-lang' // Location of the json files.
);
$jLang = new jLanguage($config);
Note: In case that the shutdown function it's not automatically, you can call this function to get the translated text:
$return = $jLang->return_shutdown();
Note 2: In case that the load function it's not automatically, you can load the json files following this code:
$jLang->load();
If you enable the option auto-location
in the jLanguage configuration, you can to use a multiple files of same language but for different locations, for example:
es.json
=> Spanish.
en.json
=> English.
ch.json
=> Chinese.
(See http://www.science.co.il/Language/Codes.asp for more information about language codes).