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

Allow fallback to a messages defined in the code without compilation #2043

Open
timofei-iatsenko opened this issue Oct 4, 2024 · 5 comments

Comments

@timofei-iatsenko
Copy link
Collaborator

ToDo: motivation, related issues

Tasks:

  1. Make configurable strip_non_essential_fields in the SWC plugin from outside. Now it's hardcoded to the ENV variable

    • or introduce new option supress_stripping_message, which will allow stripping context and comment but left message.
  2. Make the same options for Babel macro plugin

  3. Make possible to register MessageCompiler in production, PR: feat: add setMessagesCompiler method #2035

  4. Write the docs describing all configuration to achieve that.

@ilyausorov
Copy link

ilyausorov commented Oct 12, 2024

Would really appreciate supress_stripping_message because right now I'm having to patch this line in the @lingui/macro package const stripNonEssentialProps = false; // process.env.NODE_ENV == "production" && !opts.extract; to keep the message values available so I can do something like this

const SOME_TEXT = msg`Some text`;

const object = {
       originalValue: SOME_TEXT.message,
       translatedValue: _(SOME_TEXT)
}

@timofei-iatsenko
Copy link
Collaborator Author

timofei-iatsenko commented Oct 14, 2024

You don't need to patch, this is a configurable parameter. You can either use pre-release v5 version where macro is extracted to separate babel plugin and parameters could be passed directly to it, or use babel-plugin-macros configuration as specified there: https:/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md#config use lingui for macro name

// babel-plugin-macros.config.js
module.exports = {
  // ...
  // Other macros config
  lingui: {
    extract: true,
  },
}

@ilyausorov
Copy link

hey @timofei-iatsenko, thanks for this info. Just curious, is using the babel-plugin-macros configuration for lingui and specifically that the extract property is an available property, documented anywhere in the documentation? I feel like I thoroughly reviewed it, and I didn't see this before.

@timofei-iatsenko
Copy link
Collaborator Author

It's not documented, it is used internally for extractor. Later I will create a documented parameter intended for public use as described here in the first message. But you can safely use this "extract" param, because it's not going to be changed any time soon.

@ilyausorov
Copy link

Hmm I couldn't get it to work but maybe thats because I'm also in a monorepo and it's react native. I'll leave my patch in for now until you get the v5 fully released and tested 🙏

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

2 participants