Hey,

> We are close to migrating our public site from a flat html site to 
> plone, we have a deadline of the 4th of April and we've hit a brick wall 
> with our conversion scripts for linguaplone (mapping the english content 
> to the existing spanish and french content and vice versa so that the 
> content plays nice with linguaplone).
> 
> Is there anyone out there who can help with the correct usage of and 
> interactions between the following routines:
> 
>     addTranslationReference()
>     removeTranslationReference()
>     getTranslations()

if you want to add a translation for an existing object, the correct
way to do it is: (considering that canonical.Language() != '',
otherwise set it first!):

  language = 'pt-br'
  canonical.addTranslation(language)
  translation = canonical.getTranslation(language)

If you only want to link two existing objects, all you need to do is
(we also consider that translation.Language() != '', otherwise you
first need to set it too!):

  translation.addTranslationReference(canonical)

That's it.

> The code fragments on http://dev.plone.org/plone/changeset/10329 don't 
> seem to work correctly. The addTranslationReference() function seems to 
> operate in the other direction.

I haven't reviewed that piece of code yet, so I won't comment on
it now.

But you can base your script in the API tests:

http://dev.plone.org/plone/browser/LinguaPlone/trunk/tests/testAPI.py

> Specific questions would be:
> 
> 1. Does addTranslationReference() add a symetric link, or do we need to 
> add links in both directions?
> (Sometimes we've tried a single link and it seems to work both ways, 
> other times not)

All translations must have a 'translationOf' reference pointing to the
cononical object. The canonical object doesn't has any 'translationOf'
reference to any other object.

So, answering this question: you only need to add references to the
translations objects.

Supposing you have two objects, english and portuguese, each one with
a different language. At this point, both objects are canonicals, as
they don't have any references. Now we'll add a translation reference
to portuguese, pointing to english:

  portuguese.addTranslationReference(english)

At this point, only english is canonical, as portuguese now has a
reference pointing to english.

BTW, when you add a reference 'foo' to T, pointing to C, you can:

a) get C from T:

  >>> C in T.getRefs('foo')
  True

b) get T from C:

  >>> T in C.getBRefs('foo')
  True

Note that getBRefs means 'get the backward reference'.

I hope this makes the things a bit more clear now... :-)

> 2. Do we need to use removeTranslationReference() before we can have 
> another 'hack' at the catalog, or can we just keep resetting the 
> translations (We're asking this as re-running the same script 
> progressively produces more errors.)

You can't add a new translation for a language that is already
translated. So it only makes sense to call removeTranslationReference
when you want to unlink two existing objects.

So the first thing before calling addTranslationReference is to check
if the language isn't translated yet:

  if content.Language() not in canonical.getTranslationLanguages():
      content.addTranslationReference(canonical)

I'll probably add this 'guard' to the LinguaPlone code in the next
versions.

> 3. Do we have to use getTranslations() to refresh some sort of cache 
> before applying new settings ( as seems apparent at 
> http://dev.plone.org/plone/changeset/10329 ), or is it just for reading 
> translation settings?

It should not be necessary.

> 4. How do we get error information back from these routines?

When calling addTranslation with an already translated language,
you'll get a AlreadyTranslated exception. I'm not sure what happens
when you directly call addTranslationReference in this case...

> 5. Is there any documentaion beyond what is in the linguaplone product 
> package?

Unfortunately, no. On the other hand, the LinguaPlone tests covers
the complete API, which is a good start for developers.

You're welcome to write additional documentation as you go... :-)

> I know this should probably go to the plone users list and I'll send it 
> there if that is more appropriate but I just wanted to ask here first 
> because I know more people on this list, which makes me braver :-)

I didn't knew about this list until Limi point me to your message...
:-)

> Many thanks to anyone who replies :)

HTH,

-- 
 ___________________________________________________________________

       Dorneles Treméa · Developer · Plone Solutions · Brazil

   Consulting · Training · Development · http://plonesolutions.com
 ___________________________________________________________________

  Plone Foundation · http://plone.org/foundation · Protecting Plone


_______________________________________________
NGO mailing list
NGO@lists.plone.org
http://lists.plone.org/mailman/listinfo/ngo

Reply via email to