-
Notifications
You must be signed in to change notification settings - Fork 459
Avoid users to create new instances of the LocalizationResourceManager #770
Conversation
A new build for this PR has been completed. As a result a NuGet has been created which allows you to verify this fix or try out the new feature! Download here |
Also, we can minimize the breaks by adding this workaround public static LocalizationResourceManager Current { get; } = new LocalizationResourceManager(null);
LocalizationResourceManager(object obj)
{
}
[Obsolete("Please use the Current property instead of create a new instance of this class")]
[EditorBrowsable(EditorBrowsableState.Never)]
public LocalizationResourceManager()
{
} The good of the break is that we will |
Or just #pragma warning disable
public static LocalizationResourceManager Current { get; } = new LocalizationResourceManager();
#pragma warning restore
[Obsolete("Please use the Current property instead of create a new instance of this class")]
[EditorBrowsable(EditorBrowsableState.Never)]
public LocalizationResourceManager()
{
} |
@pictos but basically do you think that many people already use this class? |
@AndreiMisiukevich I have no idea, but we have more than 4k users, so if they need i18n on their apps, they can rely on our implementation and miss use it. If you look at this PR's issue, you can see that devs can miss understand it and create new instances per Yeah, your suggestion is better than mine, I'll push it. |
A new build for this PR has been completed. As a result a NuGet has been created which allows you to verify this fix or try out the new feature! Download here |
So just to be clear, this doesn't really break the users, right? This just obsoletes it and directs them to use something else?
|
src/CommunityToolkit/Xamarin.CommunityToolkit/Helpers/LocalizationResourceManager.shared.cs
Outdated
Show resolved
Hide resolved
…tionResourceManager.shared.cs Co-authored-by: Gerald Versluis <[email protected]>
@pictos could you update the description in the first comment to reflect this change? You're now talking about the private constructor which is not accurate anymore. Then merge away :) |
@pictos, @AndreiMisiukevich, @jfversluis Just to be clear, what should we do when user has multiple resource files? Like described in the issue linked to this PR. Do we just not support that scenario? Currently |
@maxkoshevoi do you know how that works in "normal" .NET/C# projects? |
@jfversluis in normal project if you have several resource files, you can reference each of them by name, and get localized resource strings from them: So normal projects allow for multiple resource files no problem. By restricting creation of |
@jfversluis There was a discussion here #769 (comment) you can see what I mean. BTW, I'm generating my |
@AmrAlSayed0 are you able to test your project with the nugget generated from this PR? |
@pictos No, I didn't see a way how I would be able to unless TranslateExtension is modified to take an instance of LocalizationResourceManager as a parameter or something (Maybe, optionally, in which case use .Current) And by the way, I should mention that I'm bringing this up because that is MY use case. I'm in no way blocking this PR. If you feel that the LocalizationResourceManager and TranslateExtenstion are ok as they are now and you got approved, go ahead and merge it. I just won't be able to use it. I already wrote something similar in my own app and I use XCT in my app so I thought I could just give up my poorly written implementation and use XCT's but this PR won't affect me very much, so feel free to do whatever. |
@AmrAlSayed0 if you have time to test it will be great because I can try to make it work on your scenario. I don't want to break any current user. If you are not able to test there is no problem I can try to implement something similar to test it. |
@pictos If |
@maxkoshevoi that could be a thing, I need to try out that first. The downside is that will add more complexity to the lib. |
@pictos One optional parameter for markup extension that only has two parameters shouldn't complicate things much, but it will allow people with more than one resource file to use our culture changing flow. |
Description of Change
Just marked the public constructor from LocalizationResourceManager (LRM) as obsolete and ask the users to access the instance using the
Current
property.Bugs Fixed
API Changes
Added:
[Obsolete] public LocalizationResourceManager();
Behavioral Changes
Users can create new instances of LRM but this is marked as obsolete
PR Checklist