-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidStringsWriter.py
More file actions
25 lines (17 loc) · 856 Bytes
/
Copy pathAndroidStringsWriter.py
File metadata and controls
25 lines (17 loc) · 856 Bytes
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
import pathlib
class AndroidStringsWriter:
LANGUAGE_DIR = 'values-'
LANGUAGE_FILE = 'strings.xml'
def __init__(self, path):
self.path = path
self.basePath = pathlib.Path(self.path)
def write(self, languages):
for language, strings in languages.items():
language_dir_path = self.basePath.joinpath(AndroidStringsWriter.LANGUAGE_DIR + language)
language_dir_path.mkdir(parents=True, exist_ok=True)
language_file_path = language_dir_path.joinpath(AndroidStringsWriter.LANGUAGE_FILE)
with open(language_file_path, newline="\n", mode="w") as file:
file.write("<resources>\n")
for s in strings.items():
file.write(" <string name=\"%s\">%s</string>\n" % (s[0], s[1]))
file.write("</resources>\n")