PHP code example of philipp15b / php-i18n

1. Go to this page and download the library: Download philipp15b/php-i18n 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/ */

    

philipp15b / php-i18n example snippets



	


	$i18n = new i18n();


	$i18n->setCachePath('./tmp/cache');
	$i18n->setFilePath('./langfiles/lang/lang_{LANGUAGE}.ini'); // language file path
	$i18n->setLangVariantEnabled(false); // trim region variant in language codes (e.g. en-us -> en)
	$i18n->setFallbackLang('en');
	$i18n->setPrefix('I');
	$i18n->setForcedLang('en'); // force english, even if another user language is available
	$i18n->setSectionSeparator('_');
	$i18n->setMergeFallback(false); // make keys available from the fallback language


	$i18n = new i18n('lang/lang_{LANGUAGE}.ini', 'langcache/', 'en');


	$i18n->init();


	echo L::greeting;
	// If 'en' is applied: 'Hello World'

	echo L::category_somethingother;
	// If 'en' is applied: 'Something other...'

	echo L::last_modified("today");
	// Could be: 'Last modified: today'

	echo L($string);
	// Outputs a dynamically chosen static property

	echo L($string, $args);
	// Same as L::last_modified("today");



	 My_i18n extends i18n {

		public function getUserLangs() {
			$userLangs = new array();

			$userLangs[] = $_GET['language'];

			$userLangs[] = $_SESSION['userlanguage'];

			return $userLangs;
		}

	}

	$i18n = new My_i18n();
	// [...]