Download the PHP package terminal42/dc_multilingual without Composer
On this page you can find all versions of the php package terminal42/dc_multilingual. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dc_multilingual
DC_Multilingual
This is a standalone DC driver for Contao Open Source CMS that allows you to easily make your data translatable.
DCA configuration
Example usage
Querying using the model
How does it work under the hood
Basically, the driver just stores translations into the same table, building up
a relationship to its parent entry using the "langPid" (or whatever you
configured it to be) column. In the back end list and tree view it makes sure
translations are filtered so you only see the fallback language there.
When querying using the Multilingual
model or using the
MultilingualQueryBuilder
, the same table is simply joined so we have the
fallback language aliased as t1
and the target language (which you specify
explicitly or it uses the current page's language) aliased as translation
. Now, using
MySQL's IFNULL()
function, it checks whether there's a translated value and
if not, automatically falls back to the fallback language. This allows you to
translate only a subset of fields.
Alias handling
You can share the alias for all translations, so you'd have something like this:
* EN: domain.com/my-post/my-beautiful-alias.html
* DE: domain.de/mein-artikel/my-beautiful-alias.html
* FR: domain.fr/mon-post/my-beautiful-alias.html
This can be achieved by using the regular alias handling you may know from
other modules such as news etc. in the back end and for the front end you simply
use the findByAlias()
method which the Multilingual
model provides:
However, there are many situations where you would like to have your aliases translated so you end up with something like this:
* EN: domain.com/my-post/my-beautiful-alias.html
* DE: domain.de/mein-artikel/mein-wunderschoenes-alias.html
* FR: domain.fr/mon-post/mon-alias-magnifique.html
In the back end it's slightly more difficult now because it does not make sense
to check for duplicate aliases within the whole table but only within the whole
table and the same language. To make this as easy as possible for you, simply
use the following eval
definitions on your alias
field:
It will automatically generate an alias if not present yet and check for duplicates within the same language.
In the front end you can then search by a multilingual alias like this:
Usage with Doctrine entities
Since the driver only writes data to the database from the backend, it is fully compatible with using Doctrine entities in the frontend. For now, you must take care of translations yourself though. Here's how an entity could look like:
Useful notes
- Sometimes a table you want to make multilingual already contains the
language
field (e.g.tl_user
), which may lead to unexpected results. In such cases you have to make sure that data container's property$GLOBALS['TL_DCA']['tl_table']['config']['langColumnName']
is set to something else thanlanguage
. See #53 for more details.
All versions of dc_multilingual with dependencies
contao/core-bundle Version ^4.13.51
doctrine/dbal Version ^2.11 || ^3.0