GithubHelp home page GithubHelp logo

Comments (5)

DarkLiKally avatar DarkLiKally commented on August 23, 2024 1

Hello @metoule,

you're right, that seems a bit complicated, I'll put it on my list to add configuration methods to access translator and other plugins directly. Thanks for the report!

Maybe for now you can use the following workaround, adding the callback inside the Configure method of your Startup class. This should work without problems because by default the services are registered as Singletons.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.ApplicationServices.GetService<ITranslator>().MissingKey += (sender, args) => 
    {
        Console.WriteLine("Missing key: " + args.Key);
    };
    // ...
}

from i18next.net.

DarkLiKally avatar DarkLiKally commented on August 23, 2024

Hello PhotoAtomic,

currently there's no support for those features in the library that's correct.
It's very busy in my life right now, so maybe if you could help me with development that would be very nice!
Thanks for your response and I'm really sorry for the late response on your issue. Had too much things going on over the last months.

from i18next.net.

DarkLiKally avatar DarkLiKally commented on August 23, 2024

@PhotoAtomic The next release (scheduled later today) will include an event on the translator (MissingKey) which will get fired when the key could not be resolved from the backend for the main language. You then could capture that event and update your data source with the missing keys.
The event args also include a property PossibleKeys with variations for context and counts when relevant arguments are included in the translation call.

You can access it by i18next.Translator.MissingKey

from i18next.net.

metoule avatar metoule commented on August 23, 2024

Could you provide an example on how to setup the event handler when using ASP.NET Core? For now, I'm using the following code, but it requires to know how to create a translator, which is a bit complex and might change in future releases:

services
    .AddI18NextLocalization(i18n => i18n
        .Configure(o => o.DetectLanguageOnEachTranslation = true)
        .AddInterpolator<HtmlInterpolator>()
        .AddTranslator(c =>
        {
            var backend = c.GetRequiredService<ITranslationBackend>();
            var logger = c.GetRequiredService<ILogger>();
            var pluralResolver = c.GetRequiredService<IPluralResolver>();
            var interpolator = c.GetRequiredService<IInterpolator>();
            var postProcessors = c.GetRequiredService<IEnumerable<IPostProcessor>>();

            var instance = new DefaultTranslator(backend, logger, pluralResolver, interpolator);
            instance.MissingKey += (obj, evt) => {
                // TODO handle event
            };

            instance.PostProcessors.AddRange(postProcessors);
            return instance;
        })
    )
    .AddMvc()
    .AddI18NextViewLocalization()
    ;

from i18next.net.

DarkLiKally avatar DarkLiKally commented on August 23, 2024

@metoule
I've added a new plugin type IMissingKeyHandler. You can create your own implementation of it and add it like any other plugin .AddMissingKeyHandler<MyCustomMissingKeyHandler>(). This way you also get dependency injection for your handler.

The new version is still not published on nuget. I have to do some more work on other parts of the library and maybe add a few more features today evening.

I'll play around myself a bit more with the missing key handlers and if they're stable I'll schedule a new version for today or tomorrow.

Also I'm working on a bit more documentation starting with xml doc comments and then I'll continue with some git wiki pages.

from i18next.net.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.