Code Monkey home page Code Monkey logo

eslint-plugin-react-i18n-extractor's Introduction

eslint-plugin-react-i18n-extractor

Helper for react-intl i18n to extract string literals and attributes in a format that is suitable for formatJS, react-intl, etc.

This rule is inspired by jsx-no-literals and it expand his capabilities, impementing a --fix.

The rule is customizable, and enhance the development experience, especially if a linter is part of the developer lifecyle and/or there's the need to internazionalize a legacy application from scratch.

For example the rule can be integrated with an IDE (like IntelliJ, VSCode, emacs, VIM,...) and automatically transform the literal strings into a standard format.

As an example, by default this code

<div>Hello</div>

gets transformed into

<div><FormattedMessage id="relative.file.path.hello" defaultMessage="Hello"></div>

and if you enable the options noAttributeStrings and noAttributeStringsList=["title"]

<div title='my title'>Hello</div>

gets transformed into

<div title={formatMessage({id:'relative.file.path.div.title.my_title', defaultMesage:'my title'})}><FormattedMessage id="relative.file.path.hello" defaultMessage="Hello"></div>

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

or

yarn add -D eslint

Next, install eslint-plugin-react-i18n-extractor:

npm install eslint-plugin-react-i18n-extractor --save-dev

or

yarn add -D eslint-plugin-react-i18n-extractor

or add it locally on a subdirectory after the checkout:

"devDependencies": {
    "@babel/eslint-parser": "^7.21.3",
    "@typescript-eslint/eslint-plugin": "^5.43.0",
    ...
    "eslint-plugin-react-i18n-extractor": "^0.0.2",
    ...
}

Usage

Add react-i18n-extractor to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "react-i18n-extractor"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "react-i18n-extractor/no-static-text": [
            "warn" : {
                "noAttributeStrings": true,
                "idPrefix": "app.",
                "noAttributeStringsInclude": [
                    "title",
                    "pretitle",
                    "placeholder",
                    "label",
                    "aria-label",
                    "suffix",
                    "message"
                ]}
        ]
    }
}

Rules

๐Ÿ”ง Automatically fixable by the --fix CLI option.

Name Description ๐Ÿ”ง
no-static-text extract static text ๐Ÿ”ง

eslint-plugin-react-i18n-extractor's People

Contributors

samuelzerozero avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.