Commit 9642949b authored by Michal Čihař's avatar Michal Čihař

Share code for translation parsing from command line

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 0516409c
......@@ -195,3 +195,19 @@ class WeblateLangCommand(WeblateCommand):
"""
raise NotImplementedError()
class WeblateTranslationCommand(BaseCommand):
"""Command with target of one translation."""
args = '<project> <component> <language>'
def get_translation(self, args):
"""Get translation object"""
try:
return Translation.objects.get(
subproject__project__slug=args[0],
subproject__slug=args[1],
language__code=args[2],
)
except Translation.DoesNotExist:
raise CommandError('No matching translation project found!')
......@@ -20,21 +20,22 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.contrib.auth.models import User
from django.http.request import HttpRequest
from weblate.trans.models import Translation
from weblate.accounts.models import get_author_name
from weblate.trans.management.commands import WeblateTranslationCommand
class Command(BaseCommand):
"""
class Command(WeblateTranslationCommand):
"""WeblateTranslationCommand
Command for mass importing suggestions.
"""
help = 'imports suggestions'
args = '<project> <component> <language> <file>'
option_list = BaseCommand.option_list + (
option_list = WeblateTranslationCommand.option_list + (
make_option(
'--author',
default='noreply@weblate.org',
......@@ -50,14 +51,7 @@ class Command(BaseCommand):
raise CommandError('Invalid number of parameters!')
# Get translation object
try:
translation = Translation.objects.get(
subproject__project__slug=args[0],
subproject__slug=args[1],
language__code=args[2],
)
except Translation.DoesNotExist:
raise CommandError('No matching translation project found!')
translation = self.get_translation(args)
# Get user
try:
......
......@@ -20,20 +20,20 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from django.contrib.auth.models import User
from weblate.trans.models import Translation, SubProject
from weblate.trans.autotranslate import auto_translate
from weblate.trans.management.commands import WeblateTranslationCommand
class Command(BaseCommand):
class Command(WeblateTranslationCommand):
"""
Command for mass automatic translation.
"""
help = 'performs automatic translation based on other components'
args = '<project> <component> <language>'
option_list = BaseCommand.option_list + (
option_list = WeblateTranslationCommand.option_list + (
make_option(
'--user',
default='anonymous',
......@@ -72,14 +72,7 @@ class Command(BaseCommand):
raise CommandError('Invalid number of parameters!')
# Get translation object
try:
translation = Translation.objects.get(
subproject__project__slug=args[0],
subproject__slug=args[1],
language__code=args[2],
)
except Translation.DoesNotExist:
raise CommandError('No matching translation project found!')
translation = self.get_translation(args)
# Get user
try:
......
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