Socket
Book a DemoInstallSign in
Socket

@lingui/swc-plugin

Package Overview
Dependencies
Maintainers
3
Versions
37
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

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
104K
-6.29%
Maintainers
3
Weekly downloads
 
Created
Source

A SWC Plugin For LinguiJS

A Rust versions of LinguiJS Macro

npm npm CI GitHub contributors GitHub

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"]
        // }
      }]
    }
  }
}

Or Next JS Usage:

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  experimental: {
    swcPlugins: [
      ['@lingui/swc-plugin', {
       // the same options as in .swcrc
      }],
    ],
  },
};

module.exports = nextConfig;

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

License

The project is licensed under the MIT license.

Keywords

swc-plugin

FAQs

Package last updated on 16 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