Listener for the I18n behavior: try to reuse existing translations

If there is a multi-lingual text in the database that has the same strings for all the fields and languages we have, assign that id as our translation_id

This means that it is possible to save a text in just one language, and get translations in all other available languages 'for free'.

package WebEnq4_I18n
author Rolf Kleef

 Methods

Before saving the record, check if we can re-use existing translations.

preSave(\Doctrine_Event $event) 
see \Doctrine_Record_Listener::preSave()

Parameters

$event

Assign a new id to a translation

assignTranslationId(Object $data, integer $id) 

Parameters

$data

Object

Object with translations

$id

integer

Id to be assigned

Find the best translations we already have

findTranslation(Object $data) : mixed

Try to find a translation id where non of the fields is conflicting with the fields we have (that are non-empty strings)

todo Add better ways to check for actual changes?
todo Not possible to store a text without a translation for a field we want to keep empty?
todo Garbage collection?

Parameters

$data

Object

Record that holds translations

Returns

mixedItem id with translation to be reused or false if none found

Determine a new pseudo-unique id for a translation

newTranslationId() : integer

Returns

integerNew id