PHP code example of mouseeatscat / phpquicktranslate
1. Go to this page and download the library: Download mouseeatscat/phpquicktranslate 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/ */
mouseeatscat / phpquicktranslate example snippets
use MouseEatsCat\QuickTranslate;
empty($_GET['language']) ? $_GET['language']: 'en';
// Instantiate PHP Quick Translate
$qt = new QuickTranslate($language);
// Single-Language JSON files
$qt->addTranslationSource('/translations/en.json', 'en');
$qt->addTranslationSource('/translations/fr.json', 'fr');
// OR Multilingual JSON file
$qt->addTranslationSource('/translations/multilingual.json');
// OR Path to translations directory
$qt->addTranslationSource('/translations/');
echo $qt->t('translation_key');
// OR echo using a method
$qt->et('translation_key');
$qt->et([
'en' => 'English Test',
'fr' => 'French Text'
]);
// OR Alternative
$qt->et('[:en]English Text[:fr]French Text');
// Instantiate PHP Quick Translate
$qt = new QuickTranslate('language');
// Translate
$qt->t('translation_key');
// Same as t() except with echo
$qt->et('translation_key');
// Set the current language
$qt->setLanguage('language');
// Get the current language
$qt->getLanguage();
// Add a translation
$qt->addTranslation('language', 'translation_key', 'translation_value');
// Add a JSON translation source file directory
// translation source file directory
$qt->addTranslationSource('path/to/json/translations/');
// Individual translation source file
$qt->addTranslationSource('path/to/json/translations/language.json', 'language');
$qt->addTranslationSource('path/to/json/translations/multilingual.json');
// Add array or translations
// (single language + multilingual)
$qt->addTranslations(['translation_key' => 'translation_value'], 'language');
$qt->addTranslations([
'translation_key' => [
'en' => 'translation_value',
'fr' => 'translation_value'
]
]);
// Determine if a translation exists for given key
// If language isn't provided, the current language will be used
$qt->hasTranslation('translation_key', 'language');
// Gets the translation for given key
// If language isn't provided, the current language will be used
$qt->getTranslation('translation_key', 'language');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.