Store metadata per segment (SetMetaData)

Hi,

I would like to store some metadata in a project per segment (e.g. an additional identifier). For example, for segment 10, this would look like: ActiveDocument.SegmentPairs.ElementAt(10).Target.Properties.TranslationOrigin.SetMetaData("MyKey", "Meta data information");


This used to work in the past. However, after doing this on a Japanese translation segment, it does not seem to work anymore. After executing this code, "MyKey" is not added.

However, in the debugger, when I invoke this method, the item is added to MetaData.

Does anyone has a clue?

Are there other (better) ways to store information at a segment?

Best regards,
Henk
Parents Reply
  • This does not seem to work if multiple files are opened.

    It is possible that multiple files are open in the active document. In that case you need to check if the segment pair belongs to the correct file where you want to add your metadata.

    For some reason, setting the metadata for the 2nd file does not seem to work.

    public SegmentpairMetadata(Document activeDocument, string currentfileId, int segmentId, string key, string value)
    {
    _currentfileId = currentfileId; //This is the File ID
    _segmentid = segmentId;
    _key = key;
    _value = value;
    activeDocument.ProcessSegmentPairs("DQF_metadata", UpdateSegmentPairProperties);
    }

    private void UpdateSegmentPairProperties(ISegmentPair segmentPair, CancelEventArgs e)
    {
    if ((_currentfileId == null) || (segmentPair.GetProjectFile().Id.ToString() != _currentfileId.ToLower()))
    {
    return;
    }

    if (segmentPair.Properties.Id.Id == _segmentid.ToString(CultureInfo.InvariantCulture))
    {
    segmentPair.Properties.TranslationOrigin.SetMetaData(_key, _value);
    }
    }
Children