1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 03:32:16 -05:00

Remove scripts to modify translations for Gradle support

This commit is contained in:
cketti 2014-04-08 18:02:47 +02:00
parent 1b14472a59
commit 420e6a91be
2 changed files with 0 additions and 87 deletions

View File

@ -1,11 +0,0 @@
#!/bin/bash
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
PROJECTROOT=`dirname $SCRIPTPATH`
cd $PROJECTROOT
find res/values* -name "strings.xml" -type f ! -wholename "res/values-fr-rCA/strings.xml" -exec ./tools/fix_strings.py {} \;
cd -

View File

@ -1,76 +0,0 @@
#!/usr/bin/env python
# Rewrite a strings file to get rid of line break/whitespace combinations that get stripped when building with Gradle.
#
# Example:
# <string name="account_size_changed">
# Account \"<xliff:g id="account">%s</xliff:g>\" shrunk from
# <xliff:g id="oldSize">%s</xliff:g>
# to
# <xliff:g id="newSize">%s</xliff:g>
# </string>
#
# will be rendered as
#
# Account "account" shrunk from10MB to1MB
#
# when built with Gradle, but displays fine when built with Ant.
#
#
# Written for use with K-9 Mail (https://github.com/k9mail/k-9)
# Licensed under the WTFPL (http://www.wtfpl.net/about/)
import sys
import re
from lxml import etree
def fix_text(element):
if element.text is not None:
element.text = re.sub(r'^\n\s*([^\s])', "\\1", element.text)
element.text = re.sub(r'\n\s*$', " ", element.text)
def fix_tail(element, is_last):
if element.tail is not None:
if is_last:
replacement = ""
else:
replacement = " "
element.tail = re.sub(r'^\n\s*([^\s])', " \\1", element.tail)
element.tail = re.sub(r'\n\s*$', replacement, element.tail)
def cleanup_string_elements(elements):
for element in elements:
if element.tag is None:
continue
tag = element.tag
children = element.getchildren()
if tag in ["string", "item"]:
if len(children) > 0:
fix_text(element)
for child in children:
if isinstance(child.tag, basestring):
fix_text(child)
fix_tail(child, child == children[-1])
elif tag == "plurals":
cleanup_string_elements(children)
if len(sys.argv) < 2:
print "Usage: fix_strings.py <strings file>"
print "Example: fix_strings.py res/values/strings.xml"
exit(1)
strings_file = sys.argv[1]
parser = etree.XMLParser(strip_cdata=False)
strings = etree.parse(strings_file, parser=parser)
cleanup_string_elements(strings.getroot().getchildren())
strings.write(strings_file, xml_declaration=True, encoding="UTF-8", pretty_print=True)