Added: Change the displayed language function

This commit is contained in:
kolaente 2016-06-23 18:10:16 +02:00 committed by kola
parent 10ef326e08
commit 0fb4026d8b
3 changed files with 18 additions and 3 deletions

View File

@ -8,7 +8,7 @@ A Class which takes care of deploying your site in multiple languages.
$lang = new lang($defaultLanguage);
```
The default language, which will be used, if the users language is not found, is english. However, you can change this to any language you want.
The default language, which will be used if the users language is not found, is english. However, you can change this to any language you want.
```php
$lang->setLangFolder('../langs');
@ -21,15 +21,23 @@ For example `lang.en.php`.
The script will find the file and use it.
You can also define multiple langfiles to get the strings of (see example.php)
You can also define multiple langfiles to get the strings of (see example.php).
To output a string, simply run the following command:
To output a string, simply use the following command:
```php
$lang->get($identifier);
$lang->get('Home');
```
Where `$identifier` is the Key _**OR**_ the value defined in the default's langfile.
###Change the displayed language
You can change the displayed language to one the user selects. To do this, use this command:
```php
$lang->setCurrentLang($lang);
```
##Reserved Identifiers
The two idetifiers `__Lang__` and `__Countrycode__` are reserved identifiers and used by the script to output a list of all available languages to the user.

View File

@ -4,6 +4,7 @@ require_once '../lang.class.php';
$lang = new lang();
$lang->setLangFolder('langs/');
$lang->setLang('lang.es.php', 'es');
$lang->setCurrentLang('de');
echo $lang->get('Home').'<br/>';
echo $lang->get('something').'<br/>';

View File

@ -14,6 +14,12 @@ class lang
$this->langfiles = [];
}
//Change the current Language
function setCurrentLang($lang)
{
$this->lang = $lang;
}
//Get Langfiles by Folder
public function setLangFolder($folder)
{