|
11 | 11 | from collections.abc import Callable |
12 | 12 | from dataclasses import asdict, dataclass |
13 | 13 | from enum import auto, Enum |
14 | | -from typing import Any, Generic, Mapping, Sequence, TypeVar |
| 14 | +from typing import Any, Generic, Mapping, Optional, Protocol, Sequence, TypeVar |
15 | 15 |
|
16 | 16 | from cmk.utils.exceptions import MKGeneralException |
17 | 17 |
|
@@ -104,16 +104,16 @@ def _get_visitor(form_spec: FormSpec, options: VisitorOptions) -> FormSpecVisito |
104 | 104 | return visitor(supported_form_spec, options) |
105 | 105 |
|
106 | 106 |
|
| 107 | +class SupportsLocalize(Protocol): |
| 108 | + def localize(self, localizer: Callable[[str], str]) -> str: ... |
| 109 | + |
| 110 | + |
| 111 | +def _localize(localizable: Optional[SupportsLocalize]) -> str: |
| 112 | + return "" if localizable is None else localizable.localize(translate_to_current_language) |
| 113 | + |
| 114 | + |
107 | 115 | def _get_title_and_help(form_spec: FormSpec) -> tuple[str, str]: |
108 | | - title = ( |
109 | | - "" if form_spec.title is None else form_spec.title.localize(translate_to_current_language) |
110 | | - ) |
111 | | - help_text = ( |
112 | | - "" |
113 | | - if form_spec.help_text is None |
114 | | - else form_spec.help_text.localize(translate_to_current_language) |
115 | | - ) |
116 | | - return title, help_text |
| 116 | + return _localize(form_spec.title), _localize(form_spec.help_text) |
117 | 117 |
|
118 | 118 |
|
119 | 119 | def _optional_validation( |
@@ -170,7 +170,10 @@ def to_vue(self, value: int) -> tuple[VueComponents.FormSpec, Value]: |
170 | 170 | title, help_text = _get_title_and_help(self.form_spec) |
171 | 171 | return ( |
172 | 172 | VueComponents.Integer( |
173 | | - title=title, help=help_text, validators=build_vue_validators(self._validators()) |
| 173 | + title=title, |
| 174 | + help=help_text, |
| 175 | + label=_localize(self.form_spec.label), |
| 176 | + validators=build_vue_validators(self._validators()), |
174 | 177 | ), |
175 | 178 | value, |
176 | 179 | ) |
|
0 commit comments