Skip to content

Commit c3cdbee

Browse files
committed
initial implementation suggestion
1 parent 2aafaff commit c3cdbee

File tree

6 files changed

+126
-13
lines changed

6 files changed

+126
-13
lines changed

docs/formats/tbx.rst

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,7 @@
33
TermBase eXchange format
44
------------------------
55

6-
.. list-table:: Supported features
7-
8-
* - :ref:`format-explanation`
9-
- Source string explanation is saved and loaded from the ``<descrip>``
10-
tag, translation string explanation from ``<note from="translator">``.
11-
12-
* - Administrative status
13-
- Terms with administrative status ``forbidden`` or ``obsolete`` in ``<termNote type="administrativeStatus">``
14-
are marked with the ``forbidden`` flag (:ref:`glossary-forbidden`).
15-
* - Translation needed
16-
- Terms with ``<termNote type="translationNote">`` containing ``no`` are marked as read-only (:ref:`glossary-untranslatable`).
17-
* - Usage notes
18-
- Usage notes from ``<descrip type="Usage note">`` tags are displayed in the glossary.
6+
.. include:: snippets/format-features/tbx-features.rst
197

208
.. versionadded:: 4.5
219
.. versionchanged:: 5.12
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. list-table:: Supported features
2+
3+
* - Identifier
4+
- tbx
5+
* - Common extensions
6+
- tbx
7+
* - Linguality
8+
- bilingual
9+
* - Supports descriptions
10+
- Yes
11+
* - Supports context
12+
- Yes
13+
* - Supports location
14+
- No
15+
* - Supports flags
16+
- Yes
17+
* - Supports additional states
18+
- No
19+
* - Supports read-only strings
20+
- No
21+
* - :ref:`format-explanation`
22+
- Source string explanation is saved and loaded from the ``<descrip>`` tag, translation string explanation from ``<note from="translator">``
23+
* - Administrative status
24+
- Terms with administrative status ``forbidden`` or ``obsolete`` in ``<termNote type="administrativeStatus">`` are marked with the ``forbidden`` flag (:ref:`glossary-forbidden`).
25+
* - Translation needed
26+
- Terms with ``<termNote type="translationNote">`` containing ``no`` are marked as read-only (:ref:`glossary-untranslatable`).
27+
* - Usage notes
28+
- Usage notes from ``<descrip type="Usage note">`` tags are displayed in the glossary.

weblate/formats/docs.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

weblate/formats/management/__init__.py

Whitespace-only changes.

weblate/formats/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright © Michal Čihař <michal@weblate.org>
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
from pathlib import Path
6+
7+
from django.core.management.base import BaseCommand
8+
9+
from weblate.formats.docs import FEATURES_REGISTRY
10+
11+
12+
class Command(BaseCommand):
13+
help = "Update format features snippets"
14+
15+
def handle(self, *args, **options) -> None:
16+
snippets_dir = Path("docs/snippets/format-features")
17+
18+
for format_id, format_features in FEATURES_REGISTRY.items():
19+
file_path = snippets_dir / f"{format_id}-features.rst"
20+
file_path.write_text(format_features().list_features())

0 commit comments

Comments
 (0)