Coverage for app/venv/lib/python3.14/site-packages/weblate/trans/management/commands/add_suggestions.py: 0%
28 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4from __future__ import annotations
6from pathlib import Path
7from typing import TYPE_CHECKING
9from django.core.management.base import CommandError
10from django.http.request import HttpRequest
12from weblate.trans.management.commands import WeblateTranslationCommand
14if TYPE_CHECKING:
15 from django.core.management.base import CommandParser
18class Command(WeblateTranslationCommand):
19 """Command for mass importing suggestions."""
21 help = "imports suggestions"
23 def add_arguments(self, parser: CommandParser) -> None:
24 super().add_arguments(parser)
25 parser.add_argument(
26 "--author",
27 default="noreply@weblate.org",
28 help=("Email address of author (has to be registered in Weblate)"),
29 )
30 parser.add_argument("file", type=Path, help="File to import")
32 def handle(self, *args, **options) -> None:
33 # Get translation object
34 translation = self.get_translation(**options)
36 # Create fake request object
37 request = HttpRequest()
38 request.user = None
40 # Process import
41 try:
42 with options["file"].open("rb") as handle:
43 try:
44 translation.handle_upload(
45 request,
46 handle,
47 False,
48 method="suggest",
49 author_email=options["author"],
50 )
51 except OSError as error:
52 msg = f"Could not import translation file: {error}"
53 raise CommandError(msg) from error
54 except OSError as error:
55 msg = f"Could not open file: {error}"
56 raise CommandError(msg) from error