Skip to content
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
2 changes: 1 addition & 1 deletion genstrings_merge.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
OUTPUT_ENCODING = 'utf-16'
OUTPUT_LINE_PATTERN = u'/* {comment} */\n"{key}" = "{value}";\n\n'

pattern = re.compile('/\* ([^"]*) \*/\s"([^"]*)" = "([^"]*)";')
pattern = re.compile(r'/\* ([^"]*) \*/\s"([^"]*)" = "((?:\\.|[^"\\])*)";')
String = namedtuple('String', ['key', 'value', 'comment'])


Expand Down
19 changes: 10 additions & 9 deletions genstrings_swift.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def read_cmd():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output', help='Command output directory', default='.')
parser.add_argument('filepath', help='file to generate strings from')
parser.add_argument('filepaths', help='file(s) to generate strings from', type=argparse.FileType('r'), nargs='+')
args = parser.parse_args()
return args

Expand Down Expand Up @@ -62,14 +62,15 @@ def generate_string(params):
return String(key, value, comment)


def grep_file(filepath):
def grep_file(filepaths):
strings = []
with io.open(filepath, encoding='utf-8') as fp:
content = fp.read()
for match in string_pattern.finditer(content):
params = match.group(1)
string = generate_string(params)
strings.append(string)
for filepath in filepaths:
with io.open(filepath.name, encoding='utf-8') as fp:
content = fp.read()
for match in string_pattern.finditer(content):
params = match.group(1)
string = generate_string(params)
strings.append(string)
return strings


Expand All @@ -82,7 +83,7 @@ def save_strings(output_dir, strings):

def main():
args = read_cmd()
strings = grep_file(args.filepath)
strings = grep_file(args.filepaths)
save_strings(args.output, strings)


Expand Down