Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract messages generated in another macro (preval/codegen) #81

Open
slorber opened this issue May 13, 2019 · 0 comments
Open

extract messages generated in another macro (preval/codegen) #81

slorber opened this issue May 13, 2019 · 0 comments

Comments

@slorber
Copy link

slorber commented May 13, 2019

Hi,

I am trying to figure out how to use your macro and preval so that we can generate dynamic translation keys.

By chance, do you know why the following does not work?

// @ts-ignore
import preval from 'preval.macro';

// @ts-ignore
import { defineMessages } from 'react-intl.macro';

const messages = defineMessages({
  'Component.greet1': {
    id: 'Component.greet1',
    defaultMessage: 'Hello, {name}!',
    description: 'Greeting to welcome the user to the app, v1',
  },
});

const generatedMessages = defineMessages(preval`module.exports = {
  'Component.greet2': {
    id: 'Component.greet2',
    defaultMessage: 'Hello, {name}!',
    description: 'Greeting to welcome the user to the app, v2',
  },
};`);

I'm running the following and get as output:

npx babel src/appConstants.tsx --extensions ".ts,.tsx" --config-file "./translations/translations.babelrc"
src/appConstants.tsx -> .messages/src/appConstants.json


import { defineMessages } from "react-intl";
const messages = defineMessages({
  'Component.greet1': {
    id: 'Component.greet1',
    defaultMessage: 'Hello, {name}!',
    description: 'Greeting to welcome the user to the app, v1'
  }
});
const generatedMessages = defineMessages({
  "Component.greet2": {
    "id": "Component.greet2",
    "defaultMessage": "Hello, {name}!",
    "description": "Greeting to welcome the user to the app, v2"
  }
});

I get this being extracted:

[
  {
    "id": "Component.greet1",
    "defaultMessage": "Hello, {name}!",
    "description": "Greeting to welcome the user to the app, v1"
  },
  { "undefined": "Greeting to welcome the user to the app, v2" }
]

Isn't this supposed to be possible? Isn't importing the macros in the correct order enough?

See also this conversation: https://twitter.com/sebastienlorber/status/1127942571790077954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant