1.7.4 • Published 7 months ago

global-message-converter v1.7.4

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Global Message Converter

global-message-converter is a command-line tool that detects hardcoded text within React applications and converts it to the format required by global messaging systems (react-intl). This library enables easy conversion of text.

CHANGELOG: Check the latest update history here.

Conversion Examples (Class and Functional Component Support)

  1. Text Conversion in JSX

    Before:

    <div>Hello.</div>

After:

<div><FormattedMessage id="greeting" defaultMessage="Hello." /></div>
  1. Plain Text Conversion
  • In this case, if the text is english converts only that starts with uppercase.

    Before:

    const hi = 'Hello.';

After:

const hi = intl.formatMessage({ id: 'new.message', defaultMessage: 'Hello.' });
  1. Template Literal Conversion

    Before:

    const error = `${error} occurred`;

After:

const error = intl.formatMessage({ id: 'error.message' }, { error });

Getting Started

To use this library, Node.js must be installed. Then you can install the library using npm.

npm install -g global-message-converter

Usage

After installation, run the library using the following command:

gmc [command]

Commands

convert

Detects hardcoded text and converts it to a format readable by the global messaging system.

Usage Example

gmc convert -t <file or folder path> -m <message file path>

Options

  • -t, --target <target>: Enter the file or folder to be converted.
  • -m, --message <message>: Enter the message file path.

Example

To convert files containing hardcoded text:

gmc convert --target ./src/components --message ./messages/messages.json

Message File Format

The message file is the baseline used to convert hardcoded text.

It detects message keys matching the text. If no matching message is found, a new message is created, and newly created messages are provided in file format (newMessages).

Must be written in JSON or JS format, with each message having a unique key and corresponding text value. Here's an example of a message file:

{
    "welcome_message": "Welcome, {username}!",
    "loading": "Loading...",
    "error": "Error: Unable to load data.",
    "success": "Congratulations! All tasks completed."
}

For JS files, nested message structures are not recognized:

export default {
    ko: {
       "welcome_message": "Welcome, {username}!",
       "loading": "Loading...",
       "error": "Error: Unable to load data.",
       "success": "Congratulations! All tasks completed."
    },
    en: {
        ...
    }
}

Must be converted to a non-nested format for proper message conversion:

export default {
   "welcome_message": "Welcome, {username}!",
   "loading": "Loading...",
   "error": "Error: Unable to load data.",
   "success": "Congratulations! All tasks completed."
}

How to Contribute

  1. Fork the repository.
  2. Create a branch: git checkout -b feature/feature-name
  3. Commit and push your changes.
  • Bug Reports: If a bug is discovered, create a new issue in the Issues section. Clearly describe the problem and include reproduction steps.
  • Feature Requests: New feature suggestions are always welcome! Provide detailed explanations to aid review.

License

This project is distributed under the MIT License.

1.7.4

7 months ago

1.7.2

8 months ago

1.7.1

8 months ago

1.7.0

8 months ago

1.6.4

8 months ago

1.6.3

8 months ago

1.6.2

8 months ago

1.5.0

8 months ago

1.4.0

8 months ago

1.3.0

8 months ago

1.2.0

8 months ago

1.1.3

8 months ago

1.1.1

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago