Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add POEditor option to ignore empty definitions #380

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ v3.1.4

*Release date: In development*

- Add `ignore_empty` optional parameter to POEditor configuration to ignore empty translations

v3.1.3
------

Expand Down
49 changes: 49 additions & 0 deletions toolium/test/utils/test_dataset_map_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ def test_a_poe_param_single_result():
assert result == expected


def test_a_poe_param_with_empty_definition_single_result():
"""
Verification of a POE mapped parameter with empty definition
"""
dataset.poeditor_terms = [
{
"term": "Poniendo mute",
"definition": "",
"reference": "home:home.tv.mute",
}
]
result = map_param('[POE:home.tv.mute]')
expected = ""
assert result == expected


def test_a_poe_param_no_result_assertion():
"""
Verification of a POE mapped parameter without result
Expand All @@ -228,6 +244,39 @@ def test_a_poe_param_no_result_assertion():
assert "No translations found in POEditor for reference home.tv.off" in str(excinfo.value)


def test_a_poe_param_with_no_definition_no_result_assertion_():
"""
Verification of a POE mapped parameter without definition and without result
"""
dataset.poeditor_terms = [
{
"term": "Poniendo mute",
"definition": None,
"reference": "home:home.tv.mute",
}
]
with pytest.raises(Exception) as excinfo:
map_param('[POE:home.tv.mute]')
assert "No translations found in POEditor for reference home.tv.mute" in str(excinfo.value)


def test_a_poe_param_with_empty_definition_no_result_assertion():
"""
Verification of a POE mapped parameter with empty definition and without result (configured ignore_empty)
"""
dataset.project_config = {'poeditor': {'key_field': 'reference', 'search_type': 'contains', 'ignore_empty': True}}
dataset.poeditor_terms = [
{
"term": "Poniendo mute",
"definition": "",
"reference": "home:home.tv.mute",
}
]
with pytest.raises(Exception) as excinfo:
map_param('[POE:home.tv.mute]')
assert "No translations found in POEditor for reference home.tv.mute" in str(excinfo.value)


def test_a_poe_param_prefix_with_no_definition():
"""
Verification of a POE mapped parameter with a single result for a reference
Expand Down
6 changes: 4 additions & 2 deletions toolium/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ def get_translation_by_poeditor_reference(reference, poeditor_terms):
poeditor_config = project_config['poeditor'] if project_config and 'poeditor' in project_config else {}
key = poeditor_config['key_field'] if 'key_field' in poeditor_config else 'reference'
search_type = poeditor_config['search_type'] if 'search_type' in poeditor_config else 'contains'
ignore_empty = poeditor_config['ignore_empty'] if 'ignore_empty' in poeditor_config else False
ignored_definitions = [None, ''] if ignore_empty else [None]
# Get POEditor prefixes and add no prefix option
poeditor_prefixes = poeditor_config['prefixes'] if 'prefixes' in poeditor_config else []
poeditor_prefixes.append('')
Expand All @@ -702,10 +704,10 @@ def get_translation_by_poeditor_reference(reference, poeditor_terms):
complete_reference = '%s%s' % (prefix, reference)
if search_type == 'exact':
translation = [term['definition'] for term in poeditor_terms
if complete_reference == term[key] and term['definition'] is not None]
if complete_reference == term[key] and term['definition'] not in ignored_definitions]
else:
translation = [term['definition'] for term in poeditor_terms
if complete_reference in term[key] and term['definition'] is not None]
if complete_reference in term[key] and term['definition'] not in ignored_definitions]
if len(translation) > 0:
break
assert len(translation) > 0, 'No translations found in POEditor for reference %s' % reference
Expand Down
1 change: 1 addition & 0 deletions toolium/utils/poeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"prefixes": [],
"key_field": "reference",
"search_type": "contains",
"ignore_empty": False,
"file_path": "output/poeditor_terms.json",
"mode": "online"
}
Expand Down
Loading