Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Benchmark Result: Default
Median of 10 attempts, 5000 iterations x 10 rounds, 10.7s total To run a specific benchmark, comment |
Contributor
|
@iruoy In real app, most of the views has translation so I'm not sure if skip folding is good solution. Skip folding for most of the views will affecting performance imo. |
Author
|
@ghabriel25 I agree it’s a workaround. I think working translations are worth the trade-off for now. It would help to know why #227 was reverted before revisiting that approach. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scenario
In an app with more than one locale, folded components show their translations in the locale of whichever request compiled the view first. That text is shown to everyone until
view:clear.The first request is in
nl, so the view compiles witharia-label="Zijbalk tonen of verbergen". A later request inenreuses the compiled view and still gets the Dutch label. A plain{{ __('Toggle sidebar') }}in the same template does follow the locale. 51 folded Flux views call__().The problem
Folding renders the component once, at compile time, and stores the HTML.
__()is evaluated during that render, and compiled views don't depend on the locale.#227 deferred each translation to a runtime call through placeholders, and was reverted. Adding
__(tocheckProblematicPatterns()would be simpler, but that check throws for every component that uses__(), which would break Flux. Checking the component's source wouldn't be enough either: a folded parent also renders its children at compile time, so a translation inside a child gets baked into the parent.The solution
While folding,
BladeRendererswaps the translator for aTranslationRecorder(withLang::swap(), as #227 did). The recorder passes every call through to the real translator and notes that a translation happened. If one did, the render throwsTranslatedWhileFoldingExceptiononce everything is restored, andFolderleaves the component unfolded. It's then compiled as usual and renders in the current locale.__(),trans(),trans_choice(),@lang,Lang::get()andLang::choice()are recorded. Other translator methods (has(),string(), …) are recorded through__call, since they depend on the locale too.InvalidBlazeFoldUsageException, and it doesn't throw in throw mode either. Otherwise every Flux component that translates would throw in throw mode, as Blaze's ownFluxTestmodal case shows.Tests: a component that translates and a folded parent of one both render in the current locale after the view has been compiled in another one. They aren't folded, even in throw mode. The translator is restored afterwards. The new tests fail on
mainand the full suite passes. I also checked it in a Laravel 13 app with Flux 2.22: rendered innlthenen, and the other way round,flux:sidebar.togglenow follows the locale. The README's "Global state" section has a sentence on it.Fixes #221
🤖 Generated with Claude Code