Created
July 27, 2020 11:14
-
-
Save amitkot/367f95ac1cb3ea73e20f80131e20c8e9 to your computer and use it in GitHub Desktop.
A tool for reversing title values for fastlane frameit when using RTL languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from argparse import ArgumentParser | |
LINE_PATTERN = re.compile(r'"(.+)"\s*=\s*"(.+)"$') | |
def _parse_args(): | |
parser = ArgumentParser(description='Reverse titles for frameit RTL') | |
parser.add_argument('--before', action='store', type=str, default='title.strings.before') | |
parser.add_argument('--output', action='store', type=str, default='title.strings') | |
parser.add_argument('--dry-run', action='store_true', default=False) | |
return parser.parse_args() | |
def _reverse_value(match): | |
return f'"{match.group(1)}" = "{match.group(2)[::-1]}"' | |
def _reverse_lines(before, output=None): | |
print('Output:') | |
for line in before: | |
line = line.strip() | |
converted = LINE_PATTERN.sub(_reverse_value, line) | |
print(converted) | |
if output: | |
output.write(f"{converted}\n") | |
def _prepare_titles(before, output, dry_run): | |
with open(before, 'r') as before: | |
if not dry_run: | |
with open(output, 'w') as output: | |
_reverse_lines(before, output) | |
else: | |
_reverse_lines(before) | |
if __name__ == '__main__': | |
args = _parse_args() | |
_prepare_titles(before=args.before, output=args.output, dry_run=args.dry_run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment