npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@m6web/eslint-plugin-i18n

v2.0.4

Published

eslint plugin for generic i18n

Downloads

2,224

Readme

@m6web/eslint-plugin-i18n

Continous Integration npm npm bundle size npm GitHub last commit NPM

This is an eslint plugin for i18n in a react application. This plugin provides you with a set of rules to check the correct use of the translation keys but also forces you not to introduce untranslated texts in your React components.

Installation

yarn add -D @m6web/eslint-plugin-i18n

Build

yarn build

Rules

  • @m6web/i18n/no-unknown-key: Verify that all translation keys you use are present in your primary translation files.
  • @m6web/i18n/no-unknown-key-secondary-langs: Same as the previous one. Allow you to have a different error level for secondary languages.
  • @m6web/i18n/no-text-as-children: Verify that you have no text children in your react code.
  • @m6web/i18n/no-text-as-attribute: Verify that you have no text in some attributes in your react components. List of attributes as to be provided in the config.
  • @m6web/i18n/interpolation-data: Checks for usage of keys containing string interpolation, if translate function is called without interpolation data it will show an error. Also if interpolation data is given and key doesn't contain interpolation it will also show an error. interpolationPattern option is required to match interpolation in your translation file.

Config

You have to add the following lines in your .eslintrc file to configure this plugin:

  // Declare the plugin
  "plugins": [
    "@m6web/i18n"
  ],
  // Specify rules severity
  "rules": {
    "@m6web/i18n/no-unknown-key": "error",
    "@m6web/i18n/no-unknown-key-secondary-langs": "warn",
    "@m6web/i18n/no-text-as-children": ["error", {"ignorePattern": "^\\s?[/.]\\s?$"}],
    "@m6web/i18n/no-text-as-attribute": ["error", {"attributes": ["alt", "title"]}],
    "@m6web/i18n/interpolation-data": ["error", { "interpolationPattern": "\\{\\.+\\}" }]
  },
  // The plugin needs jsx feature to be on for 'no-text-as-children' rule
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    }
  },
  // Settings of your translation
  "settings": {
    "i18n": {
      // Your principal languages used in 'no-unknown-key' rule
      "principalLangs": [
        {
          "name": "fr",
          "translationPath": "i18n/fr.json"
        }
      ],
      // Secondary languages used in 'no-unknown-key-secondary-langs' rule
      "secondaryLangs": [
        {
          "name": "en",
          "translationPath": "i18n/en.json"
        }
      ],
      // Name of your translate function
      "functionName": "t",
      // If you want to ignore specific files
      "ignoreFiles": ["**/*.spec.js", "**/*.int.js"],
      // If you have pluralization
      "pluralizedKeys": ["one", "other"],
      // TTL of the translations file caching (defaults to 500ms)
      "translationsCacheTTL": 300
    }
  }