Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Localization manager with more than one resource manager #832

@WebDucer

Description

@WebDucer

Summary

Currently the localization manager (singleton) can be initialized only with one resource manager. This is often not enough.

We ceurrently use own implementation for this purpose, that accept a list of resource managers (form common library, different app modules).

API Changes

Non breaking changes:

ResourceManager[] resourceManagers = new ResourceManager[0];

public void Init(ResourceManager resource) =>
resourceManager = resource;
public void Init(ResourceManager resource, CultureInfo initialCulture)
{
resourceManager = resource;
currentCulture = initialCulture;
}

public void Init(params ResourceManager[] resources) =>
    resourceManagers = resources;

public void Init(ResourceManager resource, CultureInfo initialCulture)=>
    Init(initialCulture, resource);

public void Init(CultureInfo initialCulture, params ResourceManager[] resources)
{
    resourceManagers = resources;
    currentCulture = initialCulture;
}

public string GetValue(string text) =>
resourceManager.GetString(text, CurrentCulture);

public string GetValue(string text)
{
    string translated = null;

    foreach (var rm in resourceManagers)
    {
        translated = rm.GetString(text, CurrentCulture);
        if (translated != null)
        {
            break;
        }
    }

    return translated;
    // Or as LINQ
    // return resourceManagers.Select(s => s.GetString(text, CurrentCulture))
    //    .FirstOrDefault(f => f != null);
}

Intended Use Case

Usage with more than one resource manager.

Who Will Do The Work?

  • I am willing to take this on myself
  • Just putting this out there for someone to pick up

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA request for a new feature.needs-approvalFeature request has been submitted but is awaiting final approval. Please do not implement before!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions