Fix #6101 : add locale prop and Config.plotly_locale for i18n chart formatting#6193
Fix #6101 : add locale prop and Config.plotly_locale for i18n chart formatting#6193pranavmanglik wants to merge 0 commit intoreflex-dev:mainfrom
Conversation
|
Here, if you are using |
Greptile SummaryThis PR adds i18n locale support to Confidence Score: 5/5Safe to merge; the only remaining finding is an edge-case spread-order issue that only surfaces if a caller simultaneously sets both All P0/P1 concerns from prior review rounds (production 404s, path traversal, cache race conditions, subclass rendering) have been addressed. The one new P2 finding (mergedConfig spread order) only matters when a caller provides conflicting locale settings via two different props at once, which is not a realistic usage pattern. reflex/components/plotly/plotly.py — specifically the Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Reflex App
participant RxPlot as _RxPlotLocale
participant Cache as _rxLocaleCache
participant CDN as jsDelivr CDN
participant Plotly as Plotly.js
App->>RxPlot: render(locale="de", config={...})
RxPlot->>RxPlot: useState(localeData=null)
RxPlot->>RxPlot: useEffect — locale changed
alt locale is empty string
RxPlot->>Plotly: createElement(PlotComponent, {config})
else locale is set
RxPlot->>Cache: _rxLocaleCache["de"]?
alt already cached
Cache-->>RxPlot: return existing Promise
else not cached
RxPlot->>CDN: fetch(.../plotly.js-locales/de.js)
CDN-->>RxPlot: CJS locale script text
RxPlot->>RxPlot: new Function sandbox eval
RxPlot->>Cache: store Promise
end
RxPlot->>RxPlot: setLocaleData(localeObj)
RxPlot->>Plotly: createElement(PlotComponent, {config: merged})
end
Plotly-->>App: chart rendered with i18n locale
Reviews (4): Last reviewed commit: "fix(plotly): revert is_default=False reg..." | Re-trigger Greptile |
feat(plotly): add
localeprop andConfig.plotly_localefor i18n chart formattingAll Submissions:
Type of change
New Feature Submission:
Changes To Core Features:
Summary
Adds a
localeprop torx.plotly(and all plotly subcomponents) so that charts automatically follow user language and regional formatting — number separators, date axis labels, month/weekday names, and modebar button tooltips. Also addsplotly_localetorx.Configas an app-wide default.Problem
rx.plotlyhad no way to configure the Plotly.js locale. All charts rendered withen-USdefaults regardless of the user's language — decimal separators, date axis tick labels, month/weekday names, and modebar button tooltips were always in English with no first-class Reflex API to change this.Developers targeting non-English audiences had to ship their own JS shims to work around this.
Usage
Per-chart
locale=takes precedence overConfig.plotly_locale. If neither is set, Plotly's built-in"en"defaults apply — zero behaviour change for existing apps.Test results
Manually verified with
locale="de"andlocale="zh-CN"usingreflex run. Confirmed German modebar tooltips ("Hineinzoomen", "Graphen als PNG herunterladen") and Chinese tooltips rendering correctly. Default chart (no locale set) behaviour is unchanged.Supported locales
~70 locales from
# feat(plotly): add `locale` prop and `Config.plotly_locale` for i18n chart formattingplotly.js-locales(MIT licensed), including:af,ar,bg,cs,da,de,de-ch,el,es,es-ar,et,fa,fi,fr,fr-ch,he,hi-in,hr,hu,id,it,ja,ko,lt,lv,nl,no,pl,pt-br,pt-pt,ro,ru,sk,sl,sr,sv,th,tr,uk,vi,zh-cn,zh-hk,zh-twand more.All Submissions:
Type of change
New Feature Submission:
Changes To Core Features:
Fix #6101