Support for onFailedLoading API
See original GitHub issue🚀 Feature Proposal
I would like to be able to register a callback to the onFailedLoading i18next event. We cannot use the global i18n instance to do this because .init()
is called before we are able to register the callback.
// _app.tsx
function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => {
function handleFailedLoading() {
logger.error('failed to load translations');
}
// This callback will never be called because the i18n instance
// has already attempted to load the translation data. The event
// would have already fired before this is registered.
i18n.on('failedLoading', handleFailedLoading);
return () => {
i18n.off('failedLoading', handleFailedLoading);
}
}, [])
//...
}
Motivation
We had a bug on our end that caused translations not to be loaded. We would like to be able to add logging/alerting when this happens.
Example
The example above already shows one way we might use this. I am guessing that next-i18next would need to provide some way in appWithTranslation
to allow us to hook into the time between when the i18n instance is created and when it is initialized. Maybe a third argument that takes a callback that is passed the i18n instance before init?
export default appWithTranslation(MyApp, null, (i18n) => {
i18n.on('failedLoading', handleFailedLoading)
});
Updating this
To something like this:
if (!instance.isInitialized) {
config?.use?.forEach(x => instance.use(x))
i18nCallback?.(instance)
initPromise = instance.init(config)
} else {
i18nCallback?.(instance)
initPromise = Promise.resolve(i18n.t)
}
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
API - i18next documentation
onFailedLoading. i18next.on('failedLoading', function(lng, ns, msg) {}). Gets fired if loading resources failed (after the in-built retry algorithm).
Read more >WebResourceLoadDelegate.OnFailedLoading ... - Microsoft Learn
WebResourceLoadDelegate.OnFailedLoading in the WebKit namespace. ... public virtual void OnFailedLoading (WebKit. ... Xamarin.Mac SDK, 14 ...
Read more >C# API reference - Unity Documentation
This method returns the version of the Unity Mediation SDK that is currently being used. ... OnFailedLoad, Execute logic for the ad failing...
Read more >.NET API Catalog
namespace WebKit { [Deprecated(PlatformName.MacOSX, 10, 14, PlatformArchitecture.None, "No longer supported.
Read more >How to implement a scalable support strategy for your API
Your team might be great at supporting your primary product, but know nothing about APIs. Building a specialized API support team. You might ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Usually, if there is the need of listening to failedLoading events or other custom api, there is also a backend plugin like i18next-http-backend in use… this means the config is unserializable anyway. btw: not only the appWithTranslation is affected, but also the serverSideTranslation call
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.
There are many ways to help this project 🙏