Download the PHP package arxy/entity-translations-bundle without Composer
On this page you can find all versions of the php package arxy/entity-translations-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arxy/entity-translations-bundle
More information about arxy/entity-translations-bundle
Files in arxy/entity-translations-bundle
Package entity-translations-bundle
Short Description This bundle provides translations for entities in your project. It's a bundle, but can be used standalone.
License MIT
Informations about the package entity-translations-bundle
EntityTranslationsBundle
Very simple bundle that allows you to translate your entities.
Installation:
it is recommented to install X.Y.* version - This project follow semver - Patch versions will be always compatible with each other. Minor versions may contain minor BC-breaks.
- composer require arxy/entity-translations-bundle
- Register bundle in AppKernel.php:
new Arxy\EntityTranslationsBundle\ArxyEntityTranslationsBundle()
- Translatable must
implements \Arxy\EntityTranslationsBundle\Model\Translatable
- Translations must
implements \Arxy\EntityTranslationsBundle\Model\Translation
- You must have 1 entity containing all the languages, it must
implements \Arxy\EntityTranslationsBundle\Language
- Include services.xml in config.yml:
No configuration is needed. Current and fallback locales are taken from Symfony:
Symfony Translations
How to Work with the User's Locale
Example entities:
Language
News.php
NewsTranslations.php
Then you can translate them on yourself
Internal API:
If you wish to change language of all managed entities:
You can change language of single entity:
$initializedLocale
is actual locale initialized in entity - it's not necessary to be bg
, it could be one of fallback locales.
Argument #2 can be either string locale or Language entity.
You can detach entity from manager
So it won't be affected by locale changing.
If you wish to get single translation without initialize it, you can use:
Argument #2 can be either string locale or Language entity.
You can also use translator to translate objects instead of using setCurrentTranslation.
Argument #3 is optional. If omitted current locale is assumed.
You can also use class instead of key for accessing service:
You can also use embedded Twig filters to translate in twig:
or get the whole translation:
Using form to easily translate entities.
Translatable should have addTranslation
, removeTranslation
(
see by-reference
and
How to Work with Doctrine Associations / Relations
):
Translation should implements EditableTranslation
instead of simple Translation
Load form theme (optionally)
Use '@ArxyEntityTranslations/bootstrap_3_tab_layout.html.twig'
for Bootstrap 3 support.
You need to create translation's form.
And then you can:
in your main form.
It's important to include required
in entry_language_options
for specific locales, because validation is triggered
only when language is not empty or it's required.
Language is assumed as not empty when at least one of the fields are filled in.