New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-i18n

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-i18n

Statically convert translations to strings

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-i18n

Babel plugin to statically compile keypath denoted translation calls to literals.

Compiles these...

const myString = __("my.translation.path");
const anEnum = __obj("example.countries");
const lyrics = __arr("song");
const veryComplex = __dump("complex");

...with this kind of translation...

{
  "my": {
    "translation": {
      "path": "Hei, maailma!"
    }
  },
  "example": {
    "countries": {
      "finland": "Suomi",
      "sweden": "Ruotsi"
    }
  },
  "song": [
    "Hey!",
    "Ho!",
    "Let's go!"
  ],
  "complex": [[["multilevel array"], 123], null]
}

...into this:

const myString = "Hei, maailma!";
const anEnum = {
  finland: "Suomi",
  sweden: "Ruotsi"
};
const lyrics = ["Hey!", "Ho!", "Let's go!"];
const complex = [[["multilevel array"], 123], null];

Installation

$ npm install babel-plugin-i18n --save-dev

Usage

.babelrc

{
  "plugins": ["i18n", {
    "translationLoader": "./path/to/translationLoader"
  }]
}

Via CLI

TODO: How does one actually pass options via CLI?

Via Node API

require("babel-core").transform("code", {
  plugins: ["i18n", {
    "translationLoader": "./path/to/translationLoader"
  }]
});

Translation loader example

const join = require('path').join;
const readFileSync = require('fs').readFileSync;

const TRANSLATIONS_PATH = join(__dirname, 'completeTranslations.json');

module.exports = function myTranslationLoader() {
  const translationJSON = readFileSync(TRANSLATIONS_PATH, 'utf8');
  return JSON.parse(translationJSON);
};

Keywords

FAQs

Package last updated on 06 Nov 2016

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