dpgaspar commented on code in PR #23252:
URL: https://github.com/apache/superset/pull/23252#discussion_r1133639563
##########
setup.py:
##########
@@ -126,6 +126,7 @@ def get_git_sha() -> str:
"wtforms>=2.3.3, <2.4",
"wtforms-json",
"xlsxwriter>=3.0.7, <3.1",
+ "translate == 3.6.1",
Review Comment:
this could be made an extra requirement
##########
superset/jinja_context.py:
##########
@@ -344,6 +346,54 @@ def get_filters(self, column: str, remove_filter: bool =
False) -> List[Filter]:
return filters
+ def translate(
+ self,
+ string_to_translate: str,
+ to_language: str,
+ from_language: str = "en",
+ add_to_cache_keys: bool = True,
+ escape_result: bool = True,
+ ) -> str:
+ """
+ To get a translation dynamically through Jinja templating
+
+ Usage example: (Translation to french)
+ SELECT '{{ translate('my sentence', 'fr') }}' AS translation
+
+ Output:
+ translation
+ -----------
+ ma phrase
+
+ Python package : https://pypi.org/project/translate/
+ Available languages:
+
+ https://en.wikipedia.org/wiki/ISO_639-1
+ Examples: (e.g. en, ja, ko, pt, zh, zh-TW, ...)
+ """
+ if to_language is None:
+ return string_to_translate
+
+ provider_name = current_app.config.get("PROVIDER_CREDENTIALS_DICT",
"mymemory")
+ secret = current_app.config.get("TRANSLATION_SECRET_ACCESS_KEY", None)
Review Comment:
We assume on the code base that all the necessary config keys are always
present with a default value. On this case it could make sense to just rely on
the package config methodology. More if we decide to use this package has an
extra.
--
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]