GitHub user sknoyon324234234234 added a comment to the discussion: An `msgid` 
with two meanings

This is a real gap, and gettext's standard answer (**`msgctxt`**, a translation 
context) is half-supported in Superset right now:

- **Backend:** fine. Python code can use flask_babel's `pgettext("context", 
"Open")` (it's already among the recognized gettext functions in the i18n 
tooling).
- **Frontend catalog:** also fine. `superset-frontend/scripts/po2json.js` 
explicitly keeps `msgctxt` entries, storing them under Jed's `context + 
"\u0004" + msgid` key, so a `.po` entry with `msgctxt "Candlestick"` survives 
the build.
- **Frontend lookup:** missing. `Translator.ts` 
(`superset-core/src/translation`) only exposes `translate()` and 
`translateWithNumber()`, both calling `this.i18n.translate(key)` without a 
context. So frontend code like the candlestick chart labels has no way to ask 
for the contextual entry, and "Open/High/Low/Close" share the generic msgid.

So the fix would be small and self-contained: add a context-aware helper, e.g.

```ts
translateWithContext(context: string, key: string, ...args: unknown[]) {
  return this.i18n.translate(key).withContext(context).fetch(...args);
}
```

export it alongside `t` (e.g. as `tct(context, key)`), and have the candlestick 
plugin use `tct('Candlestick', 'Open')` etc. The extraction config would also 
need to learn the new function name so `msgctxt` lands in the `.pot`.

Worth opening as an issue (or PR) referencing this. As a Japanese translator 
you're exactly the person who can show why it's needed.


GitHub link: 
https://github.com/apache/superset/discussions/45366#discussioncomment-18968582

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


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

Reply via email to