Copilot commented on code in PR #33189:
URL: https://github.com/apache/superset/pull/33189#discussion_r2264136362
##########
superset/utils/core.py:
##########
@@ -1831,3 +1833,10 @@ def get_user_agent(database: Database, source:
QuerySource | None) -> str:
return user_agent_func(database, source)
return DEFAULT_USER_AGENT
+
+
+def activate_humanize_locale() -> str:
Review Comment:
The function returns a string but doesn't return anything in its
implementation. Either add a return statement with the locale value or change
the return type to None.
##########
superset/utils/core.py:
##########
@@ -1831,3 +1833,10 @@ def get_user_agent(database: Database, source:
QuerySource | None) -> str:
return user_agent_func(database, source)
return DEFAULT_USER_AGENT
+
+
+def activate_humanize_locale() -> str:
+ locale = session.get("locale", "en")
+ if (locale != "en"):
Review Comment:
Unnecessary parentheses around the condition. Remove the parentheses for
cleaner code: `if locale != "en":`
```suggestion
if locale != "en":
```
##########
superset/utils/core.py:
##########
@@ -1831,3 +1833,10 @@ def get_user_agent(database: Database, source:
QuerySource | None) -> str:
return user_agent_func(database, source)
return DEFAULT_USER_AGENT
+
+
+def activate_humanize_locale() -> str:
+ locale = session.get("locale", "en")
+ if (locale != "en"):
+ locale = LOCALES_LANGUAGE_MAP.get(locale, "en_US")
+ humanize.i18n.activate(locale)
Review Comment:
The locale variable is reassigned but the original session locale value is
lost. Consider using a different variable name for the mapped locale to avoid
confusion.
```suggestion
if locale != "en":
mapped_locale = LOCALES_LANGUAGE_MAP.get(locale, "en_US")
humanize.i18n.activate(mapped_locale)
```
##########
superset/constants.py:
##########
@@ -203,6 +203,25 @@ class RouteMethod: # pylint:
disable=too-few-public-methods
| EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS
)
+LOCALES_LANGUAGE_MAP = {
+ "en": "en_US",
+ "es": "es_ES",
+ "it": "it_IT",
+ "fr": "fr_FR",
+ "zh": "zh_CN",
+ "zh_TW": "zh_HK",
Review Comment:
Traditional Chinese (Taiwan) is mapped to Hong Kong locale instead of
Taiwan. This should likely be "zh_TW": "zh_TW" or verify if zh_HK is the
correct humanize locale for Traditional Chinese.
```suggestion
"zh_TW": "zh_TW",
```
--
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]