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: with open(csv_filename, 'r') as fp:
reader = csv.DictReader(fp) reader = csv.DictReader(fp)
logger.info(reader.fieldnames) 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") raise Exception("Not all required fieldnames are given in csv: id, translation, regex_translation")
for row in reader: for row in reader:
@ -239,7 +239,8 @@ class Toolbox:
if len(row['translation']) < 1 and len(node['text']) > 0: if len(row['translation']) < 1 and len(node['text']) > 0:
logger.warning(f"Skipping empty translation for message {node['@id']} \"{node['text']}\"") logger.warning(f"Skipping empty translation for message {node['@id']} \"{node['text']}\"")
continue 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'] node['text'] = row['translation']
elif node['@type'] == 'Condition': elif node['@type'] == 'Condition':
if len(row['regex_translation']) < 1 and len(node['vars']['regex']) > 0: 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']) { if(div['params']['notAfterMsgId'] == startMsg['@id']) {
optionParams['selected'] = 'selected'; 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:', notAfterMsgIdEl = crel('label', 'Not when chapter has hit:',
crel('select', {'on': { 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( 'label',
crel( 'span', 'Start' ), crel( 'span', 'Start' ),
crel( 'input', startAttributes ) 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 ) { getDirectionEl( direction, msg ) {
let g = this; let g = this;
let directionEl = crel('div', let directionEl = crel('div',
@ -1709,7 +1725,7 @@ class Graph {
crel( crel(
'h3', 'h3',
{'title': direction['@id']}, {'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', { crel('div', {
'class':'btn btn--delete', 'class':'btn btn--delete',
@ -2501,7 +2517,7 @@ class Graph {
}; };
node.selectAll( "text.msg_id" ).text( d => d['@id'] ); 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'); node.selectAll( "image.status_icon" ).attr('xlink:href', d => d['audio'] ? '' : '/images/music-broken.svg');
// console.log('q'); // console.log('q');
// // TODO: update text // // TODO: update text