0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
Anki-Android/tools/manage-crowdin.py

144 lines
5.0 KiB
Python
Raw Normal View History

2011-10-24 17:06:22 +02:00
#!/usr/bin/python
# Copyright (c) 2010 norbert.nagold@gmail.com
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script updates the master file(s) for crowdin.net
# There seems to a bug in the upload of translation files; it's therefore deactivated
import pycurl
import StringIO
import sys
2011-10-24 17:17:02 +02:00
CROWDIN_KEY = ''
2011-10-24 17:06:22 +02:00
PROJECT_IDENTIFIER = 'ankidroid'
path = '../res/values/'
files = ['01-core', '02-strings', '03-dialogs', '04-network', '05-feedback', '06-statistics', '07-cardbrowser', '08-widget', '09-backup', '10-preferences', '11-arrays', '12-tutorial', '13-newfeatures', '14-marketdescription']
2011-10-29 21:48:00 +02:00
alllang = ['ar', 'ca', 'cs', 'de', 'el', 'es-ES', 'fi', 'fr', 'hu', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt-PT', 'ro', 'ru', 'sr', 'sv-SE', 'th', 'tr', 'vi', 'zh-CN', 'zh-TW']
2011-10-24 17:06:22 +02:00
def uploadtranslation(language, filename, sourcefile):
if language == 'zh-TW':
pathlan = 'zh-rTW'
elif language == 'zh-CN':
pathlan = 'zh-rCN'
else:
pathlan = language[:2]
path = '../res/values-' + pathlan + '/'
filename = filename + '.xml'
# if selu == 's':
# filename = 'strings.xml'
# elif selu == 'a':
# filename = 'arrays.xml'
# else:
# filename = ''
# print "nothing to do"
print 'Update of Translation '+language+' for '+filename
if filename:
if language:
c = pycurl.Curl()
fields = [('files['+filename+']', (c.FORM_FILE, path + sourcefile + '.xml')), ('language', language), ('auto_approve_imported','0')]
c.setopt(pycurl.URL, 'http://crowdin.net/api/project/' + PROJECT_IDENTIFIER + '/upload-translation?key=' + CROWDIN_KEY)
c.setopt(pycurl.HTTPPOST, fields)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
c.close()
print b.getvalue()
else:
print 'no language code entered'
def updateMasterFile(selu):
if selu == '12':
2011-10-29 23:35:51 +02:00
targetName = '12-tutorial.csv'
sourceName = '../assets/tutorial.csv'
elif selu == '14':
targetName = '14-marketdescription.txt'
sourceName = '../docs/marketing/localized description/marketdescription.txt'
2011-10-24 17:06:22 +02:00
else:
2011-10-29 23:35:51 +02:00
targetName = files[int(selu)-1] + '.xml'
sourceName = path + targetName
if targetName:
print 'Update of Master File ' + targetName
2011-10-24 17:06:22 +02:00
c = pycurl.Curl()
2011-10-29 23:35:51 +02:00
fields = [('files['+targetName+']', (c.FORM_FILE, sourceName))]
2011-10-24 17:06:22 +02:00
c.setopt(pycurl.URL, 'http://crowdin.net/api/project/' + PROJECT_IDENTIFIER + '/update-file?key=' + CROWDIN_KEY)
c.setopt(pycurl.HTTPPOST, fields)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
c.close()
print b.getvalue()
2011-10-27 16:04:08 +02:00
2011-10-24 17:17:02 +02:00
try:
c = open("crowdin_key.txt","r+")
CROWDIN_KEY = c.readline();
c.close()
except IOError as e:
CROWDIN_KEY = raw_input("please enter your crowdin key or create \'crowdin_key.txt\': ")
2011-10-24 17:06:22 +02:00
sel = raw_input("update (m)aster file, update (t)ranslation or (r)efresh builds? ")
if sel == 'm':
# Update Master Files:
selu = raw_input("update 0(1)-core, 0(2)-strings, 0(3)-dialogs, 0(4)-network, 0(5)-feedback, 0(6)-statistics, 0(7)-cardbrowser, 0(8)-widget, 0(9)-backup, (10)-preferences, (11)-arrays, (12)-tutorial, (13)-newfeatures, (14)-marketdescription? ")
2011-10-24 17:06:22 +02:00
if selu == 'all':
2011-10-29 23:35:51 +02:00
for n in range(1, len(files) + 1):
updateMasterFile(str(n))
2011-10-24 17:06:22 +02:00
else:
updateMasterFile(selu)
elif sel == 't':
# Update Translations:
print 'still problems with crowding here'
language = raw_input("enter language code: ")
selu = raw_input("update 0(1)-core, 0(2)-strings, 0(3)-dialogs, 0(4)-network, 0(5)-feedback, 0(6)-statistics, 0(7)-cardbrowser, 0(8)-widget, 0(9)-backup, (10)-preferences, (11)-arrays, (13)-newfeatures? ")
if selu == '12' or selu == '14':
2011-10-27 16:04:08 +02:00
print "translations of this file cannot be uploaded"
elif selu != 'all':
2011-10-24 17:06:22 +02:00
defaultSource = files[int(selu)-1]
sourcefile = raw_input("enter source file (default: " + defaultSource + "): ")
if sourcefile == "":
sourcefile = defaultSource
2011-10-27 16:09:03 +02:00
if language == 'all':
2011-10-24 17:06:22 +02:00
for language in alllang:
if selu == 'all':
for s in files:
uploadtranslation(language, s, s)
2011-10-24 17:06:22 +02:00
else:
uploadtranslation(language, files[int(selu)-1], s)
2011-10-24 17:06:22 +02:00
elif selu == 'all':
for s in files:
uploadtranslation(language, s, s)
else:
uploadtranslation(language, files[int(selu)-1], sourcefile)
elif sel == 'r':
# Update Translations:
print "Force translation export"
c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://crowdin.net/api/project/' + PROJECT_IDENTIFIER + '/export?&key=' + CROWDIN_KEY)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
c.close()
print b.getvalue()
else:
print "nothing to do"