From 0fb4026d8bf72759a057d4d7b92eab13a41b3098 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 23 Jun 2016 18:10:16 +0200 Subject: [PATCH] Added: Change the displayed language function --- README.md | 14 +++++++++++--- examples/example.php | 1 + lang.class.php | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9497b52..058514b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/example.php b/examples/example.php index 8f3132a..2557674 100644 --- a/examples/example.php +++ b/examples/example.php @@ -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').'
'; echo $lang->get('something').'
'; diff --git a/lang.class.php b/lang.class.php index c800aa0..09ee481 100644 --- a/lang.class.php +++ b/lang.class.php @@ -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) {