Skip to content

Commit

Permalink
Merge pull request #219 from tiropictor/new_branch
Browse files Browse the repository at this point in the history
feat: Added the side-by-side option to translation position setting.
  • Loading branch information
bookfere authored Mar 8, 2024
2 parents 941e3b6 + e635d0d commit 66f67cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 25 additions & 2 deletions lib/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,30 @@ def add_translation(self, translation, placeholder, position=None,
xml_escape(pattern), lambda _: get_string(reserve),
translation)
translation = self._polish_translation(translation)
new_element = etree.XML('<{0} xmlns="{1}">{2}</{0}>'.format(

if position == 'sidebyside':
new_element = etree.Element(get_name(self.element), xmlns=ns['x'])
# Create table structure
table = etree.SubElement(new_element, 'table')
tr = etree.SubElement(table, 'tr')

# Original text on the left column
td_original = etree.SubElement(tr, 'td')
td_original.set('width', '45%')
td_orig_elem = td_original.append(self.element_copy)

# Middle column
td_middle = etree.SubElement(tr, 'td')
td_middle.set('padding', '10px')
# looks awful, but I couldn't find better way to keep the gap:
td_middle.text = xml_escape('&#xA0;&#xA0;&#xA0;&#xA0;')

# Translation on the right column
td_translation = etree.SubElement(tr, 'td')
td_translation.set('width', '45%')
td_translation.text = trim(translation)
else:
new_element = etree.XML('<{0} xmlns="{1}">{2}</{0}>'.format(
get_name(self.element), ns['x'], trim(translation)))
# Preserve all attributes from the original element.
for name, value in self.element.items():
Expand All @@ -180,7 +203,7 @@ def add_translation(self, translation, placeholder, position=None,
self.element.addprevious(new_element)
else:
self.element.addnext(new_element)
if position == 'only':
if position == 'only' or position == 'sidebyside':
self.delete()
return new_element

Expand Down
5 changes: 4 additions & 1 deletion setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,18 +693,21 @@ def layout_content(self):
after_original.setChecked(True)
before_original = QRadioButton(_('Add before original'))
delete_original = QRadioButton(_('Add without original'))
side_by_side = QRadioButton(_('Side-by-side'))
position_layout.addWidget(after_original)
position_layout.addWidget(before_original)
position_layout.addWidget(delete_original)
position_layout.addWidget(side_by_side)
position_layout.addStretch(1)
layout.addWidget(position_group)

position_map = dict(enumerate(['after', 'before', 'only']))
position_map = dict(enumerate(['after', 'before', 'only', 'sidebyside']))
position_rmap = dict((v, k) for k, v in position_map.items())
position_btn_group = QButtonGroup(position_group)
position_btn_group.addButton(after_original, 0)
position_btn_group.addButton(before_original, 1)
position_btn_group.addButton(delete_original, 2)
position_btn_group.addButton(side_by_side, 3)

position_btn_group.button(position_rmap.get(
self.config.get('translation_position'))).setChecked(True)
Expand Down

0 comments on commit 66f67cf

Please sign in to comment.