Download the PHP package mnapoli/doctrine-translated without Composer

On this page you can find all versions of the php package mnapoli/doctrine-translated. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package doctrine-translated

Translated strings for Doctrine

Build Status Coverage Status Scrutinizer Code Quality Total Downloads

This library is an alternative to the Translatable extension for Doctrine.

The basic idea is to shift from "something that magically manages several versions of the same entity" to "my entity's field is an object that contains several translations".

It aims to be extremely simple and explicit on its behavior, so that it can be reliable, maintainable, easily extended and understood. The goal is to do more with less.

Requirements

This library requires PHP 5.4 and Doctrine 2.5!

How it works

The library relies on a new major feature of Doctrine 2.5: embedded objects. An embedded object will see its properties inserted in the entity that uses it.

Example:

If you use YAML instead of annotations:

The TranslatedString is defined by you by extending Mnapoli\Translated\AbstractTranslatedString. That way, you can define the languages you want to support. This class is reusable everywhere in your application, so you only need to define it once.

As you can see, the properties must be public.

Here is the same mapping in YAML:

You can then start translating that field:

Usually in your application, you will not want to hardcode "en" or "fr" when reading or setting the value. This is because the current locale varies from request to request.

That is why this library provides helpers to make it much easier, along with the Translator object.

Example:

Current integrations:

The configuration step is very straightforward:

The Mnapoli\Translated\Integration\Symfony2\TranslatedBundle is provided. You need to register the bundle in AppKernel.php:

Then in your app/config/config.yml:

The TranslatedBundle will automatically listen to the request's locale and configure the Translator accordingly.

That means you have nothing to do: just use the Translator, and it will use the request's locale to translate things.

If the current locale is not stored inside the request, you will need to set up an event listener manually. Here is an basic example using the session:

When the user logs in, his/her locale is stored inside the session. Here is the configuration:

You can then use the helper in views:

Watch out: the translate view helper already exists in ZF1. The example shown here will override it. You can use a name different than "translate" if you don't want to override it.

Pros and cons

With that method, you will end up with only one table in database:

This makes it very good for performances, and for other reasons:

However, be aware there are cons:

Translator

You saw above a basic example of using the translator.

Here is all you can do with it:

To create a new translation from scratch:

Operations

Sometimes you need to concatenate strings in a model, so you can't use the translator (and you maybe don't want to).

You can do some basic operations on the translated strings.

Concatenation

You can also create a string concatenation from scratch:

Implode

Just like the concatenation:

Untranslated strings

Sometimes you should give or return a TranslatedString but you have a non-translated string. For example:

Here there is a problem: '-' is a simple string, and if the calling code expects a TranslatedString then it won't work.

For this, you can simply create an "untranslated" string:

It will have the same value (or translation) for every language.

Fallbacks

You can define fallbacks on the Translator:

As you can see, fallbacks are optional, and can be multiple.

Now the translator will use those fallbacks:

You will note that you can also directly use fallbacks on the TranslatedString object:

Doctrine

Documentation currently being written

There are no changes regarding persisting or retrieving an entity. When you load an entity from database, all the translations will be loaded.

However, due to the fact that Product::name is not a string anymore, you cannot simply filter on the field. You need to write queries like this:

The same goes for ORDER BY:

The $lang (current locale) can be obtained from the Translator.

I am looking at ways to makes this more simple, for example with a DQL function (https://github.com/mnapoli/DoctrineTranslated/blob/master/src/Doctrine/TranslatedFunction.php). Feel free to help, currently this is stuck because Doctrine instantiate the "function" classes itself, which prevents using dependency injection to inject the current locale (or translator).

Current issue opened at Doctrine: #991.


All versions of doctrine-translated with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
doctrine/orm Version 2.5.*@dev
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mnapoli/doctrine-translated contains the following files

Loading the files please wait ....