-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring-downloader-ios.py
58 lines (45 loc) · 1.84 KB
/
string-downloader-ios.py
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
# -*- coding: utf-8 -*-
import os
import sys
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from xml.etree.ElementTree import ElementTree, Element, SubElement, dump
GDOC_ID = 'GDOC_ID' # 구글 스프레드시트 독 아이디
JSON_KEY_PATH = 'google-sheets-api.json' # 구글 키 저장 경로
VALUES_PATH = '../app/src/main/res_down' # 저장될 별도의 리소스 폴더
SUPPORTED_LANGUAGE = ['ko', 'en', 'ja']
DEFAULT_LANGUAGE = 'en'
'''
pip install gspread oauth2client
'''
def get_gdoc_information_ios():
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_PATH, scope)
# test 현재경로
# VALUES_PATH = os.getcwd()
# 구글 로그인
gc = gspread.authorize(credentials)
# 시트오픈
sh = gc.open_by_key(GDOC_ID)
# Select worksheet by index. Worksheet indexes start from zero
worksheet = sh.sheet1
# 폴더가 없으면 만들어준다
if not os.path.exists(VALUES_PATH):
os.makedirs(VALUES_PATH)
all_records = worksheet.get_all_records(empty2zero=False, head=1, default_blank='')
for language in SUPPORTED_LANGUAGE:
if language == DEFAULT_LANGUAGE:
output_path = VALUES_PATH + "/" + "Base.lproj"
else:
output_path = VALUES_PATH + "/" + language + ".lproj"
if not os.path.exists(output_path):
os.makedirs(output_path)
output_file = output_path + "/Localizable.strings"
output_stream = open(output_file, "w")
for record in all_records:
if record[language] != "":
string = record[u'ios_key'] + u"=" + record[language] + ";\n"
output_stream.write(string.encode('utf-8'))
output_stream.close()
if __name__ == '__main__':
get_gdoc_information_ios()