-
Notifications
You must be signed in to change notification settings - Fork 459
[Enhancement] Support for more than one resource manager #1047
Conversation
@pictos @brminnick @jfversluis Could you please take a look at this? |
@brminnick I know, you wanted to remove backing field for culture from public CultureInfo CurrentCulture
{
get => CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.DefaultThreadCurrentCulture;
set
{
if (CurrentCulture == value)
{
return;
}
CultureInfo.DefaultThreadCurrentUICulture = value;
CultureInfo.DefaultThreadCurrentCulture = value;
OnPropertyChanged(nameof(CurrentCulture));
}
} Works on Android, but doesn't work on UWP (cannot test on iOS). Looks like resource managers in UWP get their default culture from some other place than |
@maxkoshevoi right now we are focused in um merge the nullable PR asap. So we will review this one right after the nullable is merged (: |
@pictos Sounds great! I just had some spare time, so implemented this one. |
@maxkoshevoi, can you rebase your PR against develop? |
@AndreiMisiukevich Could you please assign @brminnick as a reviewer here? |
@maxkoshevoi done) |
FYI - this introduces a breaking change by modifying the constructor of This should be merged into a major release, e.g. v2.0.0 |
Since this PR already introduces a breaking change, we can also break the Obsolete methods that have been released in previous versions
This reverts commit e57e9c1.
@brminnick It seems like there won't be 2.0.0 considering XCT stops accepting new features in September 2021. Should this PR be merged in 1.3.0 (if approved), transferred to |
Thanks! However, we are no longer adding new features to Xamarin Community Toolkit, focusing on the .NET MAUI Community Toolkit. I've posted more information about the Future Of Xamarin Community Toolkit here: https://devblogs.microsoft.com/xamarin/the-future-of-xamarin-community-toolkit/?WT.mc_id=mobile-0000-bramin |
Description of Change
We use two classes to get localized values at runtime:
TranslateExtesion
andLocalizedString
.LocalizedString
doesn't store or reference anyResourceManager
, so it basically already supports more then one.TranslateExtesion
Always usesResourceManager
fromLocalizationResourceManager
, so this needs to change.What was done
ResourceManager
parameter toTranslateExtesion
, so that user could specifyResourceManager
for each string. If none is specified,LocalizationResourceManager.DefaultResourceManager
is used.resourceManager
inLocalizationResourceManager
toDefaultResourceManager
and made it readonly and internal (so thatTranslateExtesion
could read it).GetString
fromLocalizationResourceManager
(as suggested by @brminnick here) They were only needed to be used inTranslateExtesion
, and now it no longer uses them.Alternative implementations
DefaultResourceManager
can be moved toTranslateExtesion
as nothing else uses it. But then users will need to initializeTranslateExtesion
as well asLRM
Bugs Fixed
API Changes
Added:
ResourceManager TranslateExtension.ResourceManager { get; set; } = LocalizationResourceManager.Current.DefaultResourceManager
void LocalizationResourceManager.Init(CultureInfo initialCulture);
(since passing resource manager is no longer mandatory)Changed:
void LocalizationResourceManager.Init(ResourceManager resource)
=>void LocalizationResourceManager.Init(ResourceManager defaultResourceManager)
(renamed parameter)Removed:
string LocalizationResourceManager.GetValue(string text)
string LocalizationResourceManager.this[string text]
LocalizedString(LocalizationResourceManager localizationManager, Func<string> generator = null)
(user cannot create new instances ofLRM
, so this constructor doesn't make sense)Behavioral Changes
User can now pass any resource manager in
TranslateExstension
Breaking Changes
GetValue
fromLRM
, but they shouldn't be used anyway. And I can bring them back if needed. Their removal is not critical to this PR.resource
parameter todefaultResourceManager
.PR Checklist