Skip to content
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
30 changes: 18 additions & 12 deletions python_twine/tests/fixtures/twine_accent_values.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[[Section]]
[value_with_leading_accent]
en = `value
[value_with_trailing_accent]
en = value`
[value_with_leading_space]
en = ` value`
[value_with_trailing_space]
en = `value `
[value_wrapped_by_spaces]
en = ` value `
[value_wrapped_by_accents]
en = ``value``

[value_with_leading_accent]
en = `value

[value_with_trailing_accent]
en = value`

[value_with_leading_space]
en = ` value`

[value_with_trailing_space]
en = `value `

[value_wrapped_by_spaces]
en = ` value `

[value_wrapped_by_accents]
en = ``value``
17 changes: 9 additions & 8 deletions python_twine/tests/fixtures/twine_plural_values.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[[Bookmarks]]
[bookmarks_places]
comment = Number of bookmarks on UI
en:one = %d bookmark
en:other = %d bookmarks
ru:one = %d метка
ru:few = %d метки
ru:many = %d меток
ru:other = %d меток

[bookmarks_places]
comment = Number of bookmarks on UI
en:one = %d bookmark
en:other = %d bookmarks
ru:one = %d метка
ru:few = %d метки
ru:many = %d меток
ru:other = %d меток
7 changes: 4 additions & 3 deletions python_twine/tests/test_formatters_plural.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ def test_write_plural_format(self):
twine_content = fout.read()

assert twine_content == """[[OSM]]
\t[num_edits]
\t\ten:one = %d edit
\t\ten:other = %d edits

[num_edits]
en:one = %d edit
en:other = %d edits
"""

def test_read_plurals(self, fixtures_dir):
Expand Down
11 changes: 6 additions & 5 deletions python_twine/tests/test_twine_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ def test_write_file(self):
content = f.read()

assert content == """[[Test]]
\t[test_key]
\t\tcomment = A test string
\t\ttags = test
\t\ten = Test
\t\tes = Prueba

[test_key]
comment = A test string
tags = test
en = Test
es = Prueba
"""
finally:
Path(temp_path).unlink()
Expand Down
4 changes: 2 additions & 2 deletions python_twine/twine/formatters/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ def is_non_tag(result:str, i:int):
lambda i: not inside_cdata(result, i)
)

# Escape @ signs that aren't resource identifiers
resource_identifier_regex = re.compile(r"@(?!([a-z\.]+:)?[a-z+]+\/[a-zA-Z_]+)")
# escape non resource identifier @ signs (http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromXml)
resource_identifier_regex = re.compile(r"@(?!([a-z\.]+:)?[a-z+]+\/[a-zA-Z_]+)") # @[<package_name>:]<resource_type>/<resource_name>
result = resource_identifier_regex.sub(r"\\@", result)

return result
Expand Down
12 changes: 6 additions & 6 deletions python_twine/twine/twine_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,20 @@ def write(self, path: str):
f.write(f"[[{section.name}]]\n")

for definition in section.definitions:
f.write(f"\t[{definition.key}]\n")
f.write(f"\n[{definition.key}]\n")

# Write comment
if definition.raw_comment:
f.write(f"\t\tcomment = {definition.raw_comment}\n")
f.write(f"comment = {definition.raw_comment}\n")

# Write reference
if definition.reference_key:
f.write(f"\t\tref = {definition.reference_key}\n")
f.write(f"ref = {definition.reference_key}\n")

# Write tags
if definition.tags:
tag_str = ",".join(definition.tags)
f.write(f"\t\ttags = {tag_str}\n")
f.write(f"tags = {tag_str}\n")

# Write developer language first
if dev_lang:
Expand Down Expand Up @@ -413,12 +413,12 @@ def _write_value(
# ru:other = %d меток
output = ""
for quantity, value in definition.plural_translation_for_lang(language).items():
output += f"\t\t{language}:{quantity} = {escape_spaces_backticks(value)}\n"
output += f"{language}:{quantity} = {escape_spaces_backticks(value)}\n"

elif language in definition.translations:
singular_value = definition.translations[language]
# Write singular
output = f"\t\t{language} = {escape_spaces_backticks(singular_value)}\n"
output = f"{language} = {escape_spaces_backticks(singular_value)}\n"

if output:
file.write(output)
Expand Down