CommunityToolkit / CommunityToolkit/dotnet

[Proposal] LocalizationResourceManager

Open
#312 25 comments 3 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail: needs triage :mag:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

# LocalizationResourceManager

* [x] Proposed
* [x] Prototype: Not Started
* [ ] Implementation: Not Started
* [ ] iOS Support
* [ ] Android Support
* [ ] macOS Support
* [ ] Windows Support
* [ ] Unit Tests: Not Started
* [ ] Sample: Not Started
* [ ] Documentation: Not Started

## Summary
[summary]: #summary

The LocalizationResourceManager class is a helper class that enables users to respond to culture changes at runtime.

## Detailed Design
[design]: #detailed-design

### LocalizationResourceManager.shared.cs

```cs
public class LocalizationResourceManager : INotifyPropertyChanged
{
public static LocalizationResourceManager Current;

private LocalizationResourceManager();

public void Init(ResourceManager resource);
public void Init(ResourceManager resource, CultureInfo initialCulture);
public object GetValue(string resourceKey);

public object this[string resourceKey] => GetValue(resourceKey);

public CultureInfo CurrentCulture { get; set; }
}
```

## Usage Syntax
[usage]: #usage-syntax

### XAML Usage

N/A

### C# Usage

```cs
LocalizationResourceManager.Current.PropertyChanged += (_, _) => AppResources.Culture = LocalizationResourceManager.Current.CurrentCulture;
LocalizationResourceManager.Current.Init(AppResources.ResourceManager);

LocalizationResourceManager.Current.CurrentCulture = newCulture;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.