-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalizableStringsFileUtil.py
More file actions
executable file
·62 lines (47 loc) · 1.63 KB
/
Copy pathLocalizableStringsFileUtil.py
File metadata and controls
executable file
·62 lines (47 loc) · 1.63 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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
from Log import Log
import codecs
class LocalizableStringsFileUtil:
'iOS Localizable.strings file util'
@staticmethod
def writeToFile(keys,values,directory,additional):
if not os.path.exists(directory):
os.makedirs(directory)
Log.info("Creating iOS file:" + directory+"Localizable.strings")
fo = open(directory+"Localizable.strings", "w", encoding="utf-8")
for x in range(len(keys)):
if values[x] is None or values[x] == '':
Log.error("Key:" + keys[x] + "\'s value is None. Index:" + str(x + 1))
continue
key = keys[x]
value = values[x]
content = "\"" + key + "\" " + "= " + "\"" + value + "\";\n"
fo.write(content);
if additional is not None:
fo.write(additional)
fo.close()
@staticmethod
def getKeysAndValues(path):
if path is None:
Log.error('file path is None')
return
# 1.Read localizable.strings
file = codecs.open(path, 'r', 'utf-8')
string = file.read()
file.close()
# 2.Split by ";
localStringList = string.split('\";\n')
list = [x.split('\" = \"') for x in localStringList]
# 3.Get keys & values
keys = []
values = []
for x in range(len(list)):
keyValue = list[x]
if len(keyValue) > 1:
key = keyValue[0].split('\"')[1]
value = keyValue[1]
keys.append(key)
values.append(value)
return (keys,values)