Skip to content
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

Add a Culture parameter on components for the default templates #206

Closed
javiercampos opened this issue Aug 31, 2021 · 5 comments
Closed

Comments

@javiercampos
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When changing the Cutlure dynamically on a page (without reloading, thus, without changing the renderer thread's CurrentCulture/CurrentUICulture), you cannot reliably change the renderer's synchronization context Culture, so async calls (or InvokeAsync()) may have a different Culture.

I've made a feature request for Blazor to include this capability here: dotnet/aspnetcore#35965

When you show the value or make binding yourself in the template you can use .ToString(MyCulture) or @bind-Value:culture="@MyCulture" if needed, but components like the RadzenDataGrid, or RadzenDropdown, etc., where you don't bind directly (instead, you specify a type and a property name), always use the thread's culture on their default templates, so if you want a different culture, you need to specify the whole Template for every column, or dropdown template, etc., which is really inconvenient.

Describe the solution you'd like
Have a parameter on those components of type CultureInfo to specify the default culture on the component, e.g.: <RadzenDataGrid Culture="@MyCulture">, so that it takes it into account in the default templates (and it does .ToString(Culture) when rendering, instead of just ToString() -or nothing, which calls ToString with the CurrentUICulture format provider).

It could use CultureInfo.CurrentUICulture if not specified, so it would not break any existing code.

Additionally, default in-component templates for reflection-based rendered components (where you specify the type and the property name, instead of binding directly) would need to be revised to make use of that parameter.

@akorchev
Copy link
Collaborator

I think we won't implement this as there are supported ways to change the current culture in an ASP.NET Core application which work. Yes they require a reload but this is not such a big problem.

The Startup.cs file of the Sample application contains commented code which can be used to set the current application culture.

I have linked a screenshot showing this in action in this comment: #229 (comment)

@akorchev akorchev reopened this Sep 27, 2021
@akorchev
Copy link
Collaborator

This turned out to be a problem when certain conditions are met (static classes and events - more here. We are reopening the issue and will accept pull requests.

@javiercampos
Copy link
Contributor Author

Thanks, I'll try to work on a PR, but can't make promises with the timeframe.

Would it be ok, if, apart from a Culture parameter I add a DefaultCulture cascading parameter? That way you could optionally set up a cascading value provider that would provide the culture to all descendant radzen components without having to specify it on each individual component (while you could also set the Culture individually on any component, should you wish to do that).

@akorchev
Copy link
Collaborator

Would it be ok, if, apart from a Culture parameter I add a DefaultCulture cascading parameter?

If it is not too much of a hassle - why not. It would probably require another property though ...

[Parameter]
public CultureInfo Culture { get; set; }

[CascadingParameter]
public CultureInfo DefaultCulture { get; set; }

CultureInfo CurrentCulture => Culture ?? DefaultCulture ?? CultureInfo.CurrentCulture;

@javiercampos
Copy link
Contributor Author

javiercampos commented Sep 27, 2021

@akorchev I've made a PR. Sorry but I don't typically contribute code to OSS and I'm not sure the guidelines for making one and if that's correct. If you want me to review or test anything (I've just ran the tests as they were), please tell me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants