Use dots in resource names
Closed this issue ยท 10 comments
It seems it's not possible to use dots in resource names because of the way the Path
is parsed (here) and because of the brackets dynamically added here.
We have a project where the resource files are generated and contain lots of dots, so I'm looking for a way to use the LocalizationResourceManager
but so far not much luck.
I found a way by referencing the entire LocalizationResourceManager.Maui
project, reference my text resources using underscores instead of dots, and finally replace those underscores by dots programmatically with a text.Replace('_', '.')
here.
I'm sure there must be a better way?
Thanks!
I have forked the project so I could commit a minor change and use that fork as submodule in my main project.
Please do let me know if you decide to incorporate it into your main so that I could simply reference the nuget in my main project instead of having a submodule that is a fork of this ;)
https://github.com/sebdesalvador/LocalizationResourceManager.Maui
Cheers!
@sebdesalvador, interesting! I will look into this and come back to you!
- LocalizedString can be used to handle this, but it is only useful for a limited number of texts.
- Out of curiosity, why are there dots in the names?
Cheers!
A sort of path/namespace like system was adopted early in the project, so our resource keys look like project.web.page1.title
๐
@sebdesalvador , I been thinking how to best implement this and came up with a solution where you can activate/opt in to support name with dots by calling SupportNameWithDots
when configuring library with option to set custom replacement text.
.UseLocalizationResourceManager(settings =>
{
settings.AddResource(AppResources.ResourceManager);
settings.RestoreLatestCulture(true);
settings.SupportNameWithDots();
});
See my Support_Name_With_Dots
branch: HERE!
What do you think!?
Hi @SirJohnK, looks real good, just a minor comment, I have favoured a double underscore as substitution, just in case I did have a simple one in a resource name ;)
You have the option to set your own substitution when configuring this:
.UseLocalizationResourceManager(settings =>
{
settings.AddResource(AppResources.ResourceManager);
settings.RestoreLatestCulture(true);
settings.SupportNameWithDots("__");
});
Will soon release this in a new version! I make a shoutout when done! ;)
Perfect!
Thanks for your quick reaction to my issue ๐
Happy to help! :)