What'd be a good pattern on Doctrine to have multiple languages

Posted by PERR0_HUNTER on Stack Overflow See other posts from Stack Overflow or by PERR0_HUNTER
Published on 2010-02-03T01:08:31Z Indexed on 2010/03/27 18:03 UTC
Read the original article Hit count: 432

Filed under:
|
|
|

Hi!

I have this challenge which consist in having a system that offers it's content in multiple languages, however a part of the data contained in the system is not translatable such as dates, ints and such.

I mean if I have a content on the following YAML

Corporativos:
  columns:
    nombre:
      type: string(254)
      notnull: true
    telefonos:
      type: string(500)
    email:
      type: string(254)
    webpage:
      type: string(254)
CorporativosLang:
  columns:
    corporativo_id:
      type: integer(8)
      notnull: true
    lang:
      type: string(16)
      fixed: false
    ubicacion:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    contacto:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    tipo_de_hoteles:
      type: string(254)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    paises:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    Corporativo:
      class: Corporativos
      local: corporativo_id
      foreign: id
      type: one
      foreignAlias: Data

This would allow me to have different corporative offices, however the place of the corp, the contact and other things can be translate into a different language (lang)

Now this code here would create me a brand new corporative office with 2 translations

    $corporativo = new Corporativos();

    $corporativo->nombre = 'Duck Corp';
    $corporativo->telefonos = '66303713333';
    $corporativo->email = '[email protected]';
    $corporativo->webpage = 'http://quack.com';

    $corporativo->Data[0]->lang = 'en';
    $corporativo->Data[0]->ubicacion = 'zomg';

    $corporativo->Data[1]->lang = 'es';
    $corporativo->Data[1]->ubicacion = 'zomg amigou';

the thing now is I don't know how to retrieve this data in a more friendly way, because if I'd like to access my Corporative info in english I'd had to run DQL for the corp and then another DQL for the specific translation in english,

What I'd love to do is have my translatable fields available in the root so I could simply access them

    $corporativo = new Corporativos();

    $corporativo->nombre = 'Duck Corp';
    $corporativo->telefonos = '66303713333';
    $corporativo->email = '[email protected]';
    $corporativo->webpage = 'http://quack.com';
            $corporativo->lang = 'en';
    $corporativo->ubicacion = 'zomg';

this way the translatable fields would be mapped to the second table automatically.

I hope I can explain my self clear :(

any suggestions ?

© Stack Overflow or respective owner

Related posts about doctrine

Related posts about php