Add label option so that translated text can at least have an english label (and we can trace it)

This commit is contained in:
Ruben van de Ven 2019-11-30 18:04:12 +01:00
parent 0616fcf72f
commit ca6fd3e527
2 changed files with 22 additions and 5 deletions

View file

@ -230,7 +230,7 @@ class Toolbox:
with open(csv_filename, 'r') as fp:
reader = csv.DictReader(fp)
logger.info(reader.fieldnames)
if 'id' not in reader.fieldnames or 'translation' not in reader.fieldnames or 'regex_translation' not in reader.fieldnames:
if 'id' not in reader.fieldnames or 'translation' not in reader.fieldnames or 'regex_translation' not in reader.fieldnames or 'text' not in reader.fieldnames:
raise Exception("Not all required fieldnames are given in csv: id, translation, regex_translation")
for row in reader:
@ -239,7 +239,8 @@ class Toolbox:
if len(row['translation']) < 1 and len(node['text']) > 0:
logger.warning(f"Skipping empty translation for message {node['@id']} \"{node['text']}\"")
continue
if 'label' not in node or (len(node['label']) < 1 and node['text'] == row['text']):
node['label'] = row['text'] # store original text as label for readability
node['text'] = row['translation']
elif node['@type'] == 'Condition':
if len(row['regex_translation']) < 1 and len(node['vars']['regex']) > 0:

View file

@ -542,7 +542,7 @@ class Graph {
if(div['params']['notAfterMsgId'] == startMsg['@id']) {
optionParams['selected'] = 'selected';
}
notMsgOptions.push(crel('option', optionParams , `${startMsg['text']} (${startMsg['@id']})`));
notMsgOptions.push(crel('option', optionParams , `${this.getLabel(startMsg)} (${startMsg['@id']})`));
}
notAfterMsgIdEl = crel('label', 'Not when chapter has hit:',
crel('select', {'on': {
@ -1487,6 +1487,16 @@ class Graph {
}
} )
),
crel( 'label',
crel( 'span', 'Label' ),
crel( 'input', {
'name': msg['@id'] + '-label',
'value': msg.hasOwnProperty('label') ? msg['label'] : "",
'on': {
'change': this.getEditEventListener()
}
} )
),
crel( 'label',
crel( 'span', 'Start' ),
crel( 'input', startAttributes )
@ -1690,6 +1700,12 @@ class Graph {
}
getLabel(msg) {
if(msg.hasOwnProperty('label') && msg['label'].length > 0)
return msg['label'];
return msg['text'];
}
getDirectionEl( direction, msg ) {
let g = this;
let directionEl = crel('div',
@ -1709,7 +1725,7 @@ class Graph {
crel(
'h3',
{'title': direction['@id']},
direction['source'] == msg ? `To ${direction['target']['text']}`: `From ${direction['source']['text']}`
direction['source'] == msg ? `To ${this.getLabel(direction['target'])}`: `From ${this.getLabel(direction['source'])}`
),
crel('div', {
'class':'btn btn--delete',
@ -2501,7 +2517,7 @@ class Graph {
};
node.selectAll( "text.msg_id" ).text( d => d['@id'] );
node.selectAll( "text.msg_txt" ).text( d => formatText( `${d['text']}` ) );
node.selectAll( "text.msg_txt" ).text( d => formatText( `${this.getLabel(d)}` ) );
node.selectAll( "image.status_icon" ).attr('xlink:href', d => d['audio'] ? '' : '/images/music-broken.svg');
// console.log('q');
// // TODO: update text