An open API service indexing awesome lists of open source software.

https://github.com/themahabbat/lang-php

Language changer for PHP
https://github.com/themahabbat/lang-php

change changer global lang language php variables

Last synced: 5 months ago
JSON representation

Language changer for PHP

Awesome Lists containing this project

README

          

# 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
```php
$_GET['lang'],
'available' => ['az', 'en'],
'default' => 'az',
'cookie' => 'LANG',
'cookieExpire' => time()+86400*24*7

]);
```

## Usage
### Single Key
Gets keyName from current language's json file

Example JSON: `{ "keyName": "Hi there!" }`
```php
key('keyName'); // Hi there!
```

### Nested keys

Example JSON: `{ "keyName": [ {"inside": "This is the value inside keyName" } ] }`
```php
key('keyName@inside'); // This is the value inside keyName
```

### Variables

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

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