Skip to content

Export default core methods #84

@jkomusin

Description

@jkomusin

Hi there, what are your thoughts on exposing the default core methods for use in overriding hooks in manageTranslations? I'd like to be able to augment the default functionality with some of my own pre- or post- behavior, or in some cases overriding it entirely. For example, I'd like to be able to:

import manageTranslations, {
  provideWhitelistFile
} from 'react-intl-translations-manager';

manageTranslations({
  messagesDirectory: 'src/messages/
  translationsDirectory: 'src/translations/',
  languages: ['fr-ca'],
  overrideCoreMethods: {
    provideWhitelistFile: (lang, options) => {
      // Decide whether to do something here
      if (foo === bar) {
        return baz;
      } else {
        // Otherwise do the default thing
        return provideWhitelistFile(lang, options);
      }
    }
  }
});

The API for them would need to change slightly to accept the options that were passed into manageTranslations instead of being closures around the options within manageTranslations itself.

I haven't attempted this yet, but am interested in your appetite for considering such a change. The nice part is that the changes should be backwards compatible: any existing overridden hooks in the wild would already be standalone and ignore the new additional options argument. It would also make these core methods more testable, which could fill the gap in testing around manageTranslations itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions