コード例 #1
0
ファイル: edit.py プロジェクト: anurag1212/weblate
def auto_translation(request, project, subproject, lang):
    translation = get_translation(request, project, subproject, lang)
    project = translation.subproject.project
    if not can_automatic_translation(request.user, project):
        raise PermissionDenied()

    autoform = AutoForm(translation, request.user, request.POST)

    if translation.subproject.locked or not autoform.is_valid():
        messages.error(request, _('Failed to process form!'))
        return redirect(translation)

    updated = auto_translate(request.user, translation,
                             autoform.cleaned_data['subproject'],
                             autoform.cleaned_data['inconsistent'],
                             autoform.cleaned_data['overwrite'])

    import_message(
        request, updated,
        _('Automatic translation completed, no strings were updated.'),
        ungettext('Automatic translation completed, %d string was updated.',
                  'Automatic translation completed, %d strings were updated.',
                  updated))

    return redirect(translation)
コード例 #2
0
ファイル: auto_translate.py プロジェクト: Yixf-Self/weblate
    def handle(self, *args, **options):
        # Get translation object
        translation = self.get_translation(**options)

        # Get user
        try:
            user = User.objects.get(username=options['user'])
            Profile.objects.get_or_create(user=user)
        except User.DoesNotExist:
            raise CommandError('User does not exist!')

        if options['source']:
            parts = options['source'].split('/')
            if len(parts) != 2:
                raise CommandError('Invalid source component specified!')
            try:
                subproject = SubProject.objects.get(
                    project__slug=parts[0],
                    slug=parts[1],
                )
            except SubProject.DoesNotExist:
                raise CommandError('No matching source component found!')
            source = subproject.id
        else:
            source = ''

        result = auto_translate(
            user, translation, source,
            options['inconsistent'], options['overwrite']
        )
        self.stdout.write('Updated {0} units'.format(result))
コード例 #3
0
ファイル: edit.py プロジェクト: Yixf-Self/weblate
def auto_translation(request, project, subproject, lang):
    translation = get_translation(request, project, subproject, lang)
    project = translation.subproject.project
    if not can_automatic_translation(request.user, project):
        raise PermissionDenied()

    autoform = AutoForm(translation, request.user, request.POST)

    if translation.subproject.locked or not autoform.is_valid():
        messages.error(request, _('Failed to process form!'))
        return redirect(translation)

    updated = auto_translate(
        request.user,
        translation,
        autoform.cleaned_data['subproject'],
        autoform.cleaned_data['inconsistent'],
        autoform.cleaned_data['overwrite']
    )

    import_message(
        request, updated,
        _('Automatic translation completed, no strings were updated.'),
        ungettext(
            'Automatic translation completed, %d string was updated.',
            'Automatic translation completed, %d strings were updated.',
            updated
        )
    )

    return redirect(translation)
コード例 #4
0
ファイル: auto_translate.py プロジェクト: sc123088/weblate
    def handle(self, *args, **options):
        # Check params
        if len(args) != 3:
            raise CommandError('Invalid number of parameters!')

        # Get translation object
        translation = self.get_translation(args)

        # Get user
        try:
            user = User.objects.get(username=options['user'])
        except User.DoesNotExist:
            raise CommandError('User does not exist!')

        if options['source']:
            parts = options['source'].split('/')
            if len(parts) != 2:
                raise CommandError('Invalid source component specified!')
            try:
                subproject = SubProject.objects.get(
                    project__slug=parts[0],
                    slug=parts[1],
                )
            except SubProject.DoesNotExist:
                raise CommandError('No matching source component found!')
            source = subproject.id
        else:
            source = ''

        result = auto_translate(user, translation, source,
                                options['inconsistent'], options['overwrite'])
        self.stdout.write('Updated {0} units'.format(result))