PHP code example of gokhankurtulus / multilanguage

1. Go to this page and download the library: Download gokhankurtulus/multilanguage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gokhankurtulus / multilanguage example snippets


use MultiLanguage\MultiLanguage;

MultiLanguage::setDirectoryPath(__DIR__ . DIRECTORY_SEPARATOR . "Lang");
MultiLanguage::setAllowedLanguages(["en", "tr", "de"]);
MultiLanguage::setDefaultLanguage("en");
MultiLanguage::setCurrentLanguage("tr");

// Output will be "Homepage" because $lang parameter is set to 'en'.
// If $lang is null or empty tries to get current language
// if current is not defined then tries to get default language
// if both not defined and $lang is not given throws an LanguageException
echo MultiLanguage::translate('Homepage', 'en');

// Output will be "Anasayfa" because current language is 'tr'.
echo MultiLanguage::translate('Homepage');

// Output will be "Hallo John Doe".
// Specify unique keys in the language file then you can manipulate them.
// In this example, if your key is located many places in string it will change all of them.
echo MultiLanguage::translate('Hello', 'de', ['#name#' => 'John', '$lastname$' => 'Doe']);

MultiLanguage::translate(string  $text, ?string $lang = null, array $replacement = []);

MultiLanguage::getDirectoryPath();
MultiLanguage::setDirectoryPath(string $directoryPath, bool $force = false);

MultiLanguage::getAllowedLanguages();
MultiLanguage::setAllowedLanguages(array $languages);
MultiLanguage::isAllowedLanguage(string $lang);

MultiLanguage::getDefaultLanguage();
MultiLanguage::setDefaultLanguage(string $lang);

MultiLanguage::getCurrentLanguage();
MultiLanguage::setCurrentLanguage(string $lang);