Language changer for PHP
Add "minimum-stability": "dev"
to composer.json
Run composer require themahabbat/lang
current
: Current language
available
: Array of available languages
dir
(optional): Directory of language files exists (default: lang)
default
: Default language if current language doesn't match available languages
cookie
(optional): Cookie name (default: LANG)
cookieExpire
(optional): Expire time for cookies in Unix timestamp (default: 168 days)
Script finds .json
files in given language directory then initializes it
<?php
require_once 'vendor/autoload.php';
use Mahabbat\Lang;
$L = Lang::init([
'current' => $_GET['lang'],
'available' => ['az', 'en'],
'default' => 'az',
'cookie' => 'LANG',
'cookieExpire' => time()+86400*24*7
]);
Gets keyName from current language's json file
Example JSON: { "keyName": "Hi there!" }
<?php
echo $L->key('keyName'); // Hi there!
Example JSON: { "keyName": [ {"inside": "This is the value inside keyName" } ] }
<?php
echo $L->key('keyName@inside'); // This is the value inside keyName
Example JSON: { "keyName": "Hello :name !" }
$values = [ 'name' => 'Mahabbat!' ];
echo $L->key('keyName', $values); // Hello Mahabbat !