codeant-ai-for-open-source[bot] commented on code in PR #41780:
URL: https://github.com/apache/superset/pull/41780#discussion_r3685675938
##########
superset/views/core.py:
##########
@@ -919,7 +927,7 @@ def fetch_datasource_metadata(self) -> FlaskResponse:
@expose("/language_pack/<lang>/")
def language_pack(self, lang: str) -> FlaskResponse:
# Only allow expected language formats like "en", "pt_BR", etc.
- if not re.match(r"^[a-z]{2,3}(_[A-Z]{2})?$", lang):
+ if not LANGUAGE_CODE_RE.match(lang):
abort(400, "Invalid language code")
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require support for locale formats that Superset does not ship in
its configured LANGUAGES or translation directories; the supported locales use
either a region suffix or a script suffix, not both.
**Applied to:**
- `superset/views/core.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
superset/translations/utils.py:
##########
@@ -24,9 +25,43 @@
# Global caching for JSON language packs
ALL_LANGUAGE_PACKS: dict[str, dict[str, Any]] = {"en": {}}
+# Global caching for language pack content hashes, used to build
+# content-addressed (cache-busting) asset URLs. A locale with no pack file
+# is cached as None so repeated requests don't re-stat the filesystem or
+# re-log the same warning.
+ALL_LANGUAGE_PACK_VERSIONS: dict[str, Optional[str]] = {}
+
DIR = os.path.dirname(os.path.abspath(__file__))
+def get_language_pack_filename(locale: str) -> str:
+ """Resolve the on-disk JSON pack for a locale (empty pack for English)"""
+ if not locale or locale == "en":
+ # Forcing a dummy, quasi-empty language pack for English since the file
+ # in the en directory contains data with empty mappings
+ return DIR + "/empty_language_pack.json"
+ return DIR + f"/{locale}/LC_MESSAGES/messages.json"
+
+
+def get_language_pack_version(locale: str) -> Optional[str]:
+ """Get/cache a short content hash of the language pack file
+
+ The hash is embedded in the pack's asset URL so browsers can cache it
+ as immutable and pick up a fresh copy whenever translations change.
+ Returns None when the pack file cannot be read.
+ """
+ if locale in ALL_LANGUAGE_PACK_VERSIONS:
+ return ALL_LANGUAGE_PACK_VERSIONS[locale]
+ try:
+ with open(get_language_pack_filename(locale), "rb") as f:
+ version = hashlib.sha256(f.read()).hexdigest()[:12]
+ except OSError:
+ logger.warning("No language pack file to version for locale %s",
locale)
+ version = None
+ ALL_LANGUAGE_PACK_VERSIONS[locale] = version
+ return version
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag the lack of runtime cache invalidation for translation
catalogs; they are release-time build artifacts that do not change during a
worker's lifetime and are refreshed on redeploy.
**Applied to:**
- `superset/translations/utils.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]