Comments (5)
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.
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.
@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.
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.
@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)
- Example of use in desktop application HOT 2
- Ready for production? HOT 3
- Split up language files HOT 1
- Lazy loading from API HOT 1
- CurrentCulture vs CurrentUICulture HOT 1
- Pluralization and fallback languages
- Is the library still maintained? What are the plans for the future? HOT 1
- Feature Request: Implement Namespace fallback HOT 2
- Check whether the value is already an IDictionary<string, object> HOT 2
- Feature Request: Write Log entries (or remove ILogger interface) HOT 1
- When translation uses language detection on each translation, the detected language is ignored
- Provide consistently ConfigureAwait(false) for UI thread in Blazor
- TranslationTree.GetAllValues() doesn't include parent key paths
- Allow customization on localization files findings HOT 1
- Problem with JsonFileBackend usage: Unable to retrieve translated values
- Pluralization and JSON v4 HOT 2
- Add support for fallback language and namespace. HOT 9
- NullReferenceException when using ThreadLanguageDetector and Accept-Language header is not present HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18next.net.