'ABP: Rebuilding Localization Sources from Custom Provider

I am using ABP v4.9.0 (.NET CORE 2.2) with angular client

I built some custom localization providers. These providers get translation dictionaries from an external API. I add localization sources on startup with these providers.

            var customProvider = new CustomLocalizationProvider(...);


            var localizationSource = new DictionaryBasedLocalizationSource("SOURCENAME", customProvider );
            config.Localization.Sources.Add(localizationSource );

On startup, the providers InitializeDictionaries() is called and localization dictionaries are built. So far, so good, working as intended.

Now i'd like to manually Reload these translations on demand, but I can't make this working.

Here is what I tried.

Here I trigger the re-synchronize of the language ressources:

        foreach (var localizationSource in _localizationConfiguration.Sources)
        {
            try
            {
                localizationSource.Initialize(_localizationConfiguration, _iocResolver);
            }
            catch (Exception e)
            {
                Logger.Warn($"Could not get Localization Data for source '{localizationSource.Name}'", e);
            }
        }

In the custom provider, I first clear the Dictionaries

    public class CustomLocalizationProvider : LocalizationDictionaryProviderBase
    {

    protected int IterationNo = 0;

    protected override void InitializeDictionaries()
    {
        Dictionaries.Clear();

        IterationNo += 1;

        var deDict = new LocalizationDictionary(new CultureInfo("de-DE"));
        deDict["HelloWorld"] = $"Hallo Welt Nummer {IterationNo}";
        Dictionaries.Add("de-DE", deDict);

        var enDict = new LocalizationDictionary(new CultureInfo("en"));
        enDict["HelloWorld"] = $"Hello World number {IterationNo}";
        Dictionaries.Add("en", enDict);
    }

    }

The provider is executed again as expected.

But when I eventually use the localization clientside (angular), I still get the original translations.

What am I missing?

Thanks for the help.



Solution 1:[1]

In the meanwhile I had to go for another approach.

I am now using a XmlEmbeddedFileLocalizationDictionaryProvider wrapped by a MultiTenantLocalizationDictionaryProvider. This way, I am using db-localizations with xml-sources as fallback

Then I manually load the ressources from my API in some appservice. These localizations are then updated in the database by using LanguageTextManager.UpdateStringAsync().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RKRK