laget-se / narp

A workflow utility to ease localization in JS(X) apps
Apache License 2.0
13 stars 1 forks source link

Supports react-gettext-parser's trimming options #6

Closed alexanderwallin closed 6 years ago

alexanderwallin commented 6 years ago

It's now possible to specify the trim, trimLines and trimNewlines configs in .narprc.

If you fancy an example of the mighty evil of mutability, https://github.com/laget-se/narp/commit/3e853d4f9a287c372c545d175dadb8130c2338fb is a treat.

ridderholt commented 6 years ago

@alexanderwallin Do we change any default behavior for narp by merging this PR?

alexanderwallin commented 6 years ago

I tried to think of a scenario where we would, but couldn't come up with any. I guess if you've done some wacko stuff like:

// .narprc
{
  "extract": {
    "componentPropsMap": {
      "crayCray": "That is magically added to react-gettext-parser's defaults"
    }
  }
}

// my-script.js
const narp = require('narp')
const { GETTEXT_COMPONENT_PROPS_MAP } = require('react-gettext-parser')

// Run narp here
narp.push()

// Then depend on the contents of the react-gettext-parser defaults
for (const componentName in Object.keys(GETTEXT_COMPONENT_PROPS_MAP)) {
  // This will try to require path/to/components/crayCray.js
  const ComponentClass = require(`path/to/components/${componentName}.js`)
}

then it's gonna blow. But then you also had it coming. :)

ridderholt commented 6 years ago

@alexanderwallin Cool, do we need to do something in package.json to use the new version of react-gettext-parser that supports these features?

alexanderwallin commented 6 years ago

Yes, good catch! It's been updated now.