I just tried to submit a translation for a german page with has an outdated english translation. After submitting the translation job and investigating the "project" on the oht website, I saw that parts of the german source text were actually replaced with the outdated english text...

Is this by design (because it avoids re-translation) or a bug?

Comments

bforchhammer’s picture

Title: Entity content with existing translation » Translation job submitted with mixed-language source text

Better title.

miro_dietiker’s picture

Status: Active » Postponed (maintainer needs more info)

Seems a severe bug to me. Source is source and should never contain any translated item.

There is plan to add a feature to deal with changes but it will never behave that way. It will present the diffs to the editors when creating the job.
This however will not be introduced by TMHMT OHT but TMGMT core instead.

However, can you please provide a clean description on how to reproduce this? (step-by-step conditions, settings chosen)
We need to reproduce this easily to fix it.

berdir’s picture

I assume you're using entity translation?

Could be that we are somehow fetching the wrong field values from the source. Maybe some sort of language fallback configuration that gets in the way?

Something to help track this down would be to try another translator (e.g. file export or the test translator) if this is something that happens in TMGMT core.

berdir’s picture

Also, I think you known translatable fields/entity translation quite well, I suspect the error is in text_tmgmt_source_translation_structure() in tmgmt_field.module. We're calling field_language() there, which is probably wrong as something could change it to English.

bforchhammer’s picture

Project: BLEND Localization » Translation Management Tool
Component: Code » Core
Assigned: Unassigned » bforchhammer
Status: Postponed (maintainer needs more info) » Active

Yes, I'm using entity translation. And this does indeed also happen with the file translator, so I'm moving this to the tmgmt queue...

I suspect the error is in text_tmgmt_source_translation_structure() in tmgmt_field.module. We're calling field_language() there, which is probably wrong as something could change it to English

Yes, that sounds off. AFAIK field_language() falls back to the current display language (active content language) if the last parameter ($landcode) is not supplied... sounds like the fix might be to force that to the correct source language...

I'll see if I can produce a patch.

bforchhammer’s picture

Assigned: bforchhammer » Unassigned
Status: Active » Needs review
StatusFileSize
new3.29 KB

Here's a patch... :)

Steps to reproduce (with "file export translation"):

  1. Enable modules, add languages, configure the page content type to use translation "with field translation", make body field multilingual
  2. Create a page (source language does not have to be english), and then add some translations for the page via entity translation
  3. Request translation for a language which already has a translation
  4. Check the value of the body field in the exported file: with the attached patch it should match the actual source language, without the patch it will not always match up.
berdir’s picture

Thanks!

Wondering if we should already pass the field values in the correct language to the hook, that would simplify that a lot.

bforchhammer’s picture

Hm, we could just pass the result of field_get_items()... I can't say whether you'd ever need the entity object in a hook implementation.

berdir’s picture

Yes, I like this, looks much easier, I know that @swentel is doing some crazy things on saving the values back, see #1428900: Provide a hook for field types when populating translations., maybe check with him to see if this would affect him sowhoe.

+++ b/sources/entity/tmgmt_entity.plugin.incundefined
--- a/sources/field/tmgmt_field.api.php
+++ b/sources/field/tmgmt_field.api.phpundefined
@@ -16,6 +16,6 @@
  *
  * @ingroup tmgmt_source
  */
-function hook_tmgmt_source_translation_structure($field_name, $entity_type, $entity, $field_instance) {
+function hook_tmgmt_source_translation_structure($field_name, $field_values, $field_instance) {

I guess we need to update the api docs here, in case we actually have some :)

+++ b/sources/field/tmgmt_field.moduleundefined
@@ -64,7 +67,8 @@ function tmgmt_field_get_source_data($entity_type, $entity, $field_translation =
-    if ((!$field_translation || $info['translatable']) && $data = module_invoke($info['module'], 'tmgmt_source_translation_structure', $field_name, $entity_type, $entity, $field_instance)) {
+    $field_values = field_get_items($entity_type, $entity, $field_name, $source_langcode);

The fact that this did pass the tests might mean that we don't need that $field_translation flag anymore. Need to look at it again in detail. If that's so, the we can throw it away completely.

And we should also add some test coverage for this.

swentel’s picture

bforchhammer asked me to quickly chime in. I'm fine with the changes, I can still do what I want with the code I have in a custom project, I just need to track this in case the api changes :) However, you never know someone really really wants to check something on the entity object - although I can't think of a use case at this point, so I guess that's for the tmgmt's maintainers to decide.

berdir’s picture

Right, so what about this. We use the same arguments as hook_field_formatter_view() except $display, which means "$entity_type, $entity, $field, $instance, $langcode, $items". The advantage of that:

- $items is right there and easy to use
- If needed, you get all the information you need, the entity, language, field and field instance to do all kinds of crazy things
- It is familiar to everyone who is used to write field formatters/types, and that's developers likely do if they have to implement this hook.

I have a strange fail locally, let's see if this works here.

bforchhammer’s picture

Status: Needs review » Reviewed & tested by the community

Cool, makes sense and works for me! :-)

Thanks for chiming in, @swentel!

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Great, commited and documented in http://drupal.org/node/1873034.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.