-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blazor-Server] Ability to change renderer's Culture on each component #35965
Comments
@javiercampos it's likely that addressing #28521 (which should ensure persisting the culture across InvokeAsync calls) should help here? |
Actually, pretty much. That issue (the issue itself) looks like a much simpler explanation, but the underlying issue is the same and more than likely solving that would solve my issue. Incidentally, I'd prefer the issue to be solved with the "other" suggestion (having a ILocalizedComponent or similar), but the way that linked issue would be solved would also work, definitely |
Thanks @javiercampos closing this as dup of #28521. |
Is your feature request related to a problem? Please describe.
I want to be able to set the renderer's Culture on each component. Currently, by default, when rendering, the component gets rendered with the
CurrentUICulture
that was on the thread that created the actual renderer.This is fine if you have (as the documentation shows for localizing) one culture per http-request (or circuit) and don't change it during the lifetime of the circuit, but as soon as you want to dynamically change a component's culture, you just cannot.
An example of why this came to be is here: https://stackoverflow.com/questions/68987835/guaranteeing-currentuiculture-across-invokeasync-invocations
And an example of how changing it doesn't affect the component's rendering at all if done on an
InvokeAsync
(using the synchronization context) is here: https://gist.github.com/javiercampos/1152da404c3004d7fbaac8e503425e4aThis forces us to have a different
CultureInfo
object, which would not be a problem, but definitely forces you to use.ToString(Culture)
on the template or@bind-X:culture="@Culture"
on all two-way bindings. Which is easy to forget.Add to that, that most third-party components don't really care about doing so, so having the renderer do it would be great.
Describe the solution you'd like
Be able to specify the component's culture for the renderer in some manner.
My proposed implementations of this solution could be one of either:
RendererSynchronizationContext
, so if you doInvokeAsync(() => CultureInfo.CurrentUICulture = something)
, it'll flow it to the rest of the invocations on the context.IComponent
implement aCultureInfo
getter, or, if you don't want to break existing code, make an optionalILocalizedComponent
which has it, and the renderer understands, so if it finds it when rendering, it'll change the culture for the rendering phase), possibly changing it on ComponentState by checking if the component is anILocalizedComponent
But those are just ideas, since I'm not 100% sure how the rendering is actually implemented in Blazor
The text was updated successfully, but these errors were encountered: