Commit ae37e312 authored by Hiro's avatar Hiro 🏄
Browse files

Use locales

parent d630e7a6
{
"platforms": ["linux", "osx", "windows"],
"languages": ["en", "es", "pt"],
"dbname": "/srv/gettor.torproject.org/home/gettor/gettor.db",
"email_parser_logfile": "/srv/gettor.torproject.org/home/gettor/log/email_parser.log",
"email_requests_limit": 5,
......
......@@ -73,6 +73,7 @@ class EmailParser(object):
"""
platforms = self.settings.get("platforms")
languages = self.settings.get("languages")
log.msg("Building email message from string.", system="email parser")
msg = message_from_string(msg_str)
......@@ -137,26 +138,29 @@ class EmailParser(object):
"id": norm_addr,
"command": None,
"platform": None,
"language": None,
"service": "email"
}
if subject:
subject = subject.group(1)
for word in re.split(r"\s+", subject.strip()):
if word.lower() in languages:
request["language"] = word.lower()
if word.lower() in platforms:
request["command"] = "links"
request["platform"] = word.lower()
break
if word.lower() == "help":
request["command"] = "help"
break
if not request["command"]:
if not request["command"] and not request["language"]:
for word in re.split(r"\s+", msg_str.strip()):
if word.lower() in languages:
request["language"] = word.lower()
if word.lower() in platforms:
request["command"] = "links"
request["platform"] = word.lower()
break
if word.lower() == "help":
request["command"] = "help"
break
......
......@@ -117,13 +117,8 @@ class Sendmail(object):
status="ONHOLD", command="links", service="email"
)
"""
Load strings for translations
"""
# for now just english
strings.load_strings("en")
if help_requests:
strings.load_strings("en")
try:
log.info("Got new help request.")
......@@ -164,6 +159,8 @@ class Sendmail(object):
id = request[0]
date = request[4]
platform = request[2]
language = request[3]
strings.load_strings(language)
log.info("Getting links for {}.".format(platform))
links = yield self.conn.get_links(
......
......@@ -59,6 +59,7 @@ class Settings(object):
else:
self._settings = {
"platforms": ["linux", "osx", "windows"],
"languages": ["en", "es", "pt"],
"dbname": "/srv/gettor.torproject.org/home/gettor/gettor.db",
"email_parser_logfile": "/srv/gettor.torproject.org/home/gettor/log/email_parser.log",
"email_requests_limit": 5,
......
......@@ -77,9 +77,11 @@ def main():
"linux": "_en-US.tar.xz"
}
keys = {'osx', 'windows', 'linux'}
releases = {k: "".join(dic.get(k, version) for dic in (prefixes, versions, suffixes)) for k in keys}
keys = ['osx', 'windows', 'linux']
languages = ['en-US', 'es-ES', 'pt-BR']
releases = {k: "".join(dic.get(k, version) for dic in (prefixes, versions, suffixes)) for k in keys}
if not abs_filename:
print("Missing database filename.")
......@@ -97,9 +99,11 @@ def main():
)
for k in keys:
for p in providers:
c.execute(
"INSERT INTO links(link, platform, arch, version, provider, status)"
"VALUES ('%s', '%s', '64', '%s', '%s', 'ACTIVE')" %(providers.get(p) + releases.get(k), k, version, p))
for l in languages:
release_link = releases.get(k).replace("en-US", l)
c.execute(
"INSERT INTO links(link, platform, arch, version, provider, status)"
"VALUES ('%s', '%s', '64', '%s', '%s', 'ACTIVE')" %(providers.get(p) + release_link, k, version, p))
if __name__ == "__main__":
......
{
"en": "English"
"en": "English",
"es": "Español",
"pt": "Português Brasil"
}
{
"links_body": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n \n--\nGetTor",
"links_subject": "[GetTor] Links for your request",
"help_body": "This is how you can request a tor browser bundle link.\n\n Send an email to: gettor@torproject.org\n\nIn the body of the email only write: <operating system> <language>.\n\nWe only support windows, osx and linux as operating systems.\n\nAt the moment please only use en as language.\n\n",
"help_subject": "[GetTor] Help Email",
"help_debug": "Log application errors to stdout",
"help_config": "Custom config file location (optional)",
"smtp_links_subject": "[GetTor] Links for your request",
"smtp_mirrors_subject": "[GetTor] Mirrors",
"smtp_help_subject": "[GetTor] Help",
"smtp_unsupported_locale_subject": "[GetTor] Unsupported locale",
"smtp_unsupported_locale_msg": "The locale you requested '{}' is not supported.",
"smtp_vlinks_msg": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n \n--\nGetTor",
"smtp_mirrors_msg": "Hi! this is the GetTor robot.\n\nThank you for your request. Attached to this email you will find\nan updated list of mirrors of Tor Project's website.",
"smtp_help_msg": "Hi! This is the GetTor robot. I am here to help you download the\nlatest version of Tor Browser.\n\nPlease reply to this message with one of the options below:\n\nwindows\nlinux\nosx\nmirrors\n\nI will then send you the download instructions.\n\nIf you are unsure, just send a blank reply to this message."
}
{
"links_body": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n \n--\nGetTor",
"links_subject": "[GetTor] Links for your request",
"help_body": "This is how you can request a tor browser bundle link.\n\n Send an email to: gettor@torproject.org\n\nIn the body of the email only write: <operating system> <language>.\n\nWe only support windows, osx and linux as operating systems.\n\nAt the moment please only use en as language.\n\n",
"help_subject": "[GetTor] Help Email",
"help_debug": "Log application errors to stdout",
"help_config": "Custom config file location (optional)",
"smtp_links_subject": "[GetTor] Links for your request",
"smtp_mirrors_subject": "[GetTor] Mirrors",
"smtp_help_subject": "[GetTor] Help",
"smtp_unsupported_locale_subject": "[GetTor] Unsupported locale",
"smtp_unsupported_locale_msg": "The locale you requested '{}' is not supported.",
"smtp_vlinks_msg": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n \n--\nGetTor",
"smtp_mirrors_msg": "Hi! this is the GetTor robot.\n\nThank you for your request. Attached to this email you will find\nan updated list of mirrors of Tor Project's website.",
"smtp_help_msg": "Hi! This is the GetTor robot. I am here to help you download the\nlatest version of Tor Browser.\n\nPlease reply to this message with one of the options below:\n\nwindows\nlinux\nosx\nmirrors\n\nI will then send you the download instructions.\n\nIf you are unsure, just send a blank reply to this message."
}
......@@ -4,3 +4,4 @@ from __future__ import unicode_literals
from gettor.utils import options
from gettor.services.email import sendmail
from gettor.parse.email import EmailParser, AddressError, DKIMError
......@@ -20,6 +20,17 @@ class EmailServiceTests(unittest.TestCase):
def test_get_interval(self):
self.assertEqual(self.settings.get("sendmail_interval"), self.sm_client.get_interval())
def test_help_email_parser(self):
ep = conftests.EmailParser(self.settings, "gettor@torproject.org")
request = ep.parse("From: \"silvia [hiro]\" <hiro@torproject.org>\n Subject: help\n Reply-To: hiro@torproject.org \nTo: gettor@torproject.org")
self.assertEqual(request["command"], "help")
def test_language_email_parser(self):
ep = conftests.EmailParser(self.settings, "gettor@torproject.org")
request = ep.parse("From: \"silvia [hiro]\" <hiro@torproject.org>\n Subject: osx en\r\n Reply-To: hiro@torproject.org \nTo: gettor@torproject.org\n osx English")
self.assertEqual(request["command"], "links")
self.assertEqual(request["platform"], "osx")
self.assertEqual(request["language"], "en")
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment