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

@taskworld/typescript-custom-transformer-l10n

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@taskworld/typescript-custom-transformer-l10n

A TypeScript Custom AST transformer that inlines localization strings into the source code

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

@taskworld/typescript-custom-transformer-l10n

A TypeScript Custom AST transformer that inlines localization strings into the source code.

Background

Our localization file is several megabytes large now. It doesn’t play well with webpack’s code splitting. This custom AST transformer inlines the calls to localization routines with the data from localization file.

Usage

Given a source code:

function Tutorial() {
  return (
    <section>
      <h1>{__('tutorial.welcome.headline')}</h1>
      <p>{__('tutorial.welcome.paragraph')}</p>
    </section>
  )
}

…and a localization file:

{
  "en": {
    "tutorial.welcome.headline": "Welcome to %{workspace_name}",
    "tutorial.welcome.paragraph": "Your team will have all that you need to get work done."
  },
  "th": {
    "tutorial.welcome.headline": "ยินดีต้อนรับเข้าสู่ %{workspace_name}",
    "tutorial.welcome.paragraph": "บริหารจัดการงานได้อย่างครบถ้วนและมีประสิทธิภาพ"
  }
}

…when transpiled with this custom AST transformer, the output will look like this:

function Tutorial() {
  return (
    <section>
      <h1>
        {__({
          $key: 'tutorial.welcome.headline',
          en: 'Welcome to %{workspace_name}',
          th: 'ยินดีต้อนรับเข้าสู่ %{workspace_name}',
        })}
      </h1>
      <p>
        {__({
          $key: 'tutorial.welcome.paragraph',
          en: 'Your team will have all that you need to get work done.',
          th: 'บริหารจัดการงานได้อย่างครบถ้วนและมีประสิทธิภาพ',
        })}
      </p>
    </section>
  )
}

See the article How to Write a TypeScript Transform (Plugin) for how to use it in, e.g., webpack.

FAQs

Package last updated on 29 May 2019

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