Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
131 stars 33 forks source link

Add i18next guard #105

Open kfrancois opened 1 year ago

kfrancois commented 1 year ago

Summary

The experience of using

data: { i18nextNamespaces: ['...'] },
resolve: { i18next: I18NEXT_NAMESPACE_RESOLVER },

Is slightly brittle, as it's easy to forget I18NEXT_NAMESPACE_RESOLVER. Although easy to catch manually in development, it's hard to protect against regression during refactoring.

In our repo we added a helper to move this to a (functional) guard. This guard basically reimplements the i18nextNamespaceResolverFactory while adding the functionality of blocking navigation while namespaces are loading.

Example

Before

{
  path: 'rich_form',
  loadChildren: () => RichFormFeatureModule,
  data: { i18nextNamespaces: ['feature.rich_form'] },
  resolve: { i18next: I18NEXT_NAMESPACE_RESOLVER },
},

After

{
  path: 'rich_form',
  loadChildren: () => RichFormFeatureModule,
  canActivate: [i18NextNamespacesGuard('feature.rich_form')],
},
Romanchuk commented 1 year ago

@kfrancois Hi! Thank you for PR. Interesting idea. I should deep dive to it. Could you update your fork from master? I can't say right now... we might need both guard and resolver. But if we keep resolver - we need to make it also functional since Angular deprecated currently implemented resolver behavior