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
- Host: GitHub
- URL: https://github.com/themahabbat/lang-php
- Owner: themahabbat
- Created: 2018-04-22T10:36:47.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-22T18:32:01.000Z (about 8 years ago)
- Last Synced: 2024-04-23T20:43:59.317Z (about 2 years ago)
- Topics: change, changer, global, lang, language, php, variables
- Language: PHP
- Size: 17.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 !
```