Fix Winter.Translate default locale detection in the menu item editor - #55
Conversation
The editor located the active ML control with [data-control="multilingual"], an attribute only the mlurl widget renders. Winter.Translate turns the menu item's `title` and `url` fields into mltext (data-control="mltext"), so in the Static Menus popup the selector matched nothing and `defaultLocale` was undefined. As a result the RLTranslate[<default>][...] data lockers were never populated, and the item's own properties were read from whichever locale happened to be active - switching the locale back and forth wiped the title. Select on [data-default-locale] instead: all nine ML widget partials carry it. Scope the lookup to the popup container while we're here. Also pass the real $popupContainer in loadProperties(). That method has no `self` in scope, so `self.$popupContainer` resolved to the global `window.self` and the lookups silently fell back to a document-wide search. Fixes wintercms/wn-translate-plugin#120 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe menu item editor now reads the default locale from the active popup container in Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This change corrects locale detection and popup scoping in the menu item editor so default-language titles are preserved when switching locales; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Linked Issues checkExplanation The changes address issue Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #56 — the issue is filed on Winter.Translate, but the broken code lives here.
Problem
With Winter.Translate installed, editing a Static Menu item and switching the locale back and forth blanks the title, and the default locale's hidden data locker is never filled in.
menu-items-editor.jslocates the active ML control in three places with:data-control="multilingual"is only rendered by Winter.Translate's mlurl widget.EventRegistry::registerMenuItemTranslation()turns the menu item'stitleandurlinto mltext, whose root element isdata-control="mltext". So inside the Static Menus popup that selector matches nothing anddefaultLocaleisundefined, which silently disables all three code paths:loadProperties()never copies the item's owntitleintoRLTranslate[<default>][title], so the default locale locker stays empty;applyMenuItem()never reads the default locale back, so the item'stitleis taken from whatever locale is active at the time;select[name=reference]handler never seeds the default locale locker with the auto-filled title.Observed on a site with default locale
nl-BE, item title "Maatkasten",en→ "Our closets",fr-BE→ "Nos armoires":Applying the popup while a non-default locale was active then wrote that locale's title (or an empty one) into the item's
titleproperty.Fix
Select on
[data-default-locale]instead — all nine of Winter.Translate's ML widget partials carry that attribute, so this works whichever ML control the field was replaced with — and scope the lookup to the popup container.loadProperties()also gets the real$popupContainerpassed to it: that method has noselfin scope, soself.$popupContainerwas resolving to the globalwindow.selfand the lookups were silently falling back to a document-wide search.Testing
Same menu item, after the change:
Applying the popup with
enactive now keepstitle: "Maatkasten"and leavesviewBag.localeintact.Verified against Winter.Translate
dev-main, Winter 1.2, PHP 8.4.Summary by CodeRabbit