Closed (fixed)
Project:
Translation Management Tool
Version:
8.x-1.x-dev
Component:
Translator: Local
Priority:
Major
Category:
Feature request
Assigned:
Reporter:
Created:
29 Jun 2016 at 13:44 UTC
Updated:
3 Aug 2016 at 21:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
miro_dietikerWe discussed this requirement and it seems clear that TMGMT need to provide support for masking while editing.
So if we have an Editor that need tag masking, it means
- The text area will not show the original values. Instead it will show the masked values.
- On submission, the masking is reverted.
For this, two hooks should be provided:
- One that is triggered before we output the values in the form.
- One that is triggered when the values are taken from form state and applied to the job/data item.
This allows easy implementation of the ckeditor integration.
Mind that both hooks will receive the alterable variable with the single data text. And additionally, they will get job item / job context so they know what they have to do.
Comment #3
berdirThey will get *two* contexts. $data_item and $job_item.
Comment #4
sasanikolic commentedThis issue is about mapping the data from source to the translation editor. I think we should open another one for tag masking.
Comment #5
miro_dietikerYeah sorry i thought after our discussion, the description was incomplete.
Now that most of the discussion about the data mangling hooks is here, why not create a separate issue to discuss the mapping?
Comment #6
sasanikolic commentedComment #7
sasanikolic commentedAs per our discussion, we redefined the tags structure.
If the the tag starts with
<b>, without any attributes, the masked tag should look like this:<tmgmt-tag element=”b” raw=”<b>”>Or, if the html element, for example starts with
<img alt=... title=...>- has attributes, the tag would like this:<tmgmt-tag element=”img” raw=”<img src=... alt=... title=...>”>In the examples above, element represents the name of the html tag, while the raw is the encoded tag. Don't forget about the closing tags. When unmasking, the process will simply replace tmgmt-tag with its raw property.
With this implementation though, the alt and title attributes could not be translated and be placed back/saved untranslated, even though they could be translatable. We'd need to find a proper solution for this.
We'd also need tests for this two possibilities.
Comment #8
tduong commentedHere is a starting patch, to see if this approach works good. Still need to discuss about considering to add a context to distinguish source from translation and if the unmask hook is placed in the right place.
And of course still need test coverage.
Comment #9
miro_dietikerHmm, we extract $text and allow altering it, but it is later not used?! It should be attached to $data IMHO otherwise it won't have any effect?
I think the two hooks need documentation in .api file.
Comment #10
tduong commentedDone + starting test coverage.
Next step will be to implement some real masking as part of @sasanikolic's project as a pull request on github against his project, so we have a real case before committing the patch. Will do this on monday.
Comment #11
miro_dietikerLooks pretty nice.
I think we should always trigger this alter...
The case where translation is empty could be important to initialise it with empty segment-only tags or filled with source text and special indication "needs translation".
Comment #12
tduong commentedI've just added a check where it could be possible to handle the tags thing for this empty case. Now I'll create a PR in the github project to provide a real example.
Comment #13
tduong commentedStarted with some regex to mask/unmask the hardcoded b- and img-tags. Created PR here. Still work in progress.
Comment #14
miro_dietikerAccidental revert of 9d74ad9
Comment #15
tduong commentedSorry, forgot to update my feature branch :P
Comment #16
miro_dietikerOK, discussed and decided...
We learned with the segmenter and the editors that we should think in source + translation pairs.
Thus the hook should also operate on the pair level.
See JobItemForm::reviewFormElement()
The hook should fire before buildSource and buildTranslation, and the modified masked text should be passed into these methods as a new argument.
The submission only needs to operate on the translation. Unmasking source is not needed.
And then, we can finally commit this. :-)
Comment #17
tduong commentedDone. Improved some comments and code.
Comment #18
tduong commentedJust a small improvement :p
Comment #19
miro_dietikerHmm we should never attach temporary processed values to an entity. Anyone in the chain could trigger a save and thus accidentally persist the temporary value.
Instead create separate properties, variables as derivatives and pass them forward separately.
Here the intention was / is to add a $text argument to the buildXYZ methods (and yes, change their declaration!)
Comment #20
tduong commentedAlright, done.
Comment #21
berdirAlmost there, just a bit of cleanup and comment improvements.
As discussed, simplify to $text = ...; no $original_text needed.
$contetx needs to use array keys ('data_item' => $data_item, 'job_item' => $this->entity)
First comment: Allow other modules to change the source and translation text, for example to mask HTML tags.
Remove the second comment, that is logic that belongs in tmgmt_ckeditor (for now).
And the @todo can be removed.
(the code is fine)
list the keys with their content. See hook_entity_view_display_alter()
Comment #22
tduong commentedDone as suggested above.
Comment #23
berdirThanks, now I'm happy with it. Committed.