This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
importPOEditorKeys.py
47 lines (34 loc) · 1.54 KB
/
importPOEditorKeys.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
import sys, os, io, json
import requests
# Dependencies: requests
# Install dependencies: sudo easy_install -U requests
# Use: python importPOEditorKeys.py
__PULL_FROM_POEDITOR_URL__ = 'https://api.poeditor.com/v2/projects/export'
__LANGUAGES__ = ["en", "it", "sq"]
POEDITOR_TOKEN = raw_input("Enter your API Token: ")
POEDITOR_PROJECT_ID = raw_input("Enter the project ID: ")
def checkResponseAndRaiseException(response):
if response['response']['status'] != 'success':
print response
raise Exception('Unexpected response!')
def createFolderIfNotExist(resourceDir):
if not os.path.exists(resourceDir):
os.makedirs(resourceDir)
if __name__ == "__main__":
for lang in __LANGUAGES__:
print "Pulling " + lang
payload = {
'api_token': POEDITOR_TOKEN,
'id': POEDITOR_PROJECT_ID,
'type': 'apple_strings',
'language': lang
}
response = requests.post(__PULL_FROM_POEDITOR_URL__, data=payload).json()
checkResponseAndRaiseException(response)
poDownloadUrl = response['result']['url']
poLocalizedText = requests.get(poDownloadUrl).text
checkResponseAndRaiseException(response)
localizedLatestFilePath = 'iOSApp/Resources/Localization/%s.lproj' % lang
createFolderIfNotExist(localizedLatestFilePath)
with io.open(localizedLatestFilePath + '/Localizable.strings', 'w', encoding='utf8') as output_file:
output_file.write(poLocalizedText)