This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This gives me a command-line way to test translation systems. It's a lot easier than creating feedback and then triggering a translation for it and then removing the translation from the db.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from optparse import make_option | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from fjord.translations.models import get_translation_systems | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Translate some text with specified system.' | ||
option_list = BaseCommand.option_list + ( | ||
make_option('--system', type='string', dest='system', | ||
default=u'fake', | ||
help=u'The translation system to use.'), | ||
) | ||
def handle(self, *args, **options): | ||
system = options['system'] | ||
|
||
if len(args) < 2: | ||
raise CommandError( | ||
'Usage: ./manage.py trans [--system=SYSTEM] lang text' | ||
) | ||
|
||
lang, text = args | ||
|
||
system_classes = get_translation_systems().values() | ||
|
||
class TextClass(object): | ||
def __init__(self, src, locale): | ||
self.id = 'ou812' | ||
self.src = src | ||
self.locale = locale | ||
self.dest = '' | ||
|
||
def save(self, *args, **kwargs): | ||
pass | ||
|
||
instance = TextClass(text, lang) | ||
|
||
for system_cls in system_classes: | ||
if system_cls.name == system: | ||
system_cls().translate(instance, lang, 'src', 'en', 'dest') | ||
print 'Translated to:' | ||
print instance.dest | ||
break | ||
|
||
else: | ||
print 'No such translation system.' | ||
print ', '.join([system_cls.name for system_cls in system_classes]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters