Skip to content

Commit

Permalink
Merge pull request #19 from Kitware/fix-state-translation
Browse files Browse the repository at this point in the history
fix(translation): proper type handling with state translation
  • Loading branch information
jourdain authored Dec 29, 2023
2 parents 5e33d6b + 37b0e08 commit a4e0385
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions trame_client/widgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit a4e0385

Please sign in to comment.