Developed with love by KnpLabs Hire us for your project!
7

MultilangContentBundle

by ralf57

Support for multilanguage doctrine documents on top of phpcr-odm

A first draft of a multilanguage bundle.

Introduces a new document annotation to store language specific content.
Translations are stored as child nodes of the node.

The annotations are:

  • @cmfTranslate:Language => language this document is currently in
  • @cmfTranslate:Translated => language specific field

Documents can use phpcr: annotations for language independent fields, but
translated fields may have no phpcr annotation or they will be stored twice.

On loading, the best available language is automatically loaded into the
document, you don't need to do anything special. The bundle registers for the doctrine events and acts on postLoad.

For storing documents, you need the service with the name symfony_cmf_multilang_content_node_translation and call persistTranslation($document) on it for each language. After each call, update the language specific fields and the Language field according to your data and call persistTranslation again.

# Example

class Document
{
    /** @phpcr:Id */
    protected $path;
    /** @phpcr:Node */
    protected $node;

    /**
     * @validation:NotBlank
     * @cmfTranslate:Language
     */
    public $lang;
    /**
     * @validation:NotBlank
     * @cmfTranslate:Translated
     */
    public $title;
    /**
     * @phpcr:String()
     */
    public $url;

    public function getNode()
    {
      return $this->node;
    }
}

//controller
$translator = $this->container->get('symfony_cmf_multilang_content_node_translation');
$document = new Document(); //your odm document class
$document->url = 'http://github.com';
$document->lang = 'en';
$document->title = 'my title';
$translator->persistTranslation($document);
$document->lang = 'de';
$document->title = 'mein titel';
$translator->persistTranslation($document);

TODO

  • is the architecture of this bundle sane?
  • can we do without the need for persistTranslation?
  • how to delete a translation?
  • Use a namespace for the child node instead of lang~
  • Removed obsolete method call
    By ralf57, 6 years ago
  • Edited README.md via GitHub
    By lsmith77, 6 years ago
  • Edited README.md via GitHub
    By lsmith77, 6 years ago
  • Edited README.md via GitHub
    By lsmith77, 6 years ago
  • adding note about namespace
    By dbu, 6 years ago
  • adding code sample and improving readme
    By dbu, 6 years ago
  • adapting to phpcr-odm making non-saving flush more obvious. will need to be refactored when the odm supports more things
    By dbu, 6 years ago
  • do a soft flush that does not persist to backend yet
    By dbu, 6 years ago
  • improve an error message and added doc
    By dbu, 6 years ago
  • fixing typo
    By dbu, 6 years ago
  • initial commit
    By dbu, 6 years ago