Skip to content
Add PHP Multilingual Support
Branch: master
Clone or download
Latest commit 0045833 Jul 23, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples English Language Jul 23, 2016
phrases Create English.json Jul 23, 2016
LICENSE Initial commit Jul 23, 2016
PHPMultilingual.php PHPMultilingual Jul 23, 2016
README.md Cleanup Jul 23, 2016
example.php Create example.php Jul 23, 2016

README.md

PHP Multilingual

Add PHP Multilingual Support to a Website.


Are you interested in having a multilingual website ?

The solution is PHPMultilingual.

Usage

Include PHPMultilingual

 require __DIR__ . "/Class.Phrase.php";


###Phrases file The first thing we need to do is to create a Phrases files that will contain the text for each of the languages that will be supported by the website. For demo purpose I have chosen English. Make a directory named “directory”. In this directory create one file: ``English.json`` Here’s the content: ```json { "welcome": "Welcome", "date": "Today is : {{date}}" } ``` #### Include variable: ``` {{VAR_NAME}} ``` ``` {{date}} ``` #### Notice * Should be a valid JSON object.

### Multilingual The second thing we need to do is to create a extend class that will allow process the **Phrases File**. For demo purpose I have chosen English as Class Name.
namespace PHPMultilingual;
class English extends \ITCB\APP\TextProcessing\PHPMultilingual{
      protected $language = 'en-US'; // Language code.
      protected $configs =[ 
            // Would be used when call unavailable phrase
            "emptyPhrase" => "_Empty_", 
             // Phrases File path.
            "phrasesFile" =>  __DIR__ . "/English.json",
             //Enable Translation.
            "doTranslation" => false, 
            //Language Code.
            "language" => "en-US"

      ];
      function translation($str){
            return $str;
      }
}

Get Phrase

require __DIR__ . "/English.php";
$Language = new PHPMultilingual\English;
print "<h1>". $Language->get('welcome') . "<h1/>";
$date = date("y-M-d");
echo $Language->get('date'); // date phrase containing Variable called date 
You can’t perform that action at this time.