sadpandajoe commented on code in PR #40679:
URL: https://github.com/apache/superset/pull/40679#discussion_r3911882966


##########
superset/jinja_context.py:
##########
@@ -1251,6 +1252,24 @@ def get_template_processor(
     return template_processor(database=database, table=table, query=query, 
**kwargs)
 
 
+def i18n_macro(default_text: str) -> str:
+    """Jinja macro for translating asset metadata into the viewer's locale.
+
+    Usage in a templated field (e.g. a chart axis label or native filter 
name)::
+
+        {{ i18n('Sales') }}
+
+    Resolution is delegated to the configured ``TRANSLATION_HOOK`` and gated by
+    the ``ENABLE_I18N_ASSET_TRANSLATIONS`` feature flag; when the feature is 
off
+    or no translation exists, the original text is returned unchanged. See
+    ``superset.utils.i18n`` and SIP-161.
+    """
+    # pylint: disable=import-outside-toplevel
+    from superset.utils.i18n import translate
+
+    return translate(default_text, model_name="template", field_name="i18n") 
or ""

Review Comment:
   This renders locale-dependent SQL without participating in `ExtraCache`: 
`i18n` is absent from the macro regex and this path never adds a cache key. A 
French viewer can populate a cached query result containing the translated SQL, 
then an English viewer receives that result within the cache timeout. Could 
this add the locale or resolved value to the extra cache keys?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to