PHP code example of sonofwinter / translation-bundle
1. Go to this page and download the library: Download sonofwinter/translation-bundle 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/ */
// Translate an entity to a specific language
$translator->translate($entity, 'en');
// Translate an entity to multiple languages
$translator->translateForLangs($entity, ['en', 'fr', 'de']);
// Set a single translation
$translator->setTranslationForLangAndValue($entity, 'en', 'firstname', 'John');
// Set multiple values for one language
$translator->setTranslationForLangAndValues($entity, 'en', [
'firstname' => 'John',
'lastname' => 'Doe'
]);
// Set multiple translations for multiple languages
$translator->setTranslations($entity, [
'en' => [
'firstname' => 'John',
'lastname' => 'Doe'
],
'fr' => [
'firstname' => 'Jean',
'lastname' => 'Dupont'
]
]);
// Remove a specific translation
$translator->removeByObjectKeyAndLang($entity, 'firstname', 'en');
// Remove all translations for an entity
$translator->removeAllForTranslatable($entity);
// Remove all translations for a specific key
$translator->removeAllByKey('firstname');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.