项目作者: themahabbat

项目描述 :
Language changer for PHP
高级语言: PHP
项目地址: git://github.com/themahabbat/Lang-PHP.git
创建时间: 2018-04-22T10:36:47Z
项目社区:https://github.com/themahabbat/Lang-PHP

开源协议:

下载


Lang-PHP

Language changer for PHP

Initialization

Add "minimum-stability": "dev" to composer.json

Run composer require themahabbat/lang

Parameters

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)

How it works

Script finds .json files in given language directory then initializes it

Code

  1. <?php
  2. require_once 'vendor/autoload.php';
  3. use Mahabbat\Lang;
  4. $L = Lang::init([
  5. 'current' => $_GET['lang'],
  6. 'available' => ['az', 'en'],
  7. 'default' => 'az',
  8. 'cookie' => 'LANG',
  9. 'cookieExpire' => time()+86400*24*7
  10. ]);

Usage

Single Key

Gets keyName from current language’s json file

Example JSON: { "keyName": "Hi there!" }

  1. <?php
  2. echo $L->key('keyName'); // Hi there!

Nested keys

Example JSON: { "keyName": [ {"inside": "This is the value inside keyName" } ] }

  1. <?php
  2. echo $L->key('keyName@inside'); // This is the value inside keyName

Variables

Example JSON: { "keyName": "Hello :name !" }

  1. $values = [ 'name' => 'Mahabbat!' ];
  2. echo $L->key('keyName', $values); // Hello Mahabbat !