Skip to content

Commit 23e2f7e

Browse files
committed
Pass integer formspec label to vue
Change-Id: Ica993c8a047107e9f5ff0261876ecd2d08db4ce0
1 parent 196149a commit 23e2f7e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

cmk/gui/form_specs/vue/vue_formspec_visitor.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Callable
1212
from dataclasses import asdict, dataclass
1313
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
1515

1616
from cmk.utils.exceptions import MKGeneralException
1717

@@ -104,16 +104,16 @@ def _get_visitor(form_spec: FormSpec, options: VisitorOptions) -> FormSpecVisito
104104
return visitor(supported_form_spec, options)
105105

106106

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+
107115
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)
117117

118118

119119
def _optional_validation(
@@ -170,7 +170,10 @@ def to_vue(self, value: int) -> tuple[VueComponents.FormSpec, Value]:
170170
title, help_text = _get_title_and_help(self.form_spec)
171171
return (
172172
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()),
174177
),
175178
value,
176179
)

0 commit comments

Comments
 (0)