|
| 1 | +# Copyright © Michal Čihař <michal@weblate.org> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +from typing import TYPE_CHECKING, ClassVar, Literal |
| 8 | + |
| 9 | +from weblate.formats.ttkit import TBXFormat |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from weblate.formats.ttkit import TTKitFormat |
| 13 | + from weblate.utils.state import StringState |
| 14 | + |
| 15 | + |
| 16 | +class BaseFormatFeatures: |
| 17 | + """Base class for format capability attributes (see docs/formats.rst capabilities table).""" |
| 18 | + |
| 19 | + format: type[TTKitFormat] |
| 20 | + linguality: Literal["bilingual", "mono", "both"] = "mono" |
| 21 | + plurals: bool = False |
| 22 | + descriptions: bool = False |
| 23 | + context: bool = False |
| 24 | + location: bool = False |
| 25 | + flags: bool = False |
| 26 | + additional_states: tuple[StringState, ...] = () |
| 27 | + additional_features: ClassVar[dict[str, str]] = {} |
| 28 | + read_only_strings: bool = False |
| 29 | + |
| 30 | + def list_features(self) -> str: |
| 31 | + output = [] |
| 32 | + |
| 33 | + def new_row(*columns: str) -> None: |
| 34 | + output.extend( |
| 35 | + [ |
| 36 | + f" * - {columns[0]}", |
| 37 | + *[f" - {column}" for column in columns[1:]], |
| 38 | + ] |
| 39 | + ) |
| 40 | + |
| 41 | + output.append(".. list-table:: Supported features\n") |
| 42 | + new_row("Identifier", self.format.format_id) |
| 43 | + new_row("Common extensions", ", ".join(self.format.get_class().Extensions)) |
| 44 | + new_row("Linguality", self.linguality) |
| 45 | + |
| 46 | + new_row("Supports descriptions", "Yes" if self.descriptions else "No") |
| 47 | + new_row("Supports context", "Yes" if self.context else "No") |
| 48 | + new_row("Supports location", "Yes" if self.location else "No") |
| 49 | + new_row("Supports flags", "Yes" if self.flags else "No") |
| 50 | + new_row("Supports additional states", "Yes" if self.additional_states else "No") |
| 51 | + new_row("Supports read-only strings", "Yes" if self.read_only_strings else "No") |
| 52 | + |
| 53 | + for feature, description in self.additional_features.items(): |
| 54 | + new_row(feature, description) |
| 55 | + |
| 56 | + output.append("\n") |
| 57 | + return "\n".join(output) |
| 58 | + |
| 59 | + |
| 60 | +class TBXFeatures(BaseFormatFeatures): |
| 61 | + format = TBXFormat |
| 62 | + linguality = "bilingual" |
| 63 | + descriptions = True |
| 64 | + context = True |
| 65 | + location = False |
| 66 | + flags = True |
| 67 | + additional_features: ClassVar[dict[str, str]] = { |
| 68 | + ":ref:`format-explanation`": 'Source string explanation is saved and loaded from the ``<descrip>`` tag, translation string explanation from ``<note from="translator">``', |
| 69 | + "Administrative status": 'Terms with administrative status ``forbidden`` or ``obsolete`` in ``<termNote type="administrativeStatus">`` are marked with the ``forbidden`` flag (:ref:`glossary-forbidden`).', |
| 70 | + "Translation needed": 'Terms with ``<termNote type="translationNote">`` containing ``no`` are marked as read-only (:ref:`glossary-untranslatable`).', |
| 71 | + "Usage notes": 'Usage notes from ``<descrip type="Usage note">`` tags are displayed in the glossary.', |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | +FEATURES_REGISTRY = { |
| 76 | + "tbx": TBXFeatures, |
| 77 | +} |
0 commit comments