formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

Pass files to ignore to formatjs/cli #562

Closed donovanhiland closed 4 years ago

donovanhiland commented 4 years ago

Which package? @formatjs/cli & babel-plugin-react-intl

Is your feature request related to a problem? Please describe. I would like to 1. ignore test files and 2. auto generate ids if they're not provided. Currently I can't figure out how to extract translations from all ts and tsx files in a directory minus __tests__ and *.test.*. No amount of file glob variations have worked for me.

I can get this to work if I use the babel plugin directly and --ignore those files. But in this case I have to wire up the id generation manually.

Describe the solution you'd like It would be nice to be able to --ignore files (pass files to the babel plugin to be ignored) from @formatjs/cli.

Describe alternatives you've considered Maybe I'm looking in the wrong place and there's a file glob that would work that I haven't tried yet. Open to suggestions there

longlho commented 4 years ago

--id-interpolation-pattern should allow you to specify the ID if they're not there.

We'll add support for ignore soon :)

donovanhiland commented 4 years ago

Great thanks for the reply! The ID interpolation is working great using @formatjs/cli. I need the ignore functionality so I went with the babel plugin directly which looks like this to mimic the cli's functionality:

const { interpolateName } = require('loader-utils')

module.exports = {
  ...
  plugins: [
    [
      'react-intl',
      {
        ...
        overrideIdFn: (id, defaultMessage, description) =>
          id ||
          interpolateName({ resourcePath: 'dummy' }, '[contenthash:5]', {
            content: `${defaultMessage}#${description}`,
          }),
      },
    ],
  ],
}

Looking forward to ignore support 👍

donovanhiland commented 4 years ago

I would be happy to make a contribution and work on this if it would help

longlho commented 4 years ago

yeah it should be pretty simple, we can expose ignore in the CLI and pass it into here. PR's always welcome 😄