Hi, First many thanks for your work is this beautiful nuget package. I use it in 2 projects and it makes me win a lot of time.
I'm a French developer, and some component like File or DataGrid have some text that comes by default (browse for the file, pagination text for DataGrid).
Do you have already a solution to translate the text or planned to make on update to allow change the text of the components ?
If you don't already have the solution, the solution is to be able to change the text or to update the template to be able to change the text.


You can use CaptionTemplate to handle the column header of DataGrid. But for other components like FileEdit, I still don't have a good approach.
I have already implemented localization for Validation component messages and I will slowly do other components too. That's something I plan to work on soon.
Ok. I will have a look to CaptionTemplate. thanks
Same problem with Pagination in DataGrids in a german web app. Tanslation feature for componentes would be very nice :)

Is there an option to change First and Prev Button Caption without customizing the whole pagination element?
@Riedi2070 Not at the moment. But it's planned to be done soon.
Hello to everyone in this conversation. I'm currently working on a localization feature and I'm kinda stuck on which way to proceed.
My first idea was to use IStringLocalizer(docs). So far it works OK. But, the first problem with this solution is that I would need to add a package Microsoft.Extensions.Localization. Also, I would need to include embedded resources for every language. It's not a problem for a few languages but it can grow over time and it's not easy to configure. With this solution, the final Blazor app can be around 140KB larger which is kinda OK.
My next idea is to create IComponentLocalizer, which looks like this:
public interface IComponentLocalizer
{
string GetText( string key );
string this[string key, string defaultText]
{
get;
}
}
With this interface, I can create a default implementation that will return some texts from a dictionary. The good thing is that anyone can override their own implementation of IComponentLocalizer.
So, do you guys think any of this is good? Or have an idea for a better solution? Thanks
It would be better to stay with IStringLocalizer as that would stay inline with Microsoft implementation? I suppose if you include support one for two languages with the ability for people to add further resource files as per their need?
@araknusc Yes, that was my first idea. But it's not very flexible. It also requires more configurations on application startup(setting culture info for DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture). Not to mention that dynamically changing culture info also requires to restart the app. While doable I don't like all of the stuff that comes with it.
yes, that is correct. The setup required is not easy to figure out with IStringLocalizer. I spent the whole day yesterday to get it working on my Blazor Wasm App. But after spending that time I find future management quite easy especially because there are quite a few resx maintenance tools. If the Blazor Wasm App already uses the resx implementation then maintaining another interface requires having the texts maintained in two places sometimes. But let's see what others say :).
The same thing for me also. If it takes that long to even start using something, it's a red flag for me. It should have to be a lot easier. Anyways, as you said, let's see what others got to say.
Idea 1 "is not easy to set up" is a red flag.
I prefer Idea 2, just because it is simple and as you said, we can override it.
Guys, a little overview of what I did so far. I have tried to use IStringLocalizer but whatever I did I couldn't make it work in WebAssembly project. I wanted to be able to change the language in runtime. As far as I know, this is currently not possible because IStringLocalizer caches everything on application start and can't refresh later on. If someone knows better please let me know.
ITextLocalizerSo considering all the problems with IStringLocalizer I have decided to create a custom ITextLocalizer. The usage is the same as IStringLocalizer, eg. Localizer["Choose files"].
ITextLocalizer:AddLanguageResourceIStringLocalizerITextLocalizerService:Along with ITextLocalizer I also created ITextLocalizerService that is used to change the current culture and notify the app components that culture has changed.
ITextLocalizerService:[Inject] ITextLocalizerService LocalizationService { get; set; }
protected override async Task OnInitializedAsync()
{
await SelectCulture( "en-US" );
await base.OnInitializedAsync();
}
Task SelectCulture( string name )
{
LocalizationService.ChangeLanguage( name );
return Task.CompletedTask;
}
Obviously, if anyone still wishes to use IStringLocalizer they can just implement their own ITextLocalizer and register it with dependency injection.
One last thing that I want to add is to have maybe LocalizationText parameter on a Blazorise component so that for example we can have:
<FileEdit LocalizationText="My custom browse button" />
Once LocalizationText is defined it will have priority over ITextLocalizer.
So, what you guys think?
Most helpful comment
@Riedi2070 Not at the moment. But it's planned to be done soon.