From ca6fd3e527afd6a1c7599844719d327bb060ad3b Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 30 Nov 2019 18:04:12 +0100 Subject: [PATCH] Add label option so that translated text can at least have an english label (and we can trace it) --- hugvey/tools.py | 5 +++-- www/js/hugvey_console.js | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/hugvey/tools.py b/hugvey/tools.py index fb0ad8a..1935e8b 100644 --- a/hugvey/tools.py +++ b/hugvey/tools.py @@ -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: diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index e847a3d..b43f315 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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