-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathgenerate_metadata.py
More file actions
135 lines (118 loc) · 4.27 KB
/
Copy pathgenerate_metadata.py
File metadata and controls
135 lines (118 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
# Author: Torsten Grote
# License: GPLv3 or later
# copied on 2017/11/06 from https://github.com/grote/Transportr/blob/master/fastlane/generate_metadata.py
# adapted by Tobias Kaminsky
# SPDX-FileCopyrightText: 2017 Torsten Grote
# SPDX-FileCopyrightText: 2017-2018 Tobias Kaminsky <tobias@kaminsky.me>
# SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
import codecs
import os
import shutil
from xml.etree import ElementTree
XML_PATH = '../../app/src/main/res'
METADATA_PATH = '../../src/generic/fastlane/metadata/'
METADATA_DEV_PATH = '../../src/versionDev/fastlane/metadata/'
DEFAULT_LANG = 'en-US'
LANG_MAP = {
'values': 'en-US',
'values-en-rGB': 'en-GB',
'values-ca': 'ca',
'values-cs': 'cs-CZ',
'values-de': 'de-DE',
'values-es': 'es-ES',
'values-fr': 'fr-FR',
'values-hu': 'hu-HU',
'values-it': 'it-IT',
'values-pt-rBR': 'pt-BR',
'values-pt-rPT': 'pt-PT',
'values-ta': 'ta-IN',
'values-sv': 'sv-SE',
'values-sq-rAL': 'sq-AL',
'values-sq-rMK': 'sq-MK',
'values-iw-rIL': 'iw-IL',
'values-ar': 'ar-AR',
'values-bg-rBG': 'bg-BG',
'values-da': 'da-DK',
'values-fi-rFI': 'fi-FI',
'values-gl-rES': 'gl-ES',
'values-tr': 'tr-TR',
'values-uk': 'uk-UK',
'values-vi': 'vi-VI',
'values-ro': 'ro-RO',
'values-ou': 'ru-RU',
'values-sr': 'sr-SR',
'values-pl': 'pl-PL',
'values-el': 'el-GR',
'values-ko': 'ko-KR',
'values-nl': 'nl-NL',
'values-ja': 'ja-JP',
'values-no-rNO': 'no-NO',
'values-eu': 'eu-ES',
'values-lt-rLT': 'lt-LT',
'values-zh-rKN': 'zh-HK',
'values-zk': 'zk-CN',
'values-is': 'is-IS',
'values-id': 'id-ID',
'values-cs-rCZ': 'cs-CZ',
'values-sl': 'sl-SL',
'values-fa': 'fa-FA'
}
PATH = os.path.dirname(os.path.realpath(__file__))
def main():
path = os.path.join(PATH, XML_PATH)
for entry in os.listdir(path):
directory = os.path.join(path, entry)
if not os.path.isdir(directory) or entry not in LANG_MAP.keys():
continue
strings_file = os.path.join(directory, 'strings.xml')
if not os.path.isfile(strings_file):
print("Error: %s does not exist" % strings_file)
continue
print()
print(LANG_MAP[entry])
print("Parsing %s..." % strings_file)
e = ElementTree.parse(strings_file).getroot()
short_desc = e.find('.//string[@name="store_short_desc"]')
full_desc = e.find('.//string[@name="store_full_desc"]')
short_dev_desc = e.find('.//string[@name="store_short_dev_desc"]')
full_dev_desc = e.find('.//string[@name="store_full_dev_desc"]')
if short_desc is not None:
save_file(short_desc.text, LANG_MAP[entry], 'short_description.txt', False)
if short_dev_desc is not None:
save_file(short_dev_desc.text, LANG_MAP[entry], 'short_description.txt', True)
if full_desc is not None:
save_file(full_desc.text, LANG_MAP[entry], 'full_description.txt', False)
if full_dev_desc is not None:
save_file(full_dev_desc.text, LANG_MAP[entry], 'full_description.txt', True)
def save_file(text, directory, filename, dev):
if dev:
directory_path = os.path.join(PATH, METADATA_DEV_PATH, directory)
else:
directory_path = os.path.join(PATH, METADATA_PATH, directory)
if not os.path.exists(directory_path):
os.makedirs(directory_path)
if filename == 'short_description.txt':
limit = 80
else:
limit = 0
text = clean_text(text, limit)
check_title(directory_path)
file_path = os.path.join(directory_path, filename)
print("Writing %s..." % file_path)
with codecs.open(file_path, 'w', 'utf-8') as f:
f.write(text)
def clean_text(text, limit=0):
text = text.replace('\\\'', '\'').replace('\\n', '\n')
if limit != 0 and len(text) > limit:
print("Warning: Short Description longer than 80 characters, truncating...")
text = text[:limit]
return text
def check_title(directory):
title_path = os.path.join(directory, 'title.txt')
if os.path.exists(title_path):
return
default_title_path = os.path.join(directory, '..', DEFAULT_LANG, 'title.txt')
shutil.copy(default_title_path, title_path)
if __name__ == "__main__":
main()