Пример #1
0
    def handle(self, *args, **options):
        systems = getattr(settings, 'TRANSLATION_SYSTEMS_TO_SYNC', [])
        if not systems:
            raise CommandError(
                'No systems to sync. Set '
                'settings.TRANSLATION_SYSTEMS_TO_SYNC = [SYSTEMS]')

        all_systems = get_translation_systems()

        system_classes = []
        try:
            for key in systems:
                system_classes.append(all_systems[key])
        except KeyError:
            # FIXME - This is lazy error reporting. It should report
            # the system that
            raise CommandError(
                'System "{0}" does not exist. '
                'Existing systems are {0}.'.format(
                    key, all_systems.keys()))

        for system_cls in system_classes:
            system = system_cls()
            print '>>> {0} translation system'.format(system.name)
            print 'Pulling...'
            system.pull_translations()
            print 'Pushing...'
            system.push_translations()

        print '>>> Done!'
Пример #2
0
def translate(instance, system, src_lang, src_field, dst_lang, dst_field):
    """Translates specified field using specified system

    :arg instance: A model instance with fields to be translated
    :arg system: The name of the system to be used to do the translation
    :arg src_lang: The language to translate from
    :arg src_field: The name of the source field
    :arg dst_lang: The language to translate to
    :arg dst_field: The name of the destination field

    If the method is synchronous, then this will translate the field
    value and stick it in the translated field immediately.

    If the method is asynchronous, then this will return and the
    translated field will be filled in at some unspecified time.

    """
    # Have to import this here because of circular import problems.
    from fjord.translations.models import get_translation_systems

    # Get the translation system class.
    TranslationSystem = get_translation_systems().get(system)
    if not TranslationSystem:
        raise NoSuchSystem(
            '{0} is not a valid translation system'.format(system))

    # Instantiate the translate system class and translate this text!
    trans_system = TranslationSystem()
    trans_system.translate(instance, src_lang, src_field, dst_lang, dst_field)
Пример #3
0
    def handle(self, *args, **options):
        systems = getattr(settings, 'TRANSLATION_SYSTEMS_TO_SYNC', [])
        if not systems:
            raise CommandError(
                'No systems to sync. Set '
                'settings.TRANSLATION_SYSTEMS_TO_SYNC = [SYSTEMS]')

        all_systems = get_translation_systems()

        system_classes = []
        try:
            for key in systems:
                system_classes.append(all_systems[key])
        except KeyError:
            # FIXME - This is lazy error reporting. It should report
            # the system that
            raise CommandError('System "{0}" does not exist. '
                               'Existing systems are {0}.'.format(
                                   key, all_systems.keys()))

        for system_cls in system_classes:
            system = system_cls()
            print '>>> {0} translation system'.format(system.name)
            print 'Pulling...'
            system.pull_translations()
            print 'Pushing...'
            system.push_translations()

        print '>>> Done!'
Пример #4
0
    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])
Пример #5
0
    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])
Пример #6
0
def spot_translate(request, responseid):
    # FIXME: This is gengo-machine specific for now.
    resp = get_object_or_404(Response, id=responseid)
    system = request.POST.get('system', None)
    total_jobs = 0
    if system and system in get_translation_systems():
        total_jobs += len(create_translation_tasks(resp, system=system))

    # FIXME: If there's no system specified, we should tell the user
    # something. I'm going to defer fixing that for now since the user
    # would have to be doing "sneaky" things to hit that situation.

    messages.success(request,
                     '%s %s translation jobs added' % (total_jobs, system))
    return HttpResponseRedirect(reverse('response_view', args=(responseid, )))
Пример #7
0
def spot_translate(request, responseid):
    # FIXME: This is gengo-machine specific for now.
    resp = get_object_or_404(Response, id=responseid)
    system = request.POST.get('system', None)
    total_jobs = 0
    if system and system in get_translation_systems():
        total_jobs += len(create_translation_tasks(resp, system=system))

    # FIXME: If there's no system specified, we should tell the user
    # something. I'm going to defer fixing that for now since the user
    # would have to be doing "sneaky" things to hit that situation.

    messages.success(request, '%s %s translation jobs added' % (
        total_jobs, system))
    return HttpResponseRedirect(
        reverse('response_view', args=(responseid,)))
Пример #8
0
    def handle(self, *args, **options):
        verbose = (int(options.get('verbosity', 1)) >= 1)
        system_classes = get_translation_systems().values()

        for system_cls in system_classes:
            if not system_cls.use_daily:
                continue

            system = system_cls()

            if verbose:
                print '>>> {0} translation system'.format(system.name)
            system.run_daily_activities()

        if verbose:
            print '>>> Done!'
Пример #9
0
def spot_translate(request, responseid):
    # FIXME: This is gengo-machine specific for now.
    resp = get_object_or_404(Response, id=responseid)
    system = request.POST.get('system', None)
    if system and system in get_translation_systems():
        create_translation_tasks(resp, system=system)

    # FIXME: If there's no system specified, we should tell the user
    # something. I'm going to defer fixing that for now since the user
    # would have to be doing "sneaky" things to hit that situation.

    # FIXME: We should return a message to the user, so they know
    # it'll happen at some point. Plus we need to let the user know
    # when it's failed.
    return HttpResponseRedirect(
        reverse('response_view', args=(responseid,)))
Пример #10
0
    def handle(self, *args, **options):
        verbose = (int(options.get('verbosity', 1)) >= 1)
        system_classes = get_translation_systems().values()

        for system_cls in system_classes:
            if not system_cls.use_push_and_pull:
                continue

            system = system_cls()

            if verbose:
                print '>>> {0} translation system'.format(system.name)
                print 'Pulling...'
            system.pull_translations()
            if verbose:
                print 'Pushing...'
            system.push_translations()

        if verbose:
            print '>>> Done!'