not out of the box, you can set properties and doctypes to be exluded on sets, but not via a flag from the user.
however you could write something to remove those nodes before a job got submitted.
there is a TranslationJobService.Submitting event which fires before a job is sent to a provider (so xliff file, or via an API).
you could intercept the job at this point and then look through the content nodes it contains.
e.g
foreach(var node in job.Nodes)
{
// node.MasterNodeId is the ContentNodeId for the source page.
// you could load the job via the content service, check for your
// flag property and remove it from the collection if its set.
}
i think ideally we should have a similar even on translation node creation - but we don't in the current version 😢
but if its still based on a user flag, then in the TranslationNodeService.Creating. you will need to traverse the properties.
within a TranslatonNode all the text is stored in the Groups value (this is tabs in the old Umbraco UI terms).
then within the groups you have a list of TranslationProperties in the Properties value.
if the property you want to exclude is at the top level then the Source value in the property contains the name of the property. Then you can remove it from this list.
However if it is a value nested inside something else then you will need to recurse through the values, to get to it. a TranslationValue can have InnerValues, and these may also contain more InnerValues (think a textbox inside a grid inside a nested content element!).
quick example (not actually ran this, but it should get you started if you still need to have custom code checking).
using System;
using System.Collections.Generic;
using Jumoo.TranslationManager.Core.Models;
using Jumoo.TranslationManager.Core.Services;
using Umbraco.Core;
using Umbraco.Core.Composing;
namespace Jumoo.Translation.ExampleCode
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class PropertyRecurseComposer : ComponentComposer<PropertyRecurseComponent>
{ }
public class PropertyRecurseComponent : IComponent
{
public void Initialize()
{
TranslationNodeService.Created += TranslationNodeService_Created;
}
public void Terminate()
{
TranslationNodeService.Created -= TranslationNodeService_Created;
}
private void TranslationNodeService_Created(TranslationNodeEventArgs e)
{
// Node if of the content item we created the translation from - e.Node.MasterNodeId
// so you could load that up to check for set values. before you go into the remove
// code.
// groups are tabs.
foreach(var group in e.Node.Groups)
{
var removals = new List<int>();
// tabName in group.DisplayName
// properties in the tab.
foreach(var property in group.Properties)
{
// alias of property in doctype : property.Alias
// you could remove based on property.Alias, but the UI already lets you do this in config.
// if (property.Alias.InvariantEquals("somePropertyAlias"))
// {
// removals.Add(property.Id);
// }
var shouldRemove = RemoveValueCheck(property.Source);
if (shouldRemove)
{
removals.Add(property.Id);
}
}
if (removals.Count > 0)
{
group.Properties.RemoveAll(x => removals.Contains(x.Id));
}
}
}
/// <summary>
/// returns true if the translationValue should be removed from its parent.
/// </summary>
private bool RemoveValueCheck(TranslationValue value)
{
if (value.EditorAlias.Equals("SomeRemoveProperty", StringComparison.InvariantCultureIgnoreCase))
{
// this is the property's editorAlias of the thing we want to remove
return true;
}
else if (value.HasChildValues())
{
// else has choldren, recurse in and check if we want to remove the value from a nested item.
var removals = new List<string>();
foreach (var innerValue in value.InnerValues)
{
if (RemoveValueCheck(innerValue.Value))
{
removals.Add(innerValue.Key);
}
}
foreach (var removal in removals)
{
value.InnerValues.Remove(removal);
}
}
return false;
}
}
}
Set not to be translated flag on document
Hi Kevin,
Is it somehow possible to set a flag on documents you want to exclude from translation jobs. a True/False property will do fine.
So when a content editor want to send the entire site with all children to translation these nodes will be excluded.
/Søren
Hi,
not out of the box, you can set properties and doctypes to be exluded on sets, but not via a flag from the user.
however you could write something to remove those nodes before a job got submitted.
there is a
TranslationJobService.Submitting
event which fires before a job is sent to a provider (so xliff file, or via an API).you could intercept the job at this point and then look through the content nodes it contains.
e.g
i think ideally we should have a similar even on translation node creation - but we don't in the current version 😢
OK, it would help if i checked the code.
there IS a creating event on translation nodes.
if you register for this event you can stop the node from being created and it never gets added to the translation job.
again node.MasterNodeId would be the content id for the source page.
Great - I'll try it and let you know.
Hi Kevin,
I never got this one done.
I have tried make an event component which fires
But I dont know how to manipulate the nodes in here.
The specs has also changed a bit. It's actually just a single property eg. "bodyText" I want to remove from the translation job.
Thanks :-)
Hi Søren,
if its just a single property you want to remove , you could put it in the exclude properties list, or you could change it's data type to a non-translatable text box (we have a package that adds those data types here : https://www.nuget.org/packages/Jumoo.TranslationManager.NoneTranslatableText/)
but if its still based on a user flag, then in the TranslationNodeService.Creating. you will need to traverse the properties.
within a TranslatonNode all the text is stored in the Groups value (this is tabs in the old Umbraco UI terms).
then within the groups you have a list of TranslationProperties in the Properties value.
if the property you want to exclude is at the top level then the Source value in the property contains the name of the property. Then you can remove it from this list.
However if it is a value nested inside something else then you will need to recurse through the values, to get to it. a TranslationValue can have InnerValues, and these may also contain more InnerValues (think a textbox inside a grid inside a nested content element!).
quick example (not actually ran this, but it should get you started if you still need to have custom code checking).
Hi Kevin,
Thanks but e.Node.Groups return null - What could be the problem ?
Hi Kevin
I have the same issue with that the groups are null.
Do you have any idea to why that is ? I am using umbraco 8.12.2
The groups are null both in the creating and created event.
is working on a reply...