From 37b0e08b17a115b8137b320acde9ff7750edbc27 Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Thu, 28 Dec 2023 13:34:18 -0700 Subject: [PATCH] fix(translation): proper type handling with state translation --- trame_client/widgets/core.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/trame_client/widgets/core.py b/trame_client/widgets/core.py index 47b862d..8d495f6 100644 --- a/trame_client/widgets/core.py +++ b/trame_client/widgets/core.py @@ -462,18 +462,17 @@ def attrs(self, *names): self._attributes[name] = js_key else: self._attributes[name] = f':{js_key}="false"' - elif isinstance(value, (str, int, float)): + elif isinstance(value, str): if js_key.startswith("v-") or js_key.startswith(":"): logger.info("before: %s = %s", js_key, value) - translated_value = ( - self.server.state.translator.translate_js_expression( - self.server.state, value - ) + value = self.server.state.translator.translate_js_expression( + self.server.state, value ) - logger.info("after: %s = %s", js_key, translated_value) - self._attributes[name] = f'{js_key}="{translated_value}"' - else: - self._attributes[name] = f'{js_key}="{value}"' + logger.info("after: %s = %s", js_key, value) + + self._attributes[name] = f'{js_key}="{value}"' + elif isinstance(value, (int, float)): + self._attributes[name] = f'{js_key}="{value}"' else: print( f"Error: Don't know how to handle attribute name '{name}' with value '{value}' in {self.__class__}::{self._elem_name}"