Coverage for app/venv/lib/python3.14/site-packages/weblate/memory/management/commands/dump_memory.py: 0%
18 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
6import json
7from typing import TYPE_CHECKING
9from weblate.memory.models import Memory
10from weblate.utils.management.base import BaseCommand
12if TYPE_CHECKING:
13 from django.core.management.base import CommandParser
16class Command(BaseCommand):
17 """Command for exporting translation memory."""
19 help = "exports translation memory in JSON format"
21 def add_arguments(self, parser: CommandParser) -> None:
22 super().add_arguments(parser)
23 parser.add_argument(
24 "--indent",
25 default=2,
26 dest="indent",
27 type=int,
28 help=("Specifies the indent level to use when pretty-printing output."),
29 )
30 parser.add_argument(
31 "--backup",
32 action="store_true",
33 help="Store backup to the backups directory in the DATA_DIR",
34 )
36 def handle(self, *args, **options) -> None:
37 memory = Memory.objects.all().prefetch_lang()
38 self.stdout.ending = None # type: ignore[assignment]
39 json.dump(
40 [item.as_dict() for item in memory], self.stdout, indent=options["indent"]
41 )
42 self.stdout.write("\n")