formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.

Home Page:https://formatjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass files to ignore to formatjs/cli

donovanhiland opened this issue · comments

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

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

We'll add support for ignore soon :)

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 👍

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

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