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

Respects explicit formatted="false" tag in strings #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 0 additions & 37 deletions .github/workflows/ci.yml

This file was deleted.

19 changes: 15 additions & 4 deletions android2po/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __init__(self, language=None):
self.language = language
class StringArray(list): pass
class Plurals(dict): pass
Translation = namedtuple('Translation', ['text', 'comments', 'formatted'])
class UnformattedString(str): pass
Translation = namedtuple('Translation', ['text', 'comments', 'formatted', 'print_false_format'])


def get_element_text(tag, name, warnfunc=dummy_warn):
Expand Down Expand Up @@ -381,6 +382,8 @@ def check_formatted(forced_state, detected_state):
force_fmt = True
elif tag.attrib['formatted'] == 'false':
force_fmt = False
else:
warnfunc('%s unrecognized formatted="%s"' % (name, tag.attrib['formatted']), 'warning')

if tag.tag == 'string':
try:
Expand All @@ -390,7 +393,8 @@ def check_formatted(forced_state, detected_state):
name, e.reason), 'info')
else:
formatted = check_formatted(force_fmt, formatted)
translation = Translation(text, comment, formatted)
force_print_format = (force_fmt != None)
translation = Translation(text, comment, formatted, force_print_format)
result[name] = translation

elif tag.tag == 'string-array':
Expand Down Expand Up @@ -420,7 +424,7 @@ def check_formatted(forced_state, detected_state):
(name, e.reason), 'warning')
else:
formatted = check_formatted(force_fmt, formatted)
translation = Translation(text, comment, formatted)
translation = Translation(text, comment, formatted, False)
result[name].append(translation)

elif tag.tag == 'plurals':
Expand All @@ -442,7 +446,7 @@ def check_formatted(forced_state, detected_state):
(name, e.reason), 'warning')
else:
formatted = check_formatted(force_fmt, formatted)
translation = Translation(text, comment, formatted)
translation = Translation(text, comment, formatted, False)
result[name][quantity] = translation

# We now have processed a tag. We either added those comments to
Expand Down Expand Up @@ -628,6 +632,8 @@ def xml2po(resources, translations=None, resfilter=None, warnfunc=dummy_warn):
flags = []
if org_value.formatted:
flags.append('c-format')
elif org_value.print_false_format:
flags.append('no-c-format')

catalog.add(org_value.text, trans_value.text if trans_value else '',
flags=flags, auto_comments=org_value.comments, context=name)
Expand Down Expand Up @@ -870,6 +876,9 @@ def validate_plural_config():
if not message.string and not with_untranslated:
# Untranslated.
continue
if message.flags and 'no-c-format' in message.flags:
# This sub-class will trigger us to write the string as unformatted
value = UnformattedString(value)
xml_tree[message.context] = value

return xml_tree
Expand Down Expand Up @@ -909,6 +918,8 @@ def write_xml(tree, warnfunc=dummy_warn):
string_el = write_to_dom(
'string', value, '"%s"' % name, namespaces_used, warnfunc)
string_el.attrib['name'] = name
if isinstance(value, UnformattedString):
string_el.attrib['formatted'] = "false"
root_tags.append(string_el)

# Generate the root element, define the namespaces that have been
Expand Down
15 changes: 0 additions & 15 deletions tox.ini

This file was deleted.