Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TRANSIFEX_USER = ""
TRANSIFEX_PW = ""
csvFile = open("app/src/main/assets/translators.csv", "w")
contributorsFile = open("CONTRIBUTORS", "a")
r = requests.get('http://www.transifex.com/api/2/project/antennapod/languages/',
auth=(TRANSIFEX_USER, TRANSIFEX_PW))
for lang in r.json():
langContributers = lang['coordinators'] + lang['reviewers'] + lang['translators']
langContributers = sorted(langContributers, key=str.lower)
langCode = lang['language_code']
try:
langName = pycountry.languages.lookup(langCode).name
except:
try:
langName = pycountry.languages.lookup(
langCode.split('_')[0]).name + ' (' + langCode + ')'
except:
langName = lang['language_code']
print('\033[91mLanguage code not found:' + langCode + '\033[0m')
joinedTranslators = ', '.join(langContributers).replace(';', '');
contributorsFile.write(langName + ": " + joinedTranslators + '\n')
csvFile.write(langName + ';' + joinedTranslators + '\n')
print(langName + ';' + joinedTranslators)
csvFile.close()
contributorsFile.close()
def name_for_lang(rep):
""" Get the language name from a representation of the language"""
try:
return pycountry.languages.lookup(rep).name
except LookupError:
return rep
def makeLanguageName(self, langCode):
code = re.sub("-.*","",langCode)
try:
language = pycountry.languages.lookup(code)
match = re.match(r'^[^-]+-(.*)$',langCode)
name = language.name
if match is not None:
name = "%s (%s)" % (name, match.group(1).upper())
except LookupError:
name = langCode
return name
def suggest_language(q, limit=5):
"""Get language suggestions based on query q from a fixed dictionary.
:param q: Query string to look for (e.g. 'Polish', 'ger', 'english')
:type q: str
:param limit: limit the result to 'limit' items
:type limit: int
:return: list of pycountry.db.Language
"""
q = q.lower().strip()
lut = None
langs = []
# If query is 2 or 3 char long, lookup for the ISO code
if 2 <= len(q) <= 3:
try:
lut = pycountry.languages.lookup(q)
except LookupError:
pass
# For queries longer than 2 characters, search by name
if len(q) > 2:
langs = list(itertools.islice(
(l for l in pycountry.languages if q in l.name.lower()), limit))
# Include the ISO-fetched language (if available) on first position
if lut:
langs = ([lut, ] + [l for l in langs if l != lut])[:limit]
return langs
def language_for(rep):
""" Get the entire language entry for a given representation """
try:
return pycountry.languages.lookup(rep)
except LookupError:
return None