Commit 0607f940 authored by Michal Čihař's avatar Michal Čihař

Configurable source language

Source language can now be set sitewide in SOURCE_LANGUAGE setting.
Closes #390
parent d065fecf
......@@ -345,6 +345,14 @@ SITE_TITLE
Site title to be used in website and emails as well.
.. setting:: SOURCE_LANGUAGE
SOURCE_LANGUAGE
---------------
Source language used for translation. This is mostly useful for machine
translation services.
.. setting:: TTF_PATH
TTF_PATH
......
......@@ -11,6 +11,9 @@ up to administrator to enable them. The services have different terms of use, so
please check whether you are allowed to use them before enabling in Weblate.
The individual services are enabled using :setting:`MACHINE_TRANSLATION_SERVICES`.
The source langauge can be configured by :setting:`SOURCE_LANGUAGE` and is
shared for all translations within Weblate.
Amagama
+++++++
......
......@@ -41,14 +41,14 @@ class ApertiumTranslation(MachineTranslation):
data = self.json_status_req('http://api.apertium.org/json/listPairs')
return [item['targetLanguage']
for item in data['responseData']
if item['sourceLanguage'] == 'en']
if item['sourceLanguage'] == appsettings.SOURCE_LANGUAGE]
def download_translations(self, language, text, unit, user):
'''
Downloads list of possible translations from Apertium.
'''
args = {
'langpair': 'en|%s' % language,
'langpair': '%s|%s' % (appsettings.SOURCE_LANGUAGE, language),
'q': text.encode('utf-8'),
}
if appsettings.MT_APERTIUM_KEY is not None:
......
......@@ -19,6 +19,7 @@
#
from trans.machine.base import MachineTranslation
from weblate import appsettings
class GlosbeTranslation(MachineTranslation):
......@@ -44,7 +45,7 @@ class GlosbeTranslation(MachineTranslation):
Downloads list of possible translations from a service.
'''
params = {
'from': 'en',
'from': appsettings.SOURCE_LANGUAGE,
'dest': language,
'format': 'json',
'phrase': text.strip(',.:?! ').encode('utf-8')
......
......@@ -67,7 +67,7 @@ class GoogleTranslation(MachineTranslation):
'https://www.googleapis.com/language/translate/v2/',
key=appsettings.MT_GOOGLE_KEY,
q=text.encode('utf-8'),
source='en',
source=appsettings.SOURCE_LANGUAGE,
target=language,
)
......@@ -99,7 +99,7 @@ class GoogleWebTranslation(MachineTranslation):
'http://translate.google.com/translate_a/t',
client='t',
text=text.encode('utf-8'),
sl='en',
sl=appsettings.SOURCE_LANGUAGE,
tl=language,
ie='UTF-8',
oe='UTF-8'
......
......@@ -117,7 +117,7 @@ class MicrosoftTranslation(MachineTranslation):
'''
args = {
'text': text[:5000].encode('utf-8'),
'from': 'en',
'from': appsettings.SOURCE_LANGUAGE,
'to': language,
'contentType': 'text/plain',
'category': 'general',
......
......@@ -70,7 +70,7 @@ class MyMemoryTranslation(MachineTranslation):
'''
args = {
'q': text.split('. ')[0][:500].encode('utf-8'),
'langpair': 'en|%s' % language,
'langpair': '%s|%s' % (appsettings.SOURCE_LANGUAGE, language),
}
if appsettings.MT_MYMEMORY_EMAIL is not None:
args['de'] = appsettings.MT_MYMEMORY_EMAIL
......
......@@ -21,6 +21,8 @@
from trans.machine.base import MachineTranslation
import urllib
from weblate import appsettings
class OpenTranTranslation(MachineTranslation):
'''
......@@ -56,8 +58,8 @@ class OpenTranTranslation(MachineTranslation):
Downloads list of possible translations from a service.
'''
response = self.json_req(
'http://en.%s.open-tran.eu/json/suggest/%s' % (
language, urllib.quote(text.encode('utf-8'))
'http://%s.%s.open-tran.eu/json/suggest/%s' % (
appsettings.SOURCE_LANGUAGE, language, urllib.quote(text.encode('utf-8'))
)
)
......
......@@ -20,9 +20,10 @@
from trans.machine.base import MachineTranslation
from django.core.exceptions import ImproperlyConfigured
from weblate.appsettings import MT_TMSERVER
import urllib
from weblate import appsettings
class TMServerTranslation(MachineTranslation):
'''
......@@ -41,12 +42,12 @@ class TMServerTranslation(MachineTranslation):
'''
Returns URL of a server.
'''
if MT_TMSERVER is None:
if appsettings.MT_TMSERVER is None:
raise ImproperlyConfigured(
'Not configured tmserver URL'
)
return MT_TMSERVER.rstrip('/')
return appsettings.MT_TMSERVER.rstrip('/')
def convert_language(self, language):
'''
......@@ -64,8 +65,9 @@ class TMServerTranslation(MachineTranslation):
'''
Downloads list of possible translations from a service.
'''
url = '%s/tmserver/en/%s/unit/%s' % (
url = '%s/tmserver/%s/%s/unit/%s' % (
self.url,
urllib.quote(appsettings.SOURCE_LANGUAGE),
urllib.quote(language),
urllib.quote(text.encode('utf-8')),
)
......
......@@ -152,3 +152,6 @@ REGISTRATION_OPEN = get('REGISTRATION_OPEN', True)
# Captcha for registrations
REGISTRATION_CAPTCHA = get('REGISTRATION_CAPTCHA', True)
# Source language
SOURCE_LANGUAGE = get('SOURCE_LANGUAGE', 'en')
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