add method to export translation strings as csv

This commit is contained in:
Sanjay Bhangar 2018-12-02 17:44:15 +02:00
parent 81517ae18d
commit 2242b1ce41

View File

@ -3,6 +3,7 @@ import ox
import json
import codecs
from urllib.request import urlopen
import csv
api = ox.api.API(url)
user = api.signin({'username': username, 'password': password})
@ -10,6 +11,28 @@ user = api.signin({'username': username, 'password': password})
if 'errors' in user['data']:
print("Authentication Failed!")
def exportTranslations():
response = api.findTranslations({
"keys": ["key", "value", "id"],
"query": {
"conditions": [],
"operator": "&"
},
"range": [0, 2000],
"sort": [{
"key": "key",
"operator": "+"
}]
})
with open('translations.csv', 'w') as csvfile:
fieldnames = ['id', 'key', 'value']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for item in response['data']['items']:
del item['lang']
writer.writerow(item)
def titleContains(string):
return api.find({
'sort': [{