Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lingui/swc-plugin

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/swc-plugin

A SWC Plugin for LinguiJS

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48K
increased by11.36%
Maintainers
3
Weekly downloads
 
Created
Source

A SWC Plugin For LinguiJS

Description

This is a Rust versions of LinguiJS Macro

Usage

.swcrc https://swc.rs/docs/configuration/swcrc

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "experimental": {
      "plugins": ["@lingui/swc-plugin", {
        
        // Optional
        // Unlike the JS version this option must be passed as object only.
        // Docs https://lingui.js.org/ref/conf.html#std-config-runtimeConfigModule
        "runtimeModules": {
          "i18n": ["@lingui/core", "i18n"],
          "trans": ["@lingui/react", "Trans"]
        }
      }]
    }
  }
}

Tasks:

  • Essential t macro cases:
    • t`Some string`
    • t`Some ${variable} string`
    • t`Some ${expression} string`
    • t(i18n)`Some string` - custom i18n instance
    • dedup values object literal when the same variable appears few time, eq avoid {name, name, count}
  • NON Essential t macro cases:
    • t({ message descriptor }) call with message descriptor object
    • Passing other macros as arguments for t() eq: t({message: plural(...)})
  • defineMessage
    • Transform
    • Strip non-essential props on production
  • JS ICU calls (plural, select, selectOrdinal)
    • plural(count, {one: '# item', few: '# items'}) - simple strings
    • plural(count, {one: `${variable} # item`, few: '# items'}) - tpls with placeholders
    • plural(expression(), {one: `${variable} # item`, few: '# items'}) - expression as parameter
    • dedup values object literal when the same variable appears few time, eq avoid {name, name, count}
    • nesting expressions as described here https://lingui.js.org/ref/macro.html#plural
    • Support offset:1 and exact matches =1 {...}
  • Support JSX transformation
    • <Trans>
      • Simple cases <Trans>Hello World</Trans> -> <Trans message="Hello World" />
      • Variables interpolation <Trans>Hello {name} and {getName()}</Trans> -> <Trans variables={name, 1: getName()} msg="Hello {name} and {1}"/>
      • Recursive Components interpolation <Trans>Hello <strong>World!</strong></Trans>
      • Support edge cases <Trans>{'Hello World'}</Trans> and <Trans>{`How much is ${expression}? ${count}`}</Trans>
      • Normalizing whitespaces
      • Stripping non-essential props in production
    • ICU: <Plural> <SelectOrdinal> <Select>
      • Support offset:1 and exact matches =1 {...}
  • Support narrowing transformation to only function exported from @lingui/macro
  • Automatic adding import { i18n } from @lingui/core
  • Unicode escaping, validate how SWC produce values
  • Support runtimeConfigModule settings
  • NON-ESSENTIAL Injecting uniq variables, avoiding collision with existing variables
  • NON-ESSENTIAL support renamed macro calls import {t as macroT} from "@lingui/macro"
  • Error handling: how to properly behave to do if user passed something not expected HANDLER
  • Building binary and publishing

Keywords

FAQs

Package last updated on 11 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc