| 1 |
from .. import annotations |
| 2 |
from ..errors import CodeAction, CompileWarning |
| 3 |
from ..language import Property, Translated, Value |
| 4 |
from .utils import LinterRule |
| 5 |
|
| 6 |
|
| 7 |
class TranslatableDisplayString(LinterRule): |
| 8 |
id = "translate_display_string" |
| 9 |
severity = "suggestion" |
| 10 |
category = "hig" |
| 11 |
|
| 12 |
def check(self, type, child, stack): |
| 13 |
# rule suggestion/translatable-display-string |
| 14 |
for property in child.content.children[Property]: |
| 15 |
if not annotations.is_property_user_facing_string(property.gir_property): |
| 16 |
continue |
| 17 |
|
| 18 |
value = property.value |
| 19 |
if not isinstance(value, Value): |
| 20 |
continue |
| 21 |
|
| 22 |
if not isinstance(value.child, Translated): |
| 23 |
range = value.range |
| 24 |
self.problems.append( |
| 25 |
CompileWarning( |
| 26 |
f'Mark {type} {property.name} as translatable using _("...")', |
| 27 |
range, |
| 28 |
actions=[ |
| 29 |
CodeAction("mark as translatable", "_(" + range.text + ")") |
| 30 |
], |
| 31 |
id=self.id, |
| 32 |
) |
| 33 |
) |